use of org.logicng.solvers.SATSolver in project LogicNG by logic-ng.
the class DRUPTest method testUnsatCoresFromDimacs.
@Test
public void testUnsatCoresFromDimacs() throws IOException {
final List<List<Formula>> cnfs = new ArrayList<>(3);
cnfs.add(DimacsReader.readCNF("src/test/resources/drup/simple_input.cnf", this.f));
cnfs.add(DimacsReader.readCNF("src/test/resources/drup/pg4_input.cnf", this.f));
cnfs.add(DimacsReader.readCNF("src/test/resources/drup/avg_input.cnf", this.f, "var"));
for (final SATSolver solver : this.solvers) {
for (final List<Formula> cnf : cnfs) {
solver.add(cnf);
assertSolverUnsat(solver);
final UNSATCore<Proposition> unsatCore = solver.unsatCore();
verifyCore(unsatCore, cnf);
solver.reset();
}
}
}
use of org.logicng.solvers.SATSolver in project LogicNG by logic-ng.
the class DRUPTest method testUnsatCoresAimTestset.
@Test
public void testUnsatCoresAimTestset() throws IOException {
final File testFolder = new File("src/test/resources/sat/unsat");
final File[] files = testFolder.listFiles();
assert files != null;
int count = 0;
for (final SATSolver solver : this.solvers) {
for (final File file : files) {
final String fileName = file.getName();
if (fileName.endsWith(".cnf")) {
final List<Formula> cnf = DimacsReader.readCNF(file, this.f);
solver.add(cnf);
assertSolverUnsat(solver);
final UNSATCore<Proposition> unsatCore = solver.unsatCore();
verifyCore(unsatCore, cnf);
solver.reset();
count++;
}
}
solver.reset();
}
assertThat(count).isEqualTo(36 * this.solvers.length);
}
use of org.logicng.solvers.SATSolver in project LogicNG by logic-ng.
the class DRUPTest method testCoreAndAssumptions.
@Test
public void testCoreAndAssumptions() throws ParserException {
final FormulaFactory f = new FormulaFactory();
final SATSolver solver = MiniSat.miniSat(f, MiniSatConfig.builder().proofGeneration(true).cnfMethod(MiniSatConfig.CNFMethod.PG_ON_SOLVER).build());
final StandardProposition p1 = new StandardProposition(f.parse("A => B"));
final StandardProposition p2 = new StandardProposition(f.parse("A & B => G"));
final StandardProposition p3 = new StandardProposition(f.or(f.literal("X", false), f.literal("A", true)));
final StandardProposition p4 = new StandardProposition(f.or(f.literal("X", false), f.literal("G", false)));
final StandardProposition p5 = new StandardProposition(f.literal("G", false));
final StandardProposition p6 = new StandardProposition(f.literal("A", true));
solver.add(p1);
solver.add(p2);
solver.add(p3);
solver.add(p4);
// Assumption call
solver.sat(f.variable("X"));
solver.add(p5);
solver.add(p6);
solver.sat();
final UNSATCore<Proposition> unsatCore = solver.unsatCore();
assertThat(unsatCore.propositions()).containsExactlyInAnyOrder(p1, p2, p5, p6);
}
use of org.logicng.solvers.SATSolver in project LogicNG by logic-ng.
the class DRUPTest method testWithSpecialUnitCaseGlucose.
@Test
public void testWithSpecialUnitCaseGlucose() throws ParserException {
final FormulaFactory f = new FormulaFactory();
final SATSolver solver = MiniSat.glucose(f, MiniSatConfig.builder().proofGeneration(true).incremental(false).build(), GlucoseConfig.builder().build());
final StandardProposition p1 = new StandardProposition(f.parse("a => b"));
final StandardProposition p2 = new StandardProposition(f.parse("a => c | d"));
final StandardProposition p3 = new StandardProposition(f.parse("b => c | d"));
final StandardProposition p4 = new StandardProposition(f.parse("e | f | g | h => i"));
final StandardProposition p5 = new StandardProposition(f.parse("~j => k | j"));
final StandardProposition p6 = new StandardProposition(f.parse("b => ~(e | f)"));
final StandardProposition p7 = new StandardProposition(f.parse("c => ~j"));
final StandardProposition p8 = new StandardProposition(f.parse("l | m => ~i"));
final StandardProposition p9 = new StandardProposition(f.parse("j => (f + g + h = 1)"));
final StandardProposition p10 = new StandardProposition(f.parse("d => (l + m + e + f = 1)"));
final StandardProposition p11 = new StandardProposition(f.parse("~k"));
solver.addPropositions(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11);
assertThat(solver.sat()).isEqualTo(TRUE);
solver.add(f.variable("a"));
assertThat(solver.sat()).isEqualTo(FALSE);
assertThat(solver.unsatCore().propositions()).contains(p1, p2, p4, p5, p6, p7, p8, p9, p10, p11);
}
use of org.logicng.solvers.SATSolver in project LogicNG by logic-ng.
the class DRUPTest method testWithCcPropositions.
@Test
public void testWithCcPropositions() throws ParserException {
final FormulaFactory f = new FormulaFactory();
final SATSolver solver = MiniSat.miniSat(f, MiniSatConfig.builder().proofGeneration(true).cnfMethod(MiniSatConfig.CNFMethod.PG_ON_SOLVER).build());
final ExtendedProposition<StringBackpack> p1 = new ExtendedProposition<>(new StringBackpack("CC"), f.parse("A + B + C <= 1"));
final StandardProposition p2 = new StandardProposition(f.parse("A"));
final StandardProposition p3 = new StandardProposition(f.parse("B"));
final StandardProposition p4 = new StandardProposition(f.parse("X & Y"));
solver.add(p1);
solver.add(p2);
solver.add(p3);
solver.add(p4);
assertThat(solver.sat()).isEqualTo(FALSE);
assertThat(solver.unsatCore().propositions()).containsExactlyInAnyOrder(p1, p2, p3);
}
Aggregations