Search in sources :

Example 1 with GlucoseSyrup

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

the class UnsatCoreFunction method apply.

@Override
public UNSATCore<Proposition> apply(final MiniSat solver, final Consumer<Tristate> resultSetter) {
    if (!solver.getConfig().proofGeneration()) {
        throw new IllegalStateException("Cannot generate an unsat core if proof generation is not turned on");
    }
    if (solver.getResult() == TRUE) {
        throw new IllegalStateException("An unsat core can only be generated if the formula is solved and is UNSAT");
    }
    if (solver.getResult() == Tristate.UNDEF) {
        throw new IllegalStateException("Cannot generate an unsat core before the formula was solved.");
    }
    if (solver.underlyingSolver() instanceof MiniCard) {
        throw new IllegalStateException("Cannot compute an unsat core with MiniCard.");
    }
    if (solver.underlyingSolver() instanceof GlucoseSyrup && solver.getConfig().incremental()) {
        throw new IllegalStateException("Cannot compute an unsat core with Glucose in incremental mode.");
    }
    if (solver.isLastComputationWithAssumptions()) {
        throw new IllegalStateException("Cannot compute an unsat core for a computation with assumptions.");
    }
    final DRUPTrim trimmer = new DRUPTrim();
    final Map<Formula, Proposition> clause2proposition = new HashMap<>();
    final LNGVector<LNGIntVector> clauses = new LNGVector<>(solver.underlyingSolver().pgOriginalClauses().size());
    for (final MiniSatStyleSolver.ProofInformation pi : solver.underlyingSolver().pgOriginalClauses()) {
        clauses.push(pi.clause());
        final Formula clause = getFormulaForVector(solver, pi.clause());
        Proposition proposition = pi.proposition();
        if (proposition == null) {
            proposition = new StandardProposition(clause);
        }
        clause2proposition.put(clause, proposition);
    }
    if (containsEmptyClause(clauses)) {
        final Proposition emptyClause = clause2proposition.get(solver.factory().falsum());
        return new UNSATCore<>(Collections.singletonList(emptyClause), true);
    }
    final DRUPTrim.DRUPResult result = trimmer.compute(clauses, solver.underlyingSolver().pgProof());
    if (result.trivialUnsat()) {
        return handleTrivialCase(solver);
    }
    final LinkedHashSet<Proposition> propositions = new LinkedHashSet<>();
    for (final LNGIntVector vector : result.unsatCore()) {
        propositions.add(clause2proposition.get(getFormulaForVector(solver, vector)));
    }
    return new UNSATCore<>(new ArrayList<>(propositions), false);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DRUPTrim(org.logicng.explanations.drup.DRUPTrim) MiniCard(org.logicng.solvers.sat.MiniCard) GlucoseSyrup(org.logicng.solvers.sat.GlucoseSyrup) MiniSatStyleSolver(org.logicng.solvers.sat.MiniSatStyleSolver) HashMap(java.util.HashMap) UNSATCore(org.logicng.explanations.UNSATCore) LNGIntVector(org.logicng.collections.LNGIntVector) LNGVector(org.logicng.collections.LNGVector) StandardProposition(org.logicng.propositions.StandardProposition) Formula(org.logicng.formulas.Formula) StandardProposition(org.logicng.propositions.StandardProposition) Proposition(org.logicng.propositions.Proposition)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 LNGIntVector (org.logicng.collections.LNGIntVector)1 LNGVector (org.logicng.collections.LNGVector)1 UNSATCore (org.logicng.explanations.UNSATCore)1 DRUPTrim (org.logicng.explanations.drup.DRUPTrim)1 Formula (org.logicng.formulas.Formula)1 Proposition (org.logicng.propositions.Proposition)1 StandardProposition (org.logicng.propositions.StandardProposition)1 GlucoseSyrup (org.logicng.solvers.sat.GlucoseSyrup)1 MiniCard (org.logicng.solvers.sat.MiniCard)1 MiniSatStyleSolver (org.logicng.solvers.sat.MiniSatStyleSolver)1