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