Search in sources :

Example 16 with BDDKernel

use of org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel in project LogicNG by logic-ng.

the class SimpleBDDTest method testFormula.

@Test
public void testFormula() throws ParserException {
    final FormulaFactory f = new FormulaFactory();
    final PropositionalParser parser = new PropositionalParser(f);
    final List<Variable> ordering = Arrays.asList(f.variable("A"), f.variable("B"), f.variable("C"));
    final BDDKernel kernel = new BDDKernel(f, ordering, 1000, 1000);
    final BDD bdd = BDDFactory.build(parser.parse("(A => ~C) | (B & ~C)"), kernel, null);
    assertThat(bdd.isTautology()).isFalse();
    assertThat(bdd.isContradiction()).isFalse();
    assertThat(bdd.modelCount()).isEqualTo(BigInteger.valueOf(6));
    assertThat(bdd.underlyingKernel().factory()).isSameAs(f);
    assertThat(bdd.enumerateAllModels()).hasSize(6);
    assertThat(bdd.enumerateAllModels(f.variable("A"))).hasSize(2);
    assertThat(bdd.hashCode()).isEqualTo(BDDFactory.build(parser.parse("(A => ~C) | (B & ~C)"), kernel, null).hashCode());
    assertThat(bdd.toString()).isEqualTo("BDD{8}");
}
Also used : FormulaFactory(org.logicng.formulas.FormulaFactory) Variable(org.logicng.formulas.Variable) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) PropositionalParser(org.logicng.io.parsers.PropositionalParser) Test(org.junit.jupiter.api.Test)

Example 17 with BDDKernel

use of org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel in project LogicNG by logic-ng.

the class SimpleBDDTest method testCC.

@Test
public void testCC() throws ParserException {
    final FormulaFactory f = new FormulaFactory();
    final PseudoBooleanParser parser = new PseudoBooleanParser(f);
    final BDDKernel kernel = new BDDKernel(f, 3, 1000, 1000);
    final BDD bdd = BDDFactory.build(parser.parse("A + B + C = 1"), kernel, null);
    assertThat(bdd.isTautology()).isFalse();
    assertThat(bdd.isContradiction()).isFalse();
    assertThat(bdd.cnf()).isEqualTo(parser.parse("(A | B | C) & (A | ~B | ~C) & (~A | B | ~C) & (~A | ~B)"));
    assertThat(bdd.dnf()).isEqualTo(parser.parse("~A & ~B & C | ~A & B & ~C | A & ~B & ~C"));
    assertThat(bdd.modelCount()).isEqualTo(BigInteger.valueOf(3));
    assertThat(bdd.underlyingKernel().factory()).isSameAs(f);
    assertThat(bdd.enumerateAllModels()).containsExactlyInAnyOrder(new Assignment(f.literal("A", true), f.literal("B", false), f.literal("C", false)), new Assignment(f.literal("A", false), f.literal("B", true), f.literal("C", false)), new Assignment(f.literal("A", false), f.literal("B", false), f.literal("C", true)));
    assertThat(bdd.numberOfClausesCNF()).isEqualTo(BigInteger.valueOf(4));
}
Also used : PseudoBooleanParser(org.logicng.io.parsers.PseudoBooleanParser) Assignment(org.logicng.datastructures.Assignment) FormulaFactory(org.logicng.formulas.FormulaFactory) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) Test(org.junit.jupiter.api.Test)

Example 18 with BDDKernel

use of org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel in project LogicNG by logic-ng.

the class BDDModelEnumerationTest method testExk.

@Test
public void testExk() {
    final FormulaFactory f = new FormulaFactory();
    final Formula constraint = f.cc(CType.EQ, 8, generateVariables(15, f)).cnf();
    final BDDKernel kernel = new BDDKernel(f, constraint.variables().size(), 100000, 1000000);
    final BDD bdd = BDDFactory.build(constraint, kernel);
    assertThat(bdd.modelCount()).isEqualTo(BigInteger.valueOf(6435));
    assertThat(bdd.enumerateAllModels()).hasSize(6435);
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) Test(org.junit.jupiter.api.Test)

Example 19 with BDDKernel

use of org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel in project LogicNG by logic-ng.

the class BDDModelEnumerationTest method testExo.

@Test
public void testExo() {
    final FormulaFactory f = new FormulaFactory();
    final Formula constraint = f.exo(generateVariables(100, f)).cnf();
    final BDDKernel kernel = new BDDKernel(f, constraint.variables().size(), 100000, 1000000);
    final BDD bdd = BDDFactory.build(constraint, kernel);
    assertThat(bdd.modelCount()).isEqualTo(BigInteger.valueOf(100));
    assertThat(bdd.enumerateAllModels()).hasSize(100);
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) Test(org.junit.jupiter.api.Test)

Example 20 with BDDKernel

use of org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel in project LogicNG by logic-ng.

the class BDDModelEnumerationTest method testAmo.

@Test
public void testAmo() {
    final FormulaFactory f = new FormulaFactory();
    final Formula constraint = f.amo(generateVariables(100, f)).cnf();
    final BDDKernel kernel = new BDDKernel(f, constraint.variables().size(), 100000, 1000000);
    final BDD bdd = BDDFactory.build(constraint, kernel);
    assertThat(bdd.modelCount()).isEqualTo(BigInteger.valueOf(221));
    assertThat(bdd.enumerateAllModels(generateVariables(100, f))).hasSize(101);
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) Test(org.junit.jupiter.api.Test)

Aggregations

BDDKernel (org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel)36 Test (org.junit.jupiter.api.Test)23 Formula (org.logicng.formulas.Formula)20 FormulaFactory (org.logicng.formulas.FormulaFactory)17 PropositionalParser (org.logicng.io.parsers.PropositionalParser)6 BDDOperations (org.logicng.knowledgecompilation.bdds.jbuddy.BDDOperations)6 Variable (org.logicng.formulas.Variable)5 BDD (org.logicng.knowledgecompilation.bdds.BDD)5 VariableOrderingProvider (org.logicng.knowledgecompilation.bdds.orderings.VariableOrderingProvider)5 Assignment (org.logicng.datastructures.Assignment)4 NQueensGenerator (org.logicng.testutils.NQueensGenerator)4 NumberOfNodesBDDHandler (org.logicng.handlers.NumberOfNodesBDDHandler)3 BDDInnerNode (org.logicng.knowledgecompilation.bdds.datastructures.BDDInnerNode)3 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 TimeoutBDDHandler (org.logicng.handlers.TimeoutBDDHandler)2 LngBDDFunction (org.logicng.knowledgecompilation.bdds.functions.LngBDDFunction)2