use of org.logicng.propositions.StandardProposition in project LogicNG by logic-ng.
the class DRUPTest method testPropositionHandling.
@Test
public void testPropositionHandling() throws ParserException {
final List<Proposition> propositions = new ArrayList<>();
propositions.add(new StandardProposition("P1", this.f.parse("((a & b) => c) & ((a & b) => d)")));
propositions.add(new StandardProposition("P2", this.f.parse("(c & d) <=> ~e")));
propositions.add(new StandardProposition("P3", this.f.parse("~e => f | g")));
propositions.add(new StandardProposition("P4", this.f.parse("(f => ~a) & (g => ~b) & p & q")));
propositions.add(new StandardProposition("P5", this.f.parse("a => b")));
propositions.add(new StandardProposition("P6", this.f.parse("a")));
propositions.add(new StandardProposition("P7", this.f.parse("g | h")));
propositions.add(new StandardProposition("P8", this.f.parse("(x => ~y | z) & (z | w)")));
for (final SATSolver solver : this.solvers) {
solver.addPropositions(propositions);
assertThat(solver.sat()).isEqualTo(FALSE);
final UNSATCore<Proposition> unsatCore = solver.unsatCore();
assertThat(unsatCore.propositions()).containsExactlyInAnyOrder(propositions.get(0), propositions.get(1), propositions.get(2), propositions.get(3), propositions.get(4), propositions.get(5));
solver.reset();
}
}
use of org.logicng.propositions.StandardProposition in project LogicNG by logic-ng.
the class SATTest method testWithRelaxation.
@Test
public void testWithRelaxation() throws ParserException {
final PropositionalParser parser = new PropositionalParser(this.f);
final Formula one = parser.parse("a & b & (c | ~d)");
final Formula two = parser.parse("~a | ~c");
for (final SATSolver s : this.solvers) {
s.add(one);
s.addWithRelaxation(this.f.variable("d"), two);
assertSolverSat(s);
try {
assertThat(s.enumerateAllModels().size()).isEqualTo(2);
} catch (final Exception e) {
assertThat(e instanceof UnsupportedOperationException).isTrue();
}
s.reset();
s.add(one);
s.addWithRelaxation(this.f.variable("d"), new StandardProposition(two));
assertSolverSat(s);
try {
assertThat(s.enumerateAllModels().size()).isEqualTo(2);
} catch (final Exception e) {
assertThat(e instanceof UnsupportedOperationException).isTrue();
}
s.reset();
s.add(one);
s.addWithRelaxation(this.f.variable("d"), two);
assertSolverSat(s);
try {
assertThat(s.enumerateAllModels().size()).isEqualTo(2);
} catch (final Exception e) {
assertThat(e instanceof UnsupportedOperationException).isTrue();
}
s.reset();
s.add(one);
s.addWithRelaxation(this.f.variable("d"), Arrays.asList(two, this.f.verum()));
assertSolverSat(s);
try {
assertThat(s.enumerateAllModels().size()).isEqualTo(2);
} catch (final Exception e) {
assertThat(e instanceof UnsupportedOperationException).isTrue();
}
s.reset();
}
}
use of org.logicng.propositions.StandardProposition in project LogicNG by logic-ng.
the class UnsatCoreFunction method handleTrivialCase.
private UNSATCore<Proposition> handleTrivialCase(final MiniSat solver) {
final LNGVector<MiniSatStyleSolver.ProofInformation> clauses = solver.underlyingSolver().pgOriginalClauses();
for (int i = 0; i < clauses.size(); i++) {
for (int j = i + 1; j < clauses.size(); j++) {
if (clauses.get(i).clause().size() == 1 && clauses.get(j).clause().size() == 1 && clauses.get(i).clause().get(0) + clauses.get(j).clause().get(0) == 0) {
final LinkedHashSet<Proposition> propositions = new LinkedHashSet<>();
final Proposition pi = clauses.get(i).proposition();
final Proposition pj = clauses.get(j).proposition();
propositions.add(pi != null ? pi : new StandardProposition(getFormulaForVector(solver, clauses.get(i).clause())));
propositions.add(pj != null ? pj : new StandardProposition(getFormulaForVector(solver, clauses.get(j).clause())));
return new UNSATCore<>(new ArrayList<>(propositions), false);
}
}
}
throw new IllegalStateException("Should be a trivial unsat core, but did not found one.");
}
Aggregations