Search in sources :

Example 1 with VariableOrderingProvider

use of org.logicng.knowledgecompilation.bdds.orderings.VariableOrderingProvider 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 2 with VariableOrderingProvider

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

the class TimeoutBDDHandlerTest method testThatMethodsAreCalled.

@Test
public void testThatMethodsAreCalled() 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);
    BDDFactory.build(formula, kernel, handler);
    verify(handler, times(1)).started();
    verify(handler, atLeast(1)).newRefAdded();
}
Also used : Formula(org.logicng.formulas.Formula) VariableOrderingProvider(org.logicng.knowledgecompilation.bdds.orderings.VariableOrderingProvider) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) Test(org.junit.jupiter.api.Test)

Example 3 with VariableOrderingProvider

use of org.logicng.knowledgecompilation.bdds.orderings.VariableOrderingProvider 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 VariableOrderingProvider

use of org.logicng.knowledgecompilation.bdds.orderings.VariableOrderingProvider 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 VariableOrderingProvider

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

the class Formula method bdd.

/**
 * Generates a BDD from this formula with a given variable ordering.  This is done by generating a new BDD factory,
 * generating the variable order for this formula, and building a new BDD.  If more sophisticated operations should
 * be performed on the BDD or more than one formula should be constructed on the BDD, an own instance of
 * {@link BDDFactory} should be created and used.
 * @param variableOrdering the variable ordering
 * @return the BDD for this formula with the given ordering
 */
public BDD bdd(final VariableOrdering variableOrdering) {
    final Formula formula = this.nnf();
    final int varNum = formula.variables().size();
    final BDDKernel kernel;
    if (variableOrdering == null) {
        kernel = new BDDKernel(this.f, varNum, varNum * 30, varNum * 20);
    } else {
        final VariableOrderingProvider provider = variableOrdering.provider();
        kernel = new BDDKernel(this.f, provider.getOrder(formula), varNum * 30, varNum * 20);
    }
    return BDDFactory.build(formula, kernel, null);
}
Also used : BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) VariableOrderingProvider(org.logicng.knowledgecompilation.bdds.orderings.VariableOrderingProvider)

Aggregations

BDDKernel (org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel)5 VariableOrderingProvider (org.logicng.knowledgecompilation.bdds.orderings.VariableOrderingProvider)5 Test (org.junit.jupiter.api.Test)4 Formula (org.logicng.formulas.Formula)4 BDD (org.logicng.knowledgecompilation.bdds.BDD)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1