Search in sources :

Example 11 with BDDKernel

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

the class LargeBDDTest method testNumberOfNodesHandlerSmall.

@Test
public void testNumberOfNodesHandlerSmall() {
    final FormulaFactory f = new FormulaFactory();
    final NQueensGenerator generator = new NQueensGenerator(f);
    final Formula queens = generator.generate(4);
    final BDDKernel kernel = new BDDKernel(f, queens.variables().size(), 10000, 10000);
    final NumberOfNodesBDDHandler handler = new NumberOfNodesBDDHandler(1000);
    final BDD bdd = BDDFactory.build(queens, kernel, handler);
    assertThat(handler.aborted()).isFalse();
    assertThat(bdd.index()).isNotEqualTo(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 12 with BDDKernel

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

the class LargeBDDTest method testTimeoutBDDHandlerSmall.

@Test
public void testTimeoutBDDHandlerSmall() {
    final FormulaFactory f = new FormulaFactory();
    final NQueensGenerator generator = new NQueensGenerator(f);
    final Formula queens = generator.generate(4);
    final BDDKernel kernel = new BDDKernel(f, queens.variables().size(), 10000, 10000);
    final TimeoutBDDHandler handler = new TimeoutBDDHandler(2000L);
    final BDD bdd = BDDFactory.build(queens, kernel, handler);
    assertThat(handler.aborted()).isFalse();
    assertThat(bdd.index()).isNotEqualTo(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 13 with BDDKernel

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

the class LargeBDDTest method testQueens.

private void testQueens(final FormulaFactory f, final NQueensGenerator generator, final int size, final int models) {
    final Formula queens = generator.generate(size);
    final BDDKernel kernel = new BDDKernel(f, queens.variables().size(), 10000, 10000);
    final BDD bdd = BDDFactory.build(queens, kernel);
    final Formula cnf = bdd.cnf();
    assertThat(cnf.holds(CNFPredicate.get())).isTrue();
    final BDD cnfBDD = BDDFactory.build(cnf, kernel);
    assertThat(cnfBDD).isEqualTo(bdd);
    assertThat(bdd.support()).isEqualTo(queens.variables());
    assertThat(bdd.modelCount()).isEqualTo(BigInteger.valueOf(models));
}
Also used : Formula(org.logicng.formulas.Formula) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel)

Example 14 with BDDKernel

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

the class LargeBDDTest method testPigeonHole.

private void testPigeonHole(final FormulaFactory f, final PigeonHoleGenerator generator, final int size) {
    final Formula pigeon = generator.generate(size);
    final BDDKernel kernel = new BDDKernel(f, pigeon.variables().size(), 10000, 10000);
    final BDD bdd = BDDFactory.build(pigeon, kernel);
    assertThat(bdd.isContradiction()).isTrue();
}
Also used : Formula(org.logicng.formulas.Formula) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel)

Example 15 with BDDKernel

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

the class SimpleBDDTest method testFalse.

@Test
public void testFalse() {
    final FormulaFactory f = new FormulaFactory();
    final BDDKernel kernel = new BDDKernel(f, 0, 100, 100);
    final BDD bdd = BDDFactory.build(f.falsum(), kernel, null);
    assertThat(bdd.isTautology()).isFalse();
    assertThat(bdd.isContradiction()).isTrue();
    assertThat(bdd.cnf()).isEqualTo(f.falsum());
    assertThat(bdd.dnf()).isEqualTo(f.falsum());
    assertThat(bdd.modelCount()).isEqualTo(BigInteger.ZERO);
    assertThat(bdd.underlyingKernel()).isSameAs(kernel);
    assertThat(bdd.underlyingKernel().factory()).isSameAs(f);
    assertThat(bdd.enumerateAllModels()).isEmpty();
    assertThat(bdd.numberOfClausesCNF()).isEqualTo(BigInteger.ONE);
    assertThat(bdd.toLngBdd()).isEqualTo(BDDConstant.getFalsumNode(f));
}
Also used : 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