001/*
002 * $Id$
003 */
004
005package edu.jas.gb;
006
007import java.io.Serializable;
008
009import edu.jas.structure.RingElem;
010
011import edu.jas.poly.ExpVector;
012import edu.jas.poly.GenPolynomial;
013
014
015/**
016 * Serializable subclass to hold critical pairs of polynomials.
017 * Used also to manage reduction status of the pair.
018 * @param <C> coefficient type
019 * @author Heinz Kredel
020 */
021public class CriticalPair<C extends RingElem<C> > extends AbstractPair<C> {
022
023    protected volatile boolean inReduction;
024    protected volatile GenPolynomial<C> reductum;
025    //public final ExpVector sugar;
026
027
028    /**
029     * CriticalPair constructor.
030     * @param e lcm(lt(pi),lt(pj).
031     * @param pi polynomial i.
032     * @param pj polynomial j.
033     * @param i index of pi.
034     * @param j index pf pj.
035     */
036    public CriticalPair(ExpVector e,
037                        GenPolynomial<C> pi, GenPolynomial<C> pj, 
038                        int i, int j) {
039        super(e,pi,pj,i,j);
040        inReduction = false; 
041        reductum = null;
042    }
043
044
045    /**
046     * toString.
047     */
048    @Override
049    public String toString() {
050        StringBuffer s = new StringBuffer(super.toString() + "[ ");
051        if ( inReduction ) {
052           s.append("," + inReduction);
053        } 
054        if ( reductum != null ) {
055           s.append("," + reductum.leadingExpVector());
056        } 
057        s.append(" ]");
058        return s.toString();
059    }
060
061
062    /**
063     * Set in reduction status.
064     * inReduction is set to true.
065     */
066    public void setInReduction() {
067        if ( inReduction ) {
068           throw new IllegalStateException("already in reduction " + this);
069        }
070        inReduction = true;
071    }
072
073
074    /**
075     * Get in reduction status.
076     * @return true if the polynomial is currently in reduction, else false.
077     */
078    public boolean getInReduction() {
079        return inReduction;
080    }
081
082
083    /**
084     * Get reduced polynomial.
085     * @return the reduced polynomial or null if not done.
086     */
087    public GenPolynomial<C> getReductum() {
088        return reductum;
089    }
090
091
092    /**
093     * Set reduced polynomial.
094     * @param r the reduced polynomial.
095     */
096    public void setReductum(GenPolynomial<C> r) {
097        if ( r == null ) {
098           throw new IllegalArgumentException("reduction null not allowed " + this);
099        }
100        inReduction = false;
101        reductum = r;
102    }
103
104
105    /**
106     * Is reduced to zero.
107     * @return true if the S-polynomial of this CriticalPair 
108     *         was reduced to ZERO, else false.
109     */
110    public boolean isZERO() {
111        if ( reductum == null ) { // not jet done
112            return false;
113        }
114        return reductum.isZERO();
115    }
116
117
118    /**
119     * Is reduced to one.
120     * @return true if the S-polynomial of this CriticalPair was 
121     *         reduced to ONE, else false.
122     */
123    public boolean isONE() {
124        if ( reductum == null ) { // not jet done
125            return false;
126        }
127        return reductum.isONE();
128    }
129
130}
131