Search in sources :

Example 1 with MSVariable

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

the class GlucoseSyrup method solve.

@Override
public Tristate solve(final SATHandler handler) {
    if (this.config.incremental && this.config.proofGeneration) {
        throw new IllegalStateException("Cannot use incremental and proof generation at the same time");
    }
    this.handler = handler;
    start(handler);
    this.model.clear();
    this.conflict.clear();
    if (!this.ok) {
        return Tristate.FALSE;
    }
    for (int i = 0; i < this.assumptions.size(); i++) {
        this.assump.set(var(this.assumptions.get(i)), !sign(this.assumptions.get(i)));
    }
    Tristate status = Tristate.UNDEF;
    while (status == Tristate.UNDEF && !this.canceledByHandler) {
        status = search();
    }
    if (this.config.proofGeneration && this.assumptions.empty()) {
        if (status == Tristate.FALSE) {
            this.pgProof.push(new LNGIntVector(1, 0));
        }
    }
    if (status == Tristate.TRUE) {
        this.model = new LNGBooleanVector(this.vars.size());
        for (final MSVariable v : this.vars) {
            this.model.push(v.assignment() == Tristate.TRUE);
        }
    } else if (status == Tristate.FALSE && this.conflict.size() == 0) {
        this.ok = false;
    }
    finishSolving(handler);
    cancelUntil(0);
    this.handler = null;
    this.canceledByHandler = false;
    for (int i = 0; i < this.assumptions.size(); i++) {
        this.assump.set(var(this.assumptions.get(i)), false);
    }
    return status;
}
Also used : MSVariable(org.logicng.solvers.datastructures.MSVariable) Tristate(org.logicng.datastructures.Tristate) LNGBooleanVector(org.logicng.collections.LNGBooleanVector) LNGIntVector(org.logicng.collections.LNGIntVector)

Example 2 with MSVariable

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

the class MiniCard method analyzeFinal.

@Override
protected void analyzeFinal(final int p, final LNGIntVector outConflict) {
    outConflict.clear();
    outConflict.push(p);
    if (decisionLevel() == 0) {
        return;
    }
    this.seen.set(var(p), true);
    int x;
    MSVariable v;
    for (int i = this.trail.size() - 1; i >= this.trailLim.get(0); i--) {
        x = var(this.trail.get(i));
        if (this.seen.get(x)) {
            v = this.vars.get(x);
            if (v.reason() == null) {
                assert v.level() > 0;
                outConflict.push(not(this.trail.get(i)));
            } else {
                final MSClause c = v.reason();
                if (!c.isAtMost()) {
                    for (int j = 1; j < c.size(); j++) {
                        if (v(c.get(j)).level() > 0) {
                            this.seen.set(var(c.get(j)), true);
                        }
                    }
                } else {
                    for (int j = 0; j < c.size(); j++) {
                        if (value(c.get(j)) == Tristate.TRUE && v(c.get(j)).level() > 0) {
                            this.seen.set(var(c.get(j)), true);
                        }
                    }
                }
            }
            this.seen.set(x, false);
        }
    }
    this.seen.set(var(p), false);
}
Also used : MSClause(org.logicng.solvers.datastructures.MSClause) MSVariable(org.logicng.solvers.datastructures.MSVariable)

Example 3 with MSVariable

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

the class MiniCard method completeBacktrack.

/**
 * Performs an unconditional backtrack to level zero.
 */
protected void completeBacktrack() {
    for (int v = 0; v < this.vars.size(); v++) {
        final MSVariable var = this.vars.get(v);
        var.assign(Tristate.UNDEF);
        var.setReason(null);
        if (!this.orderHeap.inHeap(v) && var.decision()) {
            this.orderHeap.insert(v);
        }
    }
    this.trail.clear();
    this.trailLim.clear();
    this.qhead = 0;
}
Also used : MSVariable(org.logicng.solvers.datastructures.MSVariable)

Example 4 with MSVariable

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

the class MiniCard method solve.

@Override
public Tristate solve(final SATHandler handler) {
    this.handler = handler;
    start(handler);
    this.model.clear();
    this.conflict.clear();
    if (!this.ok) {
        return Tristate.FALSE;
    }
    this.learntsizeAdjustConfl = this.learntsizeAdjustStartConfl;
    this.learntsizeAdjustCnt = (int) this.learntsizeAdjustConfl;
    this.maxLearnts = this.clauses.size() * this.learntsizeFactor;
    Tristate status = Tristate.UNDEF;
    int currRestarts = 0;
    while (status == Tristate.UNDEF && !this.canceledByHandler) {
        final double restBase = luby(this.restartInc, currRestarts);
        status = search((int) (restBase * this.restartFirst));
        currRestarts++;
    }
    if (status == Tristate.TRUE) {
        this.model = new LNGBooleanVector(this.vars.size());
        for (final MSVariable v : this.vars) {
            this.model.push(v.assignment() == Tristate.TRUE);
        }
    } else if (status == Tristate.FALSE && this.conflict.empty()) {
        this.ok = false;
    }
    finishSolving(handler);
    cancelUntil(0);
    this.handler = null;
    this.canceledByHandler = false;
    return status;
}
Also used : MSVariable(org.logicng.solvers.datastructures.MSVariable) Tristate(org.logicng.datastructures.Tristate) LNGBooleanVector(org.logicng.collections.LNGBooleanVector)

Example 5 with MSVariable

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

the class MiniCard method newVar.

@Override
public int newVar(final boolean sign, final boolean dvar) {
    final int v = this.vars.size();
    final MSVariable newVar = new MSVariable(sign);
    this.vars.push(newVar);
    this.watches.push(new LNGVector<>());
    this.watches.push(new LNGVector<>());
    this.seen.push(false);
    newVar.setDecision(dvar);
    insertVarOrder(v);
    return v;
}
Also used : MSVariable(org.logicng.solvers.datastructures.MSVariable)

Aggregations

MSVariable (org.logicng.solvers.datastructures.MSVariable)20 MSClause (org.logicng.solvers.datastructures.MSClause)5 LNGBooleanVector (org.logicng.collections.LNGBooleanVector)3 LNGIntVector (org.logicng.collections.LNGIntVector)3 Tristate (org.logicng.datastructures.Tristate)3 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Formula (org.logicng.formulas.Formula)1 FormulaFactory (org.logicng.formulas.FormulaFactory)1 Literal (org.logicng.formulas.Literal)1 Variable (org.logicng.formulas.Variable)1