Clover coverage report -
Coverage timestamp: jeu. sept. 29 2005 23:57:39 CEST
file stats: LOC: 123   Methods: 3
NCLOC: 81   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CardDimacsReader.java 0% 0% 0% 0%
coverage
 1    package org.sat4j.reader;
 2   
 3    import java.io.IOException;
 4    import java.io.LineNumberReader;
 5    import java.util.StringTokenizer;
 6   
 7    import org.sat4j.core.VecInt;
 8    import org.sat4j.specs.ContradictionException;
 9    import org.sat4j.specs.ISolver;
 10    import org.sat4j.specs.IVecInt;
 11   
 12    /**
 13    * A reader for cardinality contraints.
 14    *
 15    * @author leberre
 16    *
 17    */
 18    @Deprecated
 19    public class CardDimacsReader extends DimacsReader {
 20   
 21    /**
 22    *
 23    */
 24    private static final long serialVersionUID = 3258130241376368435L;
 25   
 26  0 public CardDimacsReader(ISolver solver) {
 27  0 super(solver);
 28    }
 29   
 30    /**
 31    * @param in
 32    * the input stream
 33    * @throws IOException
 34    * iff an IO problems occurs
 35    * @throws ParseFormatException
 36    * if the input stream does not comply with the DIMACS format.
 37    * @throws ContradictionException
 38    * si le probl?me est trivialement inconsistant.
 39    */
 40  0 @Override
 41    protected void readConstrs(LineNumberReader in) throws IOException,
 42    ParseFormatException, ContradictionException {
 43  0 int lit;
 44  0 String line;
 45  0 StringTokenizer stk;
 46   
 47  0 int realNbOfClauses = 0;
 48   
 49  0 IVecInt literals = new VecInt();
 50   
 51  0 while (true) {
 52  0 line = in.readLine();
 53   
 54  0 if (line == null) {
 55    // end of file
 56  0 if (literals.size() > 0) {
 57    // no 0 end the last clause
 58  0 solver.addClause(literals);
 59  0 realNbOfClauses++;
 60    }
 61   
 62  0 break;
 63    }
 64   
 65  0 if (line.startsWith("c ")) {
 66    // skip commented line
 67  0 continue;
 68    }
 69  0 if (line.startsWith("%") && expectedNbOfConstr == realNbOfClauses) {
 70  0 System.out
 71    .println("Ignoring the rest of the file (SATLIB format");
 72  0 break;
 73    }
 74  0 stk = new StringTokenizer(line);
 75  0 String token;
 76   
 77  0 while (stk.hasMoreTokens()) {
 78    // on lit le prochain token
 79  0 token = stk.nextToken();
 80   
 81  0 if ((token.equals("<=")) || (token.equals(">="))) {
 82    // on est sur une contrainte de cardinalit?
 83  0 readCardinalityConstr(token, stk, literals);
 84  0 literals.clear();
 85  0 realNbOfClauses++;
 86    } else {
 87  0 lit = Integer.parseInt(token);
 88   
 89  0 if (lit != 0) {
 90  0 literals.push(lit);
 91    } else {
 92  0 if (literals.size() > 0) {
 93  0 solver.addClause(literals);
 94  0 literals.clear();
 95  0 realNbOfClauses++;
 96    }
 97    }
 98   
 99    }
 100    }
 101    }
 102  0 if (expectedNbOfConstr != realNbOfClauses) {
 103  0 throw new ParseFormatException("wrong nbclauses parameter. Found "
 104    + realNbOfClauses + ", " + expectedNbOfConstr + " expected");
 105    }
 106    }
 107   
 108  0 private void readCardinalityConstr(String token, StringTokenizer stk,
 109    IVecInt literals) throws ContradictionException,
 110    ParseFormatException {
 111  0 int card = Integer.parseInt(stk.nextToken());
 112  0 int lit = Integer.parseInt(stk.nextToken());
 113  0 if (lit == 0) {
 114  0 if (token.equals("<=")) {
 115  0 solver.addAtMost(literals, card);
 116  0 } else if (token.equals(">=")) {
 117  0 solver.addAtLeast(literals, card);
 118    }
 119    } else
 120  0 throw new ParseFormatException();
 121    }
 122   
 123    }