use of org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel in project LogicNG by logic-ng.
the class BDDCNFFunction method apply.
@Override
public Formula apply(final BDD bdd) {
final BDDKernel kernel = bdd.underlyingKernel();
final List<byte[]> unsatPaths = new BDDOperations(kernel).allUnsat(bdd.index());
final List<Formula> clauses = new ArrayList<>();
List<Formula> literals;
for (final byte[] path : unsatPaths) {
literals = new ArrayList<>();
for (int i = 0; i < path.length; i++) {
if (path[i] == 0) {
literals.add(kernel.getVariableForIndex(i));
} else if (path[i] == 1) {
literals.add(kernel.getVariableForIndex(i).negate());
}
}
clauses.add(kernel.factory().or(literals));
}
return kernel.factory().and(clauses);
}
use of org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel 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<>());
}
use of org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel 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.jbuddy.BDDKernel 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.jbuddy.BDDKernel 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();
}
Aggregations