Example #1
0
 @Test(expected = IllegalArgumentException.class)
 public void testIllegalCC1() {
   final FormulaFactory f = new FormulaFactory();
   final CCEncoder encoder = new CCEncoder(f);
   final int numLits = 100;
   final Variable[] problemLits = new Variable[numLits];
   for (int i = 0; i < numLits; i++) problemLits[i] = f.variable("v" + i);
   encoder.encode(f.cc(CType.GE, -1, problemLits));
 }
Example #2
0
 private void testCC(int numLits, int rhs, int expected, final FormulaFactory f) {
   final Variable[] problemLits = new Variable[numLits];
   for (int i = 0; i < numLits; i++) problemLits[i] = f.variable("v" + i);
   final SATSolver solver = MiniSat.miniSat(f);
   solver.add(f.cc(CType.GE, rhs, problemLits));
   if (expected != 0) Assert.assertEquals(Tristate.TRUE, solver.sat());
   else Assert.assertEquals(Tristate.FALSE, solver.sat());
   final List<Assignment> models =
       solver.enumerateAllModels(problemLits, new NumberOfModelsHandler(12000));
   Assert.assertEquals(expected, models.size());
   for (final Assignment model : models) Assert.assertTrue(model.positiveLiterals().size() >= rhs);
 }
Example #3
0
 @Override
 public boolean test(final Formula formula, boolean cache) {
   final Tristate cached = formula.predicateCacheEntry(IS_TAUTOLOGY);
   if (cached != Tristate.UNDEF) return cached == Tristate.TRUE;
   final FormulaFactory factory = formula.factory();
   boolean result;
   if (formula.holds(cnfPredicate)) result = formula == factory.verum();
   else {
     final Formula negation = formula.negate();
     result = !negation.holds(this.satPredicate);
   }
   if (cache) formula.setPredicateCacheEntry(IS_TAUTOLOGY, result);
   return result;
 }
Example #4
0
 /**
  * Computes the distribution (factorization) of two formulas.
  *
  * @param f1 the first formula
  * @param f2 the second formula
  * @return the distribution of the two formulas
  */
 private Formula distribute(final Formula f1, final Formula f2) {
   if (this.handler != null) this.proceed = this.handler.performedDistribution();
   if (this.proceed) {
     final FormulaFactory f = f1.factory();
     if (f1.type() == AND || f2.type() == AND) {
       final LinkedHashSet<Formula> nops = new LinkedHashSet<>();
       for (final Formula op : f1.type() == AND ? f1 : f2) {
         final Formula distribute = this.distribute(op, f1.type() == AND ? f2 : f1);
         if (!this.proceed) return null;
         nops.add(distribute);
       }
       return f.and(nops);
     }
     final Formula clause = f.or(f1, f2);
     if (this.handler != null) proceed = this.handler.createdClause(clause);
     return clause;
   }
   return null;
 }
Example #5
0
 @Test
 public void testALK() {
   final FormulaFactory f = new FormulaFactory();
   int counter = 0;
   for (final CCConfig config : this.configs) {
     f.putConfiguration(config);
     testCC(10, 0, 1, f);
     testCC(10, 1, 1023, f);
     testCC(10, 2, 1013, f);
     testCC(10, 3, 968, f);
     testCC(10, 4, 848, f);
     testCC(10, 5, 638, f);
     testCC(10, 6, 386, f);
     testCC(10, 7, 176, f);
     testCC(10, 8, 56, f);
     testCC(10, 9, 11, f);
     testCC(10, 10, 1, f);
     testCC(10, 12, 0, f);
     Assert.assertTrue(f.newCCVariable().name().endsWith("_" + counter++));
   }
 }