use of org.logicng.propositions.StandardProposition 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.propositions.StandardProposition in project LogicNG by logic-ng.
the class MUSGenerationTest method readDimacs.
private List<StandardProposition> readDimacs(final String fileName) throws IOException {
final List<StandardProposition> result = new ArrayList<>();
final BufferedReader reader = new BufferedReader(new FileReader(fileName));
while (reader.ready()) {
final String line = reader.readLine();
if (!line.startsWith("p") && !line.startsWith("c")) {
final String[] tokens = line.split("\\s");
final List<Literal> clause = new ArrayList<>();
for (int i = 0; i < tokens.length - 1; i++) {
final int lit = Integer.parseInt(tokens[i]);
clause.add(lit < 0 ? this.f.literal("v" + (-lit), false) : this.f.literal("v" + lit, true));
}
result.add(new StandardProposition(this.f.clause(clause)));
}
}
return result;
}
use of org.logicng.propositions.StandardProposition in project LogicNG by logic-ng.
the class SATTest method testAnd2.
@Test
public void testAnd2() {
for (final SATSolver s : this.solvers) {
final StandardProposition prop = new StandardProposition(this.f.and(this.f.literal("a", true), this.f.literal("b", false), this.f.literal("c", true), this.f.literal("d", false)));
s.add(prop);
assertSolverSat(s);
assertThat(s.model().size()).isEqualTo(4);
assertThat(s.model().evaluateLit(this.f.variable("a"))).isTrue();
assertThat(s.model().evaluateLit(this.f.variable("b"))).isFalse();
assertThat(s.model().evaluateLit(this.f.variable("c"))).isTrue();
assertThat(s.model().evaluateLit(this.f.variable("d"))).isFalse();
s.reset();
}
}
use of org.logicng.propositions.StandardProposition in project LogicNG by logic-ng.
the class DRUPTest method testPropositionIncDec.
@Test
public void testPropositionIncDec() throws ParserException {
final SATSolver solver = this.solvers[0];
final StandardProposition p1 = new StandardProposition("P1", this.f.parse("((a & b) => c) & ((a & b) => d)"));
final StandardProposition p2 = new StandardProposition("P2", this.f.parse("(c & d) <=> ~e"));
final StandardProposition p3 = new StandardProposition("P3", this.f.parse("~e => f | g"));
final StandardProposition p4 = new StandardProposition("P4", this.f.parse("(f => ~a) & (g => ~b) & p & q"));
final StandardProposition p5 = new StandardProposition("P5", this.f.parse("a => b"));
final StandardProposition p6 = new StandardProposition("P6", this.f.parse("a"));
final StandardProposition p7 = new StandardProposition("P7", this.f.parse("g | h"));
final StandardProposition p8 = new StandardProposition("P8", this.f.parse("(x => ~y | z) & (z | w)"));
final StandardProposition p9 = new StandardProposition("P9", this.f.parse("a & b"));
final StandardProposition p10 = new StandardProposition("P10", this.f.parse("(p => q) & p"));
final StandardProposition p11 = new StandardProposition("P11", this.f.parse("a & ~q"));
solver.addPropositions(p1, p2, p3, p4);
final SolverState state1 = solver.saveState();
solver.addPropositions(p5, p6);
final SolverState state2 = solver.saveState();
solver.addPropositions(p7, p8);
assertThat(solver.sat()).isEqualTo(FALSE);
UNSATCore<Proposition> unsatCore = solver.unsatCore();
assertThat(unsatCore.propositions()).containsExactlyInAnyOrder(p1, p2, p3, p4, p5, p6);
solver.loadState(state2);
assertThat(solver.sat()).isEqualTo(FALSE);
unsatCore = solver.unsatCore();
assertThat(unsatCore.propositions()).containsExactlyInAnyOrder(p1, p2, p3, p4, p5, p6);
solver.loadState(state1);
solver.add(p9);
assertThat(solver.sat()).isEqualTo(FALSE);
unsatCore = solver.unsatCore();
assertThat(unsatCore.propositions()).containsExactlyInAnyOrder(p1, p2, p3, p4, p9);
solver.loadState(state1);
solver.add(p5);
solver.add(p6);
assertThat(solver.sat()).isEqualTo(FALSE);
unsatCore = solver.unsatCore();
assertThat(unsatCore.propositions()).containsExactlyInAnyOrder(p1, p2, p3, p4, p5, p6);
solver.loadState(state1);
solver.add(p10);
solver.add(p11);
assertThat(solver.sat()).isEqualTo(FALSE);
unsatCore = solver.unsatCore();
assertThat(unsatCore.propositions()).containsExactlyInAnyOrder(p4, p11);
}
use of org.logicng.propositions.StandardProposition in project LogicNG by logic-ng.
the class DRUPTest method testWithSpecialUnitCaseMiniSat.
@Test
public void testWithSpecialUnitCaseMiniSat() throws ParserException {
final FormulaFactory f = new FormulaFactory();
final SATSolver solver = MiniSat.miniSat(f, MiniSatConfig.builder().proofGeneration(true).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);
}
Aggregations