Search in sources :

Example 1 with BDD

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

the class LngBDDFunction method apply.

@Override
public BDDNode apply(final BDD bdd) {
    final BDDKernel kernel = bdd.underlyingKernel();
    final int index = bdd.index();
    final Map<Integer, int[]> kernelNodeMap = new BDDOperations(kernel).allNodes(index).stream().collect(Collectors.toMap(node -> node[0], node -> node));
    return buildBDDNode(index, kernel, kernelNodeMap, new HashMap<>());
}
Also used : BDDNode(org.logicng.knowledgecompilation.bdds.datastructures.BDDNode) BDD(org.logicng.knowledgecompilation.bdds.BDD) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) Variable(org.logicng.formulas.Variable) Map(java.util.Map) BDDInnerNode(org.logicng.knowledgecompilation.bdds.datastructures.BDDInnerNode) BDDConstant(org.logicng.knowledgecompilation.bdds.datastructures.BDDConstant) BDDOperations(org.logicng.knowledgecompilation.bdds.jbuddy.BDDOperations) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) BDDOperations(org.logicng.knowledgecompilation.bdds.jbuddy.BDDOperations)

Example 2 with BDD

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

the class TimeoutBDDHandlerTest method testTimeoutHandlerSingleTimeout.

@Test
public void testTimeoutHandlerSingleTimeout() {
    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(100L);
    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 3 with BDD

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

the class TimeoutBDDHandlerTest method testThatNewRefAddedHandledProperly.

@Test
public void testThatNewRefAddedHandledProperly() throws ParserException {
    final Formula formula = f.parse("(A => ~B) & ((A & C) | ~(D & ~C)) & (A | Y | X)");
    final VariableOrderingProvider provider = VariableOrdering.BFS.provider();
    final BDDKernel kernel = new BDDKernel(this.f, provider.getOrder(formula), 100, 100);
    final TimeoutBDDHandler handler = Mockito.mock(TimeoutBDDHandler.class);
    final AtomicInteger count = new AtomicInteger(0);
    when(handler.newRefAdded()).then(invocationOnMock -> count.addAndGet(1) < 5);
    final BDD result = BDDFactory.build(formula, kernel, handler);
    assertThat(result).isEqualTo(new BDD(BDDKernel.BDD_ABORT, kernel));
    verify(handler, times(1)).started();
    verify(handler, times(5)).newRefAdded();
}
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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test)

Example 4 with BDD

use of org.logicng.knowledgecompilation.bdds.BDD 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 5 with BDD

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

the class DnnfCompilerTest method countWithBdd.

private BigInteger countWithBdd(final Formula formula) {
    if (formula.type() == FType.TRUE) {
        return BigInteger.ONE;
    } else if (formula.type() == FType.FALSE) {
        return BigInteger.ZERO;
    }
    final BDDKernel kernel = new BDDKernel(formula.factory(), new ForceOrdering().getOrder(formula), 100000, 1000000);
    final BDD bdd = BDDFactory.build(formula, kernel);
    return bdd.modelCount();
}
Also used : BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) BDD(org.logicng.knowledgecompilation.bdds.BDD) ForceOrdering(org.logicng.knowledgecompilation.bdds.orderings.ForceOrdering)

Aggregations

BDD (org.logicng.knowledgecompilation.bdds.BDD)5 BDDKernel (org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel)5 Test (org.junit.jupiter.api.Test)3 Formula (org.logicng.formulas.Formula)3 VariableOrderingProvider (org.logicng.knowledgecompilation.bdds.orderings.VariableOrderingProvider)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Variable (org.logicng.formulas.Variable)1 BDDConstant (org.logicng.knowledgecompilation.bdds.datastructures.BDDConstant)1 BDDInnerNode (org.logicng.knowledgecompilation.bdds.datastructures.BDDInnerNode)1 BDDNode (org.logicng.knowledgecompilation.bdds.datastructures.BDDNode)1 BDDOperations (org.logicng.knowledgecompilation.bdds.jbuddy.BDDOperations)1 ForceOrdering (org.logicng.knowledgecompilation.bdds.orderings.ForceOrdering)1