use of org.logicng.solvers.MiniSat in project LogicNG by logic-ng.
the class DRUPTest method testCoreAndAssumptions2.
@Test
public void testCoreAndAssumptions2() throws ParserException {
final FormulaFactory f = new FormulaFactory();
final MiniSat solver = MiniSat.miniSat(f, MiniSatConfig.builder().proofGeneration(true).cnfMethod(MiniSatConfig.CNFMethod.PG_ON_SOLVER).build());
solver.add(f.parse("~C => D"));
solver.add(f.parse("C => D"));
solver.add(f.parse("D => B | A"));
solver.add(f.parse("B => X"));
solver.add(f.parse("B => ~X"));
solver.sat(f.literal("A", false));
solver.add(f.parse("~A"));
solver.sat();
assertThat(solver.unsatCore()).isNotNull();
}
use of org.logicng.solvers.MiniSat in project LogicNG by logic-ng.
the class DRUPTest method testCoreAndAssumptions3.
@Test
public void testCoreAndAssumptions3() throws ParserException {
// Unit test for DRUP issue which led to java.lang.ArrayIndexOutOfBoundsException: -1
final FormulaFactory f = new FormulaFactory();
final MiniSat solver = MiniSat.miniSat(f, MiniSatConfig.builder().proofGeneration(true).cnfMethod(MiniSatConfig.CNFMethod.PG_ON_SOLVER).build());
solver.add(f.parse("X => Y"));
solver.add(f.parse("X => Z"));
solver.add(f.parse("C => E"));
solver.add(f.parse("D => ~F"));
solver.add(f.parse("B => M"));
solver.add(f.parse("D => N"));
solver.add(f.parse("G => O"));
solver.add(f.parse("A => B"));
solver.add(f.parse("T1 <=> A & K & ~B & ~C"));
solver.add(f.parse("T2 <=> A & B & C & K"));
solver.add(f.parse("T1 + T2 = 1"));
// required for DRUP issue
solver.sat();
solver.add(f.parse("Y => ~X & D"));
solver.add(f.parse("X"));
solver.sat();
assertThat(solver.unsatCore()).isNotNull();
}
use of org.logicng.solvers.MiniSat in project LogicNG by logic-ng.
the class DRUPTest method verifyCore.
/**
* Checks that each formula of the core is part of the original problem and that the core is really unsat.
* @param originalCore the original core
* @param cnf the original problem
*/
private void verifyCore(final UNSATCore<Proposition> originalCore, final List<Formula> cnf) {
final List<Formula> core = new ArrayList<>(originalCore.propositions().size());
for (final Proposition prop : originalCore.propositions()) {
core.add(prop.formula());
}
final SoftAssertions softly = new SoftAssertions();
softly.assertThat(cnf).as("Core contains only original clauses").containsAll(core);
final MiniSat solver = MiniSat.glucose(this.f, MiniSatConfig.builder().proofGeneration(true).incremental(false).build(), GlucoseConfig.builder().build());
solver.add(core);
softly.assertThat(solver.sat()).as("Core is unsatisfiable").isEqualTo(Tristate.FALSE);
softly.assertAll();
}
use of org.logicng.solvers.MiniSat in project LogicNG by logic-ng.
the class MUSGenerationTest method testMUS.
private void testMUS(final List<StandardProposition> original, final UNSATCore<StandardProposition> mus) {
assertThat(mus.isMUS()).isTrue();
assertThat(mus.propositions().size() <= original.size()).isTrue();
final MiniSat miniSat = MiniSat.miniSat(this.f);
for (final StandardProposition p : mus.propositions()) {
assertThat(original.contains(p)).isTrue();
assertThat(miniSat.sat()).isEqualTo(Tristate.TRUE);
miniSat.add(p);
}
assertThat(miniSat.sat()).isEqualTo(Tristate.FALSE);
}
use of org.logicng.solvers.MiniSat in project LogicNG by logic-ng.
the class BackboneGenerationTest method testSmallFormulas.
@Test
public void testSmallFormulas() throws IOException, ParserException {
final FormulaFactory f = new FormulaFactory();
final Formula formula = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/small_formulas.txt", f);
final MiniSat solver = MiniSat.miniSat(f);
solver.add(formula);
final Backbone backbone = solver.execute(BackboneFunction.builder().variables(formula.variables()).build());
assertThat(verifyBackbone(backbone, formula, formula.variables())).isTrue();
}
Aggregations