Search in sources :

Example 6 with StandardProposition

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);
}
Also used : StandardProposition(org.logicng.propositions.StandardProposition) MiniSat(org.logicng.solvers.MiniSat)

Example 7 with StandardProposition

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;
}
Also used : StandardProposition(org.logicng.propositions.StandardProposition) Literal(org.logicng.formulas.Literal) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 8 with StandardProposition

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

Example 9 with StandardProposition

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);
}
Also used : SATSolver(org.logicng.solvers.SATSolver) StandardProposition(org.logicng.propositions.StandardProposition) SolverState(org.logicng.solvers.SolverState) 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 10 with StandardProposition

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);
}
Also used : SATSolver(org.logicng.solvers.SATSolver) StandardProposition(org.logicng.propositions.StandardProposition) FormulaFactory(org.logicng.formulas.FormulaFactory) LogicNGTest(org.logicng.LogicNGTest) Test(org.junit.jupiter.api.Test)

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