Search in sources :

Example 16 with StandardProposition

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();
    }
}
Also used : StandardProposition(org.logicng.propositions.StandardProposition) SATSolver(org.logicng.solvers.SATSolver) ArrayList(java.util.ArrayList) StandardProposition(org.logicng.propositions.StandardProposition) Proposition(org.logicng.propositions.Proposition) ExtendedProposition(org.logicng.propositions.ExtendedProposition) LogicNGTest(org.logicng.LogicNGTest) Test(org.junit.jupiter.api.Test)

Example 17 with StandardProposition

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();
    }
}
Also used : SATSolver(org.logicng.solvers.SATSolver) StandardProposition(org.logicng.propositions.StandardProposition) Formula(org.logicng.formulas.Formula) IOException(java.io.IOException) ParserException(org.logicng.io.parsers.ParserException) PropositionalParser(org.logicng.io.parsers.PropositionalParser) LogicNGTest(org.logicng.LogicNGTest) Test(org.junit.jupiter.api.Test)

Example 18 with StandardProposition

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.");
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StandardProposition(org.logicng.propositions.StandardProposition) UNSATCore(org.logicng.explanations.UNSATCore) StandardProposition(org.logicng.propositions.StandardProposition) Proposition(org.logicng.propositions.Proposition)

Aggregations

StandardProposition (org.logicng.propositions.StandardProposition)18 Test (org.junit.jupiter.api.Test)13 LogicNGTest (org.logicng.LogicNGTest)9 SATSolver (org.logicng.solvers.SATSolver)9 Proposition (org.logicng.propositions.Proposition)6 ExtendedProposition (org.logicng.propositions.ExtendedProposition)5 FormulaFactory (org.logicng.formulas.FormulaFactory)4 ArrayList (java.util.ArrayList)3 Formula (org.logicng.formulas.Formula)3 LinkedHashSet (java.util.LinkedHashSet)2 UNSATCore (org.logicng.explanations.UNSATCore)2 BoundedSatHandler (org.logicng.handlers.BoundedSatHandler)2 SATHandler (org.logicng.handlers.SATHandler)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LNGIntVector (org.logicng.collections.LNGIntVector)1 LNGVector (org.logicng.collections.LNGVector)1 DRUPTrim (org.logicng.explanations.drup.DRUPTrim)1