Search in sources :

Example 26 with BDDKernel

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

the class LargeBDDTest method testNumberOfNodesHandler.

@Test
public void testNumberOfNodesHandler() throws ParserException {
    final FormulaFactory f = new FormulaFactory();
    final Formula formula = f.parse("A <=> ~(B => C & F & G & ~H | A & D & ~E)");
    final BDDKernel kernel = new BDDKernel(f, formula.variables().size(), 10000, 10000);
    final NumberOfNodesBDDHandler handler = new NumberOfNodesBDDHandler(5);
    final BDD bdd = BDDFactory.build(formula, kernel, handler);
    assertThat(handler.aborted()).isTrue();
    assertThat(bdd.index()).isEqualTo(BDDKernel.BDD_ABORT);
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) NumberOfNodesBDDHandler(org.logicng.handlers.NumberOfNodesBDDHandler) Test(org.junit.jupiter.api.Test)

Example 27 with BDDKernel

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

the class LargeBDDTest method testNumberOfNodesHandlerLarge.

@Test
public void testNumberOfNodesHandlerLarge() {
    final FormulaFactory f = new FormulaFactory();
    final NQueensGenerator generator = new NQueensGenerator(f);
    final Formula queens = generator.generate(10);
    final BDDKernel kernel = new BDDKernel(f, queens.variables().size(), 10000, 10000);
    final NumberOfNodesBDDHandler handler = new NumberOfNodesBDDHandler(5);
    final BDD bdd = BDDFactory.build(queens, kernel, handler);
    assertThat(handler.aborted()).isTrue();
    assertThat(bdd.index()).isEqualTo(BDDKernel.BDD_ABORT);
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) NumberOfNodesBDDHandler(org.logicng.handlers.NumberOfNodesBDDHandler) NQueensGenerator(org.logicng.testutils.NQueensGenerator) Test(org.junit.jupiter.api.Test)

Example 28 with BDDKernel

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

the class LargeBDDTest method testTimeoutBDDHandlerLarge.

@Test
public void testTimeoutBDDHandlerLarge() {
    final FormulaFactory f = new FormulaFactory();
    final NQueensGenerator generator = new NQueensGenerator(f);
    final Formula queens = generator.generate(10);
    final BDDKernel kernel = new BDDKernel(f, queens.variables().size(), 10000, 10000);
    final TimeoutBDDHandler handler = new TimeoutBDDHandler(1000L);
    final BDD bdd = BDDFactory.build(queens, kernel, handler);
    assertThat(handler.aborted()).isTrue();
    assertThat(bdd.index()).isEqualTo(BDDKernel.BDD_ABORT);
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) TimeoutBDDHandler(org.logicng.handlers.TimeoutBDDHandler) NQueensGenerator(org.logicng.testutils.NQueensGenerator) Test(org.junit.jupiter.api.Test)

Example 29 with BDDKernel

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

the class SimpleBDDTest method testAnd.

@Test
public void testAnd() 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 & B & ~C"), kernel, null);
    assertThat(bdd.isTautology()).isFalse();
    assertThat(bdd.isContradiction()).isFalse();
    assertThat(bdd.cnf()).isEqualTo(parser.parse("A & (~A | B) & (~A | ~B | ~C)"));
    assertThat(bdd.dnf()).isEqualTo(parser.parse("A & B & ~C"));
    assertThat(bdd.modelCount()).isEqualTo(BigInteger.valueOf(1));
    assertThat(bdd.underlyingKernel().factory()).isSameAs(f);
    assertThat(bdd.enumerateAllModels()).containsExactlyInAnyOrder(new Assignment(f.literal("A", true), f.literal("B", true), f.literal("C", false)));
    assertThat(bdd.numberOfClausesCNF()).isEqualTo(BigInteger.valueOf(3));
    assertThat(bdd.toLngBdd().toString()).isEqualTo("<A | low=<$false> high=<B | low=<$false> high=<C | low=<$true> high=<$false>>>>");
}
Also used : Assignment(org.logicng.datastructures.Assignment) 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 30 with BDDKernel

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

the class BDDDotFileWriterTest method testWriter.

@Test
public void testWriter() throws IOException, ParserException {
    final FormulaFactory f = new FormulaFactory();
    final PropositionalParser p = new PropositionalParser(f);
    final List<Variable> ordering = Arrays.asList(f.variable("A"), f.variable("B"), f.variable("C"), f.variable("D"));
    final BDDKernel kernel = new BDDKernel(f, ordering, 1000, 1000);
    testFiles("false", BDDFactory.build(p.parse("$false"), kernel));
    testFiles("true", BDDFactory.build(p.parse("$true"), kernel));
    testFiles("a", BDDFactory.build(p.parse("A"), kernel));
    testFiles("not_a", BDDFactory.build(p.parse("~A"), kernel));
    testFiles("impl", BDDFactory.build(p.parse("A => ~C"), kernel));
    testFiles("equiv", BDDFactory.build(p.parse("A <=> ~C"), kernel));
    testFiles("or", BDDFactory.build(p.parse("A | B | ~C"), kernel));
    testFiles("and", BDDFactory.build(p.parse("A & B & ~C"), kernel));
    testFiles("not", BDDFactory.build(p.parse("~(A & B & ~C)"), kernel));
    testFiles("formula", BDDFactory.build(p.parse("(A => (B|~C)) & (B => C & D) & (D <=> A)"), kernel));
}
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)

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