use of org.logicng.knowledgecompilation.bdds.functions.LngBDDFunction in project LogicNG by logic-ng.
the class BDDReorderingTest method testSwappingMultipleBdds.
@Test
public void testSwappingMultipleBdds() throws ParserException {
final BDDKernel kernel = new BDDKernel(this.f, Arrays.asList(this.A, this.B, this.C), 100, 100);
final Formula formula1 = this.f.parse("a | b | c");
final Formula formula2 = this.f.parse("a & b");
final BDD bdd1 = BDDFactory.build(formula1, kernel);
final BDD bdd2 = BDDFactory.build(formula2, kernel);
assertThat(bdd1.getVariableOrder()).containsExactly(this.A, this.B, this.C);
assertThat(bdd2.getVariableOrder()).containsExactly(this.A, this.B, this.C);
assertThat(bdd2.apply(new LngBDDFunction())).isEqualTo(new BDDInnerNode(this.A, BDDConstant.getFalsumNode(this.f), new BDDInnerNode(this.B, BDDConstant.getFalsumNode(this.f), BDDConstant.getVerumNode(this.f))));
bdd1.swapVariables(this.A, this.B);
assertThat(bdd1.getVariableOrder()).containsExactly(this.B, this.A, this.C);
assertThat(bdd2.getVariableOrder()).containsExactly(this.B, this.A, this.C);
assertThat(bdd2.apply(new LngBDDFunction())).isEqualTo(new BDDInnerNode(this.B, BDDConstant.getFalsumNode(this.f), new BDDInnerNode(this.A, BDDConstant.getFalsumNode(this.f), BDDConstant.getVerumNode(this.f))));
}
use of org.logicng.knowledgecompilation.bdds.functions.LngBDDFunction in project LogicNG by logic-ng.
the class BDDReorderingTest method testSwapping.
@Test
public void testSwapping() throws ParserException {
final BDDKernel kernel = new BDDKernel(this.f, Arrays.asList(this.A, this.B, this.C), 100, 100);
final Formula formula = this.f.parse("a | b | c");
final BDD bdd = BDDFactory.build(formula, kernel);
assertThat(bdd.getVariableOrder()).containsExactly(this.A, this.B, this.C);
bdd.swapVariables(this.A, this.B);
assertThat(bdd.getVariableOrder()).containsExactly(this.B, this.A, this.C);
bdd.swapVariables(this.A, this.B);
assertThat(bdd.getVariableOrder()).containsExactly(this.A, this.B, this.C);
bdd.swapVariables(this.A, this.A);
assertThat(bdd.getVariableOrder()).containsExactly(this.A, this.B, this.C);
bdd.swapVariables(this.A, this.C);
assertThat(bdd.getVariableOrder()).containsExactly(this.C, this.B, this.A);
bdd.swapVariables(this.B, this.C);
assertThat(bdd.getVariableOrder()).containsExactly(this.B, this.C, this.A);
assertThat(this.f.equivalence(formula, bdd.cnf()).holds(new TautologyPredicate(this.f))).isTrue();
assertThat(bdd.apply(new LngBDDFunction())).isEqualTo(new BDDInnerNode(this.B, new BDDInnerNode(this.C, new BDDInnerNode(this.A, BDDConstant.getFalsumNode(this.f), BDDConstant.getVerumNode(this.f)), BDDConstant.getVerumNode(this.f)), BDDConstant.getVerumNode(this.f)));
assertThatThrownBy(() -> bdd.swapVariables(this.B, this.X)).isInstanceOf(IllegalArgumentException.class);
}
Aggregations