use of org.logicng.predicates.satisfiability.TautologyPredicate in project LogicNG by logic-ng.
the class BDDReorderingTest method verifyBddConsistency.
private boolean verifyBddConsistency(final FormulaFactory f, final Formula f1, final BDD bdd, final BigInteger modelCount) {
final BDDVerification verification = new BDDVerification(bdd.underlyingKernel());
if (!verification.verify(bdd.index())) {
return false;
}
final long nodes = verification.verifyTree(bdd.index());
if (nodes < 0) {
return false;
}
this.stats.newBddSize(nodes);
if (modelCount != null && !modelCount.equals(bdd.modelCount())) {
System.out.println("Nodecount changed!");
return false;
}
if (modelCount == null && !f.equivalence(f1, bdd.cnf()).holds(new TautologyPredicate(f))) {
System.out.println("Not equal");
return false;
}
return true;
}
use of org.logicng.predicates.satisfiability.TautologyPredicate in project LogicNG by logic-ng.
the class FormulaBDDTest method testBDDGeneration.
@Test
public void testBDDGeneration() throws ParserException {
final FormulaFactory f = new FormulaFactory();
final PseudoBooleanParser p = new PseudoBooleanParser(f);
final Formula formula = p.parse("(A => ~B) & ((A & C) | (D & ~C)) & (A | Y | X) & (Y <=> (X | (W + A + F < 1)))");
final BDD bddNoOrder = formula.bdd();
final BDD bddBfs = formula.bdd(VariableOrdering.BFS);
final BDD bddDfs = formula.bdd(VariableOrdering.DFS);
final BDD bddMin2Max = formula.bdd(VariableOrdering.MIN2MAX);
final BDD bddMax2Min = formula.bdd(VariableOrdering.MAX2MIN);
assertThat(bddNoOrder.nodeCount()).isEqualTo(13);
assertThat(bddBfs.nodeCount()).isEqualTo(14);
assertThat(bddDfs.nodeCount()).isEqualTo(13);
assertThat(bddMin2Max.nodeCount()).isEqualTo(14);
assertThat(bddMax2Min.nodeCount()).isEqualTo(22);
final TautologyPredicate tautology = new TautologyPredicate(f);
assertThat(f.equivalence(bddNoOrder.cnf(), formula).holds(tautology)).isTrue();
assertThat(f.equivalence(bddBfs.cnf(), formula).holds(tautology)).isTrue();
assertThat(f.equivalence(bddDfs.cnf(), formula).holds(tautology)).isTrue();
assertThat(f.equivalence(bddMin2Max.cnf(), formula).holds(tautology)).isTrue();
assertThat(f.equivalence(bddMax2Min.cnf(), formula).holds(tautology)).isTrue();
}
use of org.logicng.predicates.satisfiability.TautologyPredicate in project LogicNG by logic-ng.
the class PlaistedGreenbaumTransformationSolverTest method computeAndVerify.
private static void computeAndVerify(final Formula formula) {
final FormulaFactory f = formula.factory();
final SATSolver solver = MiniSat.miniSat(f, MiniSatConfig.builder().cnfMethod(MiniSatConfig.CNFMethod.FULL_PG_ON_SOLVER).auxiliaryVariablesInModels(false).build());
solver.add(formula);
final List<Assignment> models = solver.enumerateAllModels();
final Formula dnf = f.or(models.stream().map(model -> f.and(model.literals())).collect(Collectors.toList()));
assertThat(f.equivalence(formula, dnf).holds(new TautologyPredicate(f))).isTrue();
}
use of org.logicng.predicates.satisfiability.TautologyPredicate in project LogicNG by logic-ng.
the class DNFSubsumptionTest method testEvenLargerFormulas.
@Test
public void testEvenLargerFormulas() throws IOException, ParserException {
final FormulaFactory f = new FormulaFactory();
final Formula formula = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/small_formulas.txt", f);
// test only first 10 formulas
int count = 10;
for (final Formula op : formula) {
if (count == 0) {
break;
}
final Formula dnf = op.transform(new DNFFactorization());
final Formula subsumed = dnf.transform(new DNFSubsumption());
assertThat(f.equivalence(dnf, subsumed).holds(new TautologyPredicate(f))).isTrue();
assertThat(dnf.numberOfOperands() > subsumed.numberOfOperands()).isTrue();
count--;
}
}
use of org.logicng.predicates.satisfiability.TautologyPredicate in project LogicNG by logic-ng.
the class QuineMcCluskeyTest method testLarge1.
@Test
public void testLarge1() throws ParserException {
final FormulaFactory f = new FormulaFactory();
final PropositionalParser p = new PropositionalParser(f);
final Formula formula = p.parse("A => B & ~((D | E | I | J) & ~K) & L");
final Formula dnf = QuineMcCluskeyAlgorithm.compute(formula);
assertThat(dnf.holds(DNFPredicate.get())).isTrue();
assertThat(f.equivalence(formula, dnf).holds(new TautologyPredicate(f))).isTrue();
}
Aggregations