Clover coverage report -
Coverage timestamp: mar. juil. 11 2006 04:58:35 CEST
file stats: LOC: 85   Methods: 6
NCLOC: 65   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SupportsDirectEncoding.java 0% 0% 0% 0%
coverage
 1    package org.sat4j.reader.csp;
 2   
 3    import org.sat4j.core.VecInt;
 4    import org.sat4j.specs.ContradictionException;
 5    import org.sat4j.specs.ISolver;
 6    import org.sat4j.specs.IVec;
 7    import org.sat4j.specs.IVecInt;
 8   
 9   
 10    public class SupportsDirectEncoding implements Relation {
 11   
 12    protected final int arity;
 13   
 14    protected int[][] tuples;
 15   
 16    private IVecInt clause;
 17    private int lastmatch;
 18   
 19  0 public SupportsDirectEncoding(int arity, int nbtuples) {
 20  0 this.arity = arity;
 21  0 tuples = new int[nbtuples][];
 22    }
 23   
 24  0 public void addTuple(int index, int[] tuple) {
 25  0 tuples[index] = tuple;
 26    }
 27   
 28  0 public void toClause(ISolver solver, IVec<Var> scope, IVec<Evaluable> vars)
 29    throws ContradictionException {
 30    // need to find all the tuples that are not expressed here.
 31  0 clause = new VecInt();
 32  0 int[] tuple = new int[vars.size()];
 33  0 lastmatch=-1;
 34  0 find(tuple, 0, scope,vars, solver);
 35    }
 36   
 37  0 private void find(int[] tuple, int n, IVec<Var> scope, IVec<Evaluable> vars, ISolver solver)
 38    throws ContradictionException {
 39  0 if (n == vars.size()) {
 40  0 if (notPresent(tuple)) {
 41  0 clause.clear();
 42  0 for (int j = 0; j < vars.size(); j++) {
 43  0 clause.push(-vars.get(j).translate(tuple[j]));
 44    }
 45    // System.err.println("Adding clause:" + clause);
 46  0 solver.addClause(clause);
 47    }
 48    } else {
 49  0 int[] domain = vars.get(n).domain();
 50  0 for (int i = 0; i < domain.length; i++) {
 51  0 tuple[n] = domain[i];
 52  0 find(tuple, n + 1, scope,vars, solver);
 53    }
 54   
 55    }
 56   
 57    }
 58   
 59  0 private boolean notPresent(int[] tuple) {
 60    // System.out.println("Checking:" + Arrays.asList(tuple));
 61    // find the first tuple begining with the same
 62    // initial number
 63  0 int i = lastmatch+1;
 64  0 int j = 0;
 65  0 while (i<tuples.length&&j < tuple.length) {
 66  0 if (tuples[i][j] < tuple[j]) {
 67  0 i++;
 68  0 j = 0;
 69  0 continue;
 70    }
 71  0 if (tuples[i][j] > tuple[j])
 72  0 return true;
 73  0 j++;
 74    }
 75  0 if (j==tuple.length) {
 76  0 lastmatch=i;
 77  0 return false;
 78    }
 79  0 return true;
 80    }
 81   
 82  0 public int arity() {
 83  0 return arity;
 84    }
 85    }