Search in sources :

Example 1 with TautologyPredicate

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;
}
Also used : TautologyPredicate(org.logicng.predicates.satisfiability.TautologyPredicate) BDDVerification(org.logicng.knowledgecompilation.bdds.jbuddy.BDDVerification)

Example 2 with TautologyPredicate

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();
}
Also used : PseudoBooleanParser(org.logicng.io.parsers.PseudoBooleanParser) Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) TautologyPredicate(org.logicng.predicates.satisfiability.TautologyPredicate) Test(org.junit.jupiter.api.Test)

Example 3 with TautologyPredicate

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();
}
Also used : SATSolver(org.logicng.solvers.SATSolver) Assignment(org.logicng.datastructures.Assignment) Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) TautologyPredicate(org.logicng.predicates.satisfiability.TautologyPredicate)

Example 4 with TautologyPredicate

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--;
    }
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) TautologyPredicate(org.logicng.predicates.satisfiability.TautologyPredicate) Test(org.junit.jupiter.api.Test)

Example 5 with TautologyPredicate

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();
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) TautologyPredicate(org.logicng.predicates.satisfiability.TautologyPredicate) PropositionalParser(org.logicng.io.parsers.PropositionalParser) Test(org.junit.jupiter.api.Test)

Aggregations

TautologyPredicate (org.logicng.predicates.satisfiability.TautologyPredicate)23 Formula (org.logicng.formulas.Formula)19 FormulaFactory (org.logicng.formulas.FormulaFactory)16 Test (org.junit.jupiter.api.Test)13 ArrayList (java.util.ArrayList)5 Assignment (org.logicng.datastructures.Assignment)5 PropositionalParser (org.logicng.io.parsers.PropositionalParser)5 SATSolver (org.logicng.solvers.SATSolver)5 Literal (org.logicng.formulas.Literal)3 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 BigInteger (java.math.BigInteger)1 TreeSet (java.util.TreeSet)1 LongRunningTag (org.logicng.LongRunningTag)1 RandomTag (org.logicng.RandomTag)1 Variable (org.logicng.formulas.Variable)1 PseudoBooleanParser (org.logicng.io.parsers.PseudoBooleanParser)1 BDDInnerNode (org.logicng.knowledgecompilation.bdds.datastructures.BDDInnerNode)1 LngBDDFunction (org.logicng.knowledgecompilation.bdds.functions.LngBDDFunction)1 BDDKernel (org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel)1