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}");
}
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));
}
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);
}
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);
}
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);
}
Aggregations