Search in sources :

Example 6 with BDDKernel

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

the class TimeoutBDDHandlerTest method testTimeoutHandlerFixedEnd.

@Test
public void testTimeoutHandlerFixedEnd() {
    final Formula formula = pg.generate(10);
    final VariableOrderingProvider provider = VariableOrdering.BFS.provider();
    final BDDKernel kernel = new BDDKernel(this.f, provider.getOrder(formula), 100, 100);
    final TimeoutBDDHandler handler = new TimeoutBDDHandler(System.currentTimeMillis() + 100L, TimeoutHandler.TimerType.FIXED_END);
    final BDD result = BDDFactory.build(formula, kernel, handler);
    assertThat(handler.aborted).isTrue();
    assertThat(result).isEqualTo(new BDD(BDDKernel.BDD_ABORT, kernel));
}
Also used : Formula(org.logicng.formulas.Formula) VariableOrderingProvider(org.logicng.knowledgecompilation.bdds.orderings.VariableOrderingProvider) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) BDD(org.logicng.knowledgecompilation.bdds.BDD) Test(org.junit.jupiter.api.Test)

Example 7 with BDDKernel

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

the class BDDModelEnumerationTest method testModelEnumeration.

@Test
public void testModelEnumeration() {
    for (int i = 0; i < this.formulas.size(); i++) {
        final BDDKernel kernel = new BDDKernel(this.f, this.variables.get(i).size(), 10000, 10000);
        final BDD bdd = BDDFactory.build(this.formulas.get(i), kernel);
        final Set<Assignment> models = new HashSet<>(bdd.enumerateAllModels());
        assertThat(models.size()).isEqualTo(this.expected[i].intValue());
        for (final Assignment model : models) {
            assertThat(this.formulas.get(i).evaluate(model)).isTrue();
        }
    }
}
Also used : Assignment(org.logicng.datastructures.Assignment) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 8 with BDDKernel

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

the class BDDModelEnumerationTest method testModelCount.

@Test
public void testModelCount() {
    for (int i = 0; i < this.formulas.size(); i++) {
        final BDDKernel kernel = new BDDKernel(this.f, this.variables.get(i).size(), 10000, 10000);
        final BDD bdd = BDDFactory.build(this.formulas.get(i), kernel);
        assertThat(bdd.modelCount()).isEqualTo(this.expected[i]);
    }
}
Also used : BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) Test(org.junit.jupiter.api.Test)

Example 9 with BDDKernel

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

the class BDDOperationsTest method init.

@BeforeEach
public void init() throws ParserException {
    this.f = new FormulaFactory();
    this.parser = new PropositionalParser(this.f);
    this.kernel = new BDDKernel(this.f, 3, 1000, 1000);
    this.bddVerum = BDDFactory.build(this.f.verum(), this.kernel);
    this.bddFalsum = BDDFactory.build(this.f.falsum(), this.kernel);
    this.bddPosLit = BDDFactory.build(this.f.literal("A", true), this.kernel);
    this.bddNegLit = BDDFactory.build(this.f.literal("A", false), this.kernel);
    this.bddImpl = BDDFactory.build(this.parser.parse("A => ~B"), this.kernel);
    this.bddEquiv = BDDFactory.build(this.parser.parse("A <=> ~B"), this.kernel);
    this.bddOr = BDDFactory.build(this.parser.parse("A | B | ~C"), this.kernel);
    this.bddAnd = BDDFactory.build(this.parser.parse("A & B & ~C"), this.kernel);
}
Also used : FormulaFactory(org.logicng.formulas.FormulaFactory) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) PropositionalParser(org.logicng.io.parsers.PropositionalParser) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with BDDKernel

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

the class BDDReorderingTest method performReorder.

private void performReorder(final FormulaFactory f, final Formula formula, final BDDReorderingMethod reorderMethod, final boolean withBlocks, final boolean verbose) {
    final BDDKernel kernel = new BDDKernel(f, new ArrayList<>(formula.variables()), 1000, 10000);
    final BDD bdd = BDDFactory.build(formula, kernel);
    final BigInteger count = bdd.modelCount();
    final int usedBefore = new BDDOperations(kernel).nodeCount(bdd.index());
    final long start = System.currentTimeMillis();
    addVariableBlocks(formula.variables().size(), withBlocks, kernel);
    kernel.getReordering().reorder(reorderMethod);
    final long duration = System.currentTimeMillis() - start;
    final int usedAfter = new BDDOperations(kernel).nodeCount(bdd.index());
    assertThat(verifyBddConsistency(f, formula, bdd, count)).isTrue();
    verifyVariableBlocks(f, formula, withBlocks, bdd);
    if (reorderMethod != BDDReorderingMethod.BDD_REORDER_RANDOM) {
        assertThat(usedAfter).isLessThanOrEqualTo(usedBefore);
    }
    final double reduction = (usedBefore - usedAfter) / (double) usedBefore * 100;
    if (verbose) {
        System.out.println(String.format("%-20s: Reduced %7s blocks in %5dms by %.2f%% from %d to %d", reorderMethod, withBlocks ? "with" : "without", duration, reduction, usedBefore, usedAfter));
    }
}
Also used : BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) BDDOperations(org.logicng.knowledgecompilation.bdds.jbuddy.BDDOperations) BigInteger(java.math.BigInteger)

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