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));
}
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();
}
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();
}
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));
}
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);
}
Aggregations