use of org.logicng.transformations.cnf.TseitinTransformation in project LogicNG by logic-ng.
the class ModelTest method testCNFWithAuxiliaryVarsRestrictedToOriginal.
@ParameterizedTest
@MethodSource("solvers")
public void testCNFWithAuxiliaryVarsRestrictedToOriginal(final SATSolver solver) throws ParserException {
solver.reset();
final Formula formula = f.parse("(A => B & C) & (~A => C & ~D) & (C => (D & E | ~E & B)) & ~F");
final Formula cnf = formula.transform(new TseitinTransformation(0));
solver.add(cnf);
solver.sat();
final Assignment model = solver.model(formula.variables());
assertThat(formula.evaluate(model)).isTrue();
final List<Assignment> allModels = solver.enumerateAllModels(formula.variables());
assertThat(allModels).hasSize(4);
assertThat(model.formula(f).variables()).isEqualTo(formula.variables());
for (final Assignment assignment : allModels) {
assertThat(formula.evaluate(assignment)).isTrue();
assertThat(assignment.formula(f).variables()).isEqualTo(formula.variables());
}
}
use of org.logicng.transformations.cnf.TseitinTransformation in project LogicNG by logic-ng.
the class FormulaFactoryImporterTest method testAdjustCounters.
@Test
public void testAdjustCounters() throws ParserException {
final FormulaFactory f = new FormulaFactory(FormulaFactoryConfig.builder().name("Factory").build());
final PseudoBooleanParser p = new PseudoBooleanParser(f);
final Formula cc = p.parse("A + B + C + D + E <= 2").cnf();
final Formula pbc = p.parse("2*A + -2*B + 3*C + D + 2*E <= 3").cnf();
final Formula cnf = p.parse("A & B & C | C & D & ~A").transform(new TseitinTransformation(0));
final FormulaFactory g = new FormulaFactory();
g.newCNFVariable();
g.newCNFVariable();
g.newCCVariable();
g.newCCVariable();
g.newCCVariable();
g.newPBVariable();
g.newPBVariable();
g.newPBVariable();
g.importFormula(cc);
g.importFormula(pbc);
g.importFormula(cnf);
assertThat(g.statistics().cnfCounter()).isEqualTo(2);
assertThat(g.statistics().ccCounter()).isEqualTo(13);
assertThat(g.statistics().pbCounter()).isEqualTo(25);
}
use of org.logicng.transformations.cnf.TseitinTransformation in project LogicNG by logic-ng.
the class ModelTest method testCNFWithAuxiliaryVars.
@ParameterizedTest
@MethodSource("solvers")
public void testCNFWithAuxiliaryVars(final MiniSat solver) throws ParserException {
solver.reset();
final Formula formula = f.parse("(A => B & C) & (~A => C & ~D) & (C => (D & E | ~E & B)) & ~F");
final Formula cnf = formula.transform(new TseitinTransformation(0));
solver.add(cnf);
solver.sat();
final Assignment model = solver.model();
assertThat(formula.evaluate(model)).isTrue();
final List<Assignment> allModels = solver.enumerateAllModels();
assertThat(allModels).hasSize(4);
if (solver.getConfig().isAuxiliaryVariablesInModels()) {
assertThat(model.formula(f).variables()).isEqualTo(cnf.variables());
for (final Assignment assignment : allModels) {
assertThat(formula.evaluate(assignment)).isTrue();
assertThat(assignment.formula(f).variables()).isEqualTo(cnf.variables());
}
} else {
assertThat(model.formula(f).variables()).isEqualTo(formula.variables());
for (final Assignment assignment : allModels) {
assertThat(formula.evaluate(assignment)).isTrue();
assertThat(assignment.formula(f).variables()).isEqualTo(formula.variables());
}
}
}
Aggregations