Search in sources :

Example 1 with MiniSat

use of org.logicng.solvers.MiniSat in project LogicNG by logic-ng.

the class DRUPTest method testCoreAndAssumptions2.

@Test
public void testCoreAndAssumptions2() throws ParserException {
    final FormulaFactory f = new FormulaFactory();
    final MiniSat solver = MiniSat.miniSat(f, MiniSatConfig.builder().proofGeneration(true).cnfMethod(MiniSatConfig.CNFMethod.PG_ON_SOLVER).build());
    solver.add(f.parse("~C => D"));
    solver.add(f.parse("C => D"));
    solver.add(f.parse("D => B | A"));
    solver.add(f.parse("B => X"));
    solver.add(f.parse("B => ~X"));
    solver.sat(f.literal("A", false));
    solver.add(f.parse("~A"));
    solver.sat();
    assertThat(solver.unsatCore()).isNotNull();
}
Also used : FormulaFactory(org.logicng.formulas.FormulaFactory) MiniSat(org.logicng.solvers.MiniSat) LogicNGTest(org.logicng.LogicNGTest) Test(org.junit.jupiter.api.Test)

Example 2 with MiniSat

use of org.logicng.solvers.MiniSat in project LogicNG by logic-ng.

the class DRUPTest method testCoreAndAssumptions3.

@Test
public void testCoreAndAssumptions3() throws ParserException {
    // Unit test for DRUP issue which led to java.lang.ArrayIndexOutOfBoundsException: -1
    final FormulaFactory f = new FormulaFactory();
    final MiniSat solver = MiniSat.miniSat(f, MiniSatConfig.builder().proofGeneration(true).cnfMethod(MiniSatConfig.CNFMethod.PG_ON_SOLVER).build());
    solver.add(f.parse("X => Y"));
    solver.add(f.parse("X => Z"));
    solver.add(f.parse("C => E"));
    solver.add(f.parse("D => ~F"));
    solver.add(f.parse("B => M"));
    solver.add(f.parse("D => N"));
    solver.add(f.parse("G => O"));
    solver.add(f.parse("A => B"));
    solver.add(f.parse("T1 <=> A & K & ~B & ~C"));
    solver.add(f.parse("T2 <=> A & B & C & K"));
    solver.add(f.parse("T1 + T2 = 1"));
    // required for DRUP issue
    solver.sat();
    solver.add(f.parse("Y => ~X & D"));
    solver.add(f.parse("X"));
    solver.sat();
    assertThat(solver.unsatCore()).isNotNull();
}
Also used : FormulaFactory(org.logicng.formulas.FormulaFactory) MiniSat(org.logicng.solvers.MiniSat) LogicNGTest(org.logicng.LogicNGTest) Test(org.junit.jupiter.api.Test)

Example 3 with MiniSat

use of org.logicng.solvers.MiniSat in project LogicNG by logic-ng.

the class DRUPTest method verifyCore.

/**
 * Checks that each formula of the core is part of the original problem and that the core is really unsat.
 * @param originalCore the original core
 * @param cnf          the original problem
 */
private void verifyCore(final UNSATCore<Proposition> originalCore, final List<Formula> cnf) {
    final List<Formula> core = new ArrayList<>(originalCore.propositions().size());
    for (final Proposition prop : originalCore.propositions()) {
        core.add(prop.formula());
    }
    final SoftAssertions softly = new SoftAssertions();
    softly.assertThat(cnf).as("Core contains only original clauses").containsAll(core);
    final MiniSat solver = MiniSat.glucose(this.f, MiniSatConfig.builder().proofGeneration(true).incremental(false).build(), GlucoseConfig.builder().build());
    solver.add(core);
    softly.assertThat(solver.sat()).as("Core is unsatisfiable").isEqualTo(Tristate.FALSE);
    softly.assertAll();
}
Also used : Formula(org.logicng.formulas.Formula) MiniSat(org.logicng.solvers.MiniSat) SoftAssertions(org.assertj.core.api.SoftAssertions) ArrayList(java.util.ArrayList) StandardProposition(org.logicng.propositions.StandardProposition) Proposition(org.logicng.propositions.Proposition) ExtendedProposition(org.logicng.propositions.ExtendedProposition)

Example 4 with MiniSat

use of org.logicng.solvers.MiniSat 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 5 with MiniSat

use of org.logicng.solvers.MiniSat in project LogicNG by logic-ng.

the class BackboneGenerationTest method testSmallFormulas.

@Test
public void testSmallFormulas() throws IOException, ParserException {
    final FormulaFactory f = new FormulaFactory();
    final Formula formula = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/small_formulas.txt", f);
    final MiniSat solver = MiniSat.miniSat(f);
    solver.add(formula);
    final Backbone backbone = solver.execute(BackboneFunction.builder().variables(formula.variables()).build());
    assertThat(verifyBackbone(backbone, formula, formula.variables())).isTrue();
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) MiniSat(org.logicng.solvers.MiniSat) Test(org.junit.jupiter.api.Test)

Aggregations

MiniSat (org.logicng.solvers.MiniSat)23 Test (org.junit.jupiter.api.Test)12 FormulaFactory (org.logicng.formulas.FormulaFactory)12 Formula (org.logicng.formulas.Formula)9 LogicNGTest (org.logicng.LogicNGTest)7 TreeSet (java.util.TreeSet)6 Literal (org.logicng.formulas.Literal)6 ArrayList (java.util.ArrayList)5 SolverState (org.logicng.solvers.SolverState)5 Variable (org.logicng.formulas.Variable)4 Proposition (org.logicng.propositions.Proposition)3 SATSolver (org.logicng.solvers.SATSolver)3 Assignment (org.logicng.datastructures.Assignment)2 UNSATCore (org.logicng.explanations.UNSATCore)2 StandardProposition (org.logicng.propositions.StandardProposition)2 LinkedHashSet (java.util.LinkedHashSet)1 SoftAssertions (org.assertj.core.api.SoftAssertions)1 PropositionalParser (org.logicng.io.parsers.PropositionalParser)1 PseudoBooleanParser (org.logicng.io.parsers.PseudoBooleanParser)1 ExtendedProposition (org.logicng.propositions.ExtendedProposition)1