Clover coverage report -
Coverage timestamp: jeu. juin 15 2006 08:24:33 CEST
file stats: LOC: 165   Methods: 13
NCLOC: 87   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MinWatchCardPB.java 55,6% 74,3% 84,6% 71,2%
coverage coverage
 1    package org.sat4j.minisat.constraints.pb;
 2   
 3    import java.math.BigInteger;
 4   
 5    import org.sat4j.minisat.constraints.card.MinWatchCard;
 6    import org.sat4j.minisat.core.Constr;
 7    import org.sat4j.minisat.core.ILits;
 8    import org.sat4j.minisat.core.UnitPropagationListener;
 9    import org.sat4j.specs.ContradictionException;
 10    import org.sat4j.specs.IVecInt;
 11   
 12    public class MinWatchCardPB extends MinWatchCard implements PBConstr {
 13   
 14    /**
 15    *
 16    */
 17    private static final long serialVersionUID = 1L;
 18   
 19    private final BigInteger degree;
 20   
 21  2544 public MinWatchCardPB(ILits voc, IVecInt ps, boolean moreThan, int degree) {
 22  2544 super(voc, ps, moreThan, degree);
 23  2544 this.degree = new BigInteger(String.valueOf(degree));
 24    }
 25   
 26  18412 public MinWatchCardPB(ILits voc, IVecInt ps, int degree) {
 27  18412 super(voc, ps, degree);
 28  18412 this.degree = new BigInteger(String.valueOf(degree));
 29    }
 30   
 31    /*
 32    * (non-Javadoc)
 33    *
 34    * @see org.sat4j.minisat.constraints.pb.PBConstr#getCoefficient(int)
 35    */
 36  2418979 public BigInteger getCoef(int literal) {
 37  2418979 return BigInteger.ONE;
 38    }
 39   
 40    /*
 41    * (non-Javadoc)
 42    *
 43    * @see org.sat4j.minisat.constraints.pb.PBConstr#getDegree()
 44    */
 45  76975 public BigInteger getDegree() {
 46  76975 return degree;
 47    }
 48   
 49  8362 public BigInteger[] getCoefs() {
 50  8362 BigInteger[] tmp = new BigInteger[size()];
 51  8362 for (int i = 0; i < tmp.length; i++)
 52  317358 tmp[i] = BigInteger.ONE;
 53  8362 return tmp;
 54    }
 55   
 56    /**
 57    * Permet la cr?ation de contrainte de cardinalit? ? observation minimale
 58    *
 59    * @param s
 60    * outil pour la propagation des litt?raux
 61    * @param voc
 62    * vocabulaire utilis? par la contrainte
 63    * @param ps
 64    * liste des litt?raux de la nouvelle contrainte
 65    * @param degree
 66    * fournit le degr? de la contrainte
 67    * @return une nouvelle clause si tout va bien, null sinon
 68    * @throws ContradictionException
 69    */
 70  18412 public static MinWatchCardPB normalizedMinWatchCardPBNew(
 71    UnitPropagationListener s, ILits voc, IVecInt ps, int degree)
 72    throws ContradictionException {
 73  18412 return minWatchCardPBNew(s, voc, ps, ATLEAST, degree, true);
 74    }
 75   
 76    /**
 77    * Permet la cr?ation de contrainte de cardinalit? ? observation minimale
 78    *
 79    * @param s
 80    * outil pour la propagation des litt?raux
 81    * @param voc
 82    * vocabulaire utilis? par la contrainte
 83    * @param ps
 84    * liste des litt?raux de la nouvelle contrainte
 85    * @param moreThan
 86    * d?termine si c'est une sup?rieure ou ?gal ? l'origine
 87    * @param degree
 88    * fournit le degr? de la contrainte
 89    * @return une nouvelle clause si tout va bien, null sinon
 90    * @throws ContradictionException
 91    */
 92  0 public static MinWatchCardPB minWatchCardPBNew(UnitPropagationListener s,
 93    ILits voc, IVecInt ps, boolean moreThan, int degree)
 94    throws ContradictionException {
 95  0 return minWatchCardPBNew(s, voc, ps, moreThan, degree, false);
 96    }
 97   
 98  18412 private static MinWatchCardPB minWatchCardPBNew(UnitPropagationListener s,
 99    ILits voc, IVecInt ps, boolean moreThan, int degree,
 100    boolean normalized) throws ContradictionException {
 101  18412 int mydegree = degree + linearisation(voc, ps);
 102   
 103  18412 if (ps.size() == 0 && mydegree > 0) {
 104  0 throw new ContradictionException();
 105  18412 } else if (ps.size() == mydegree || ps.size() <= 0) {
 106  0 for (int i = 0; i < ps.size(); i++)
 107  0 if (!s.enqueue(ps.get(i))) {
 108  0 throw new ContradictionException();
 109    }
 110  0 return null;
 111    }
 112   
 113    // constraint is now instanciated
 114  18412 MinWatchCardPB retour = null;
 115  18412 if (normalized)
 116  18412 retour = new MinWatchCardPB(voc, ps, mydegree);
 117    else
 118  0 retour = new MinWatchCardPB(voc, ps, moreThan, mydegree);
 119   
 120  18412 if (retour.degree.signum() <= 0)
 121  0 return null;
 122   
 123  18412 retour.computeWatches();
 124   
 125  18412 return ((MinWatchCardPB) retour.computePropagation(s));
 126    }
 127   
 128    /**
 129    *
 130    */
 131    private boolean learnt = false;
 132   
 133    /**
 134    * D?termine si la contrainte est apprise
 135    *
 136    * @return true si la contrainte est apprise, false sinon
 137    * @see Constr#learnt()
 138    */
 139  20956 public boolean learnt() {
 140  20956 return learnt;
 141    }
 142   
 143  5088 public void setLearnt() {
 144  5088 learnt = true;
 145    }
 146   
 147  2544 public void register() {
 148    assert learnt;
 149  2544 computeWatches();
 150    }
 151   
 152  2544 public void assertConstraint(UnitPropagationListener s) {
 153  2544 for (int i = 0; i < size(); i++) {
 154  486546 if (getVocabulary().isUnassigned(get(i))) {
 155  19459 boolean ret = s.enqueue(get(i), this);
 156    assert ret;
 157    }
 158    }
 159    }
 160   
 161  0 public IVecInt computeAnImpliedClause() {
 162  0 return null;
 163    }
 164   
 165    }