Search in sources :

Example 6 with IVecInt

use of org.sat4j.specs.IVecInt in project spoon by INRIA.

the class Solver method analyze.

/**
 * @throws TimeoutException
 *             if the timeout is reached during conflict analysis.
 */
public void analyze(Constr confl, Pair results) throws TimeoutException {
    assert confl != null;
    final boolean[] seen = this.mseen;
    final IVecInt outLearnt = this.moutLearnt;
    final IVecInt preason = this.mpreason;
    outLearnt.clear();
    assert outLearnt.size() == 0;
    for (int i = 0; i < seen.length; i++) {
        seen[i] = false;
    }
    int counter = 0;
    int p = ILits.UNDEFINED;
    outLearnt.push(ILits.UNDEFINED);
    // reserve de la place pour le litteral falsifie
    int outBtlevel = 0;
    IConstr prevConfl = null;
    do {
        preason.clear();
        assert confl != null;
        if (prevConfl != confl) {
            confl.calcReason(p, preason);
            this.learnedConstraintsDeletionStrategy.onConflictAnalysis(confl);
            // Trace reason for p
            for (int j = 0; j < preason.size(); j++) {
                int q = preason.get(j);
                this.order.updateVar(q);
                if (!seen[q >> 1]) {
                    seen[q >> 1] = true;
                    if (this.voc.getLevel(q) == decisionLevel()) {
                        counter++;
                        this.order.updateVarAtDecisionLevel(q);
                    } else if (this.voc.getLevel(q) > 0) {
                        // only literals assigned after decision level 0
                        // part of
                        // the explanation
                        outLearnt.push(q ^ 1);
                        outBtlevel = Math.max(outBtlevel, this.voc.getLevel(q));
                    }
                }
            }
        }
        prevConfl = confl;
        // select next reason to look at
        do {
            p = this.trail.last();
            confl = this.voc.getReason(p);
            undoOne();
        } while (!seen[p >> 1]);
    // seen[p.var] indique que p se trouve dans outLearnt ou dans
    // le dernier niveau de d?cision
    } while (--counter > 0);
    outLearnt.set(0, p ^ 1);
    this.simplifier.simplify(outLearnt);
    Constr c = this.dsfactory.createUnregisteredClause(outLearnt);
    // slistener.learn(c);
    this.learnedConstraintsDeletionStrategy.onClauseLearning(c);
    results.reason = c;
    assert outBtlevel > -1;
    results.backtrackLevel = outBtlevel;
}
Also used : IVecInt(org.sat4j.specs.IVecInt) IConstr(org.sat4j.specs.IConstr) IConstr(org.sat4j.specs.IConstr)

Example 7 with IVecInt

use of org.sat4j.specs.IVecInt in project spoon by INRIA.

the class Solver method unsatExplanation.

/**
 * @since 2.2
 */
public IVecInt unsatExplanation() {
    IVecInt copy = new VecInt(this.unsatExplanationInTermsOfAssumptions.size());
    this.unsatExplanationInTermsOfAssumptions.copyTo(copy);
    return copy;
}
Also used : IVecInt(org.sat4j.specs.IVecInt) IVecInt(org.sat4j.specs.IVecInt) VecInt(org.sat4j.core.VecInt)

Example 8 with IVecInt

use of org.sat4j.specs.IVecInt in project spoon by INRIA.

the class Solver method addAtMostOnTheFly.

/**
 * @param literals
 */
public IConstr addAtMostOnTheFly(int[] literals, int degree) {
    IVecInt clause = new VecInt(literals.length);
    for (int d : literals) {
        clause.push(LiteralsUtils.toInternal(-d));
    }
    IVecInt copy = new VecInt(clause.size());
    clause.copyTo(copy);
    this.sharedConflict = this.dsfactory.createUnregisteredCardinalityConstraint(copy, literals.length - degree);
    this.sharedConflict.register();
    addConstr(this.sharedConflict);
    // backtrack to the first decision level with a reason
    // for falsifying that constraint
    IVecInt reason = new VecInt();
    this.sharedConflict.calcReasonOnTheFly(ILits.UNDEFINED, trail, reason);
    Set<Integer> subset = fromLastDecisionLevel(reason);
    while (!trail.isEmpty() && !subset.contains(trail.last())) {
        undoOne();
        if (!trailLim.isEmpty() && trailLim.last() == trail.size()) {
            trailLim.pop();
        }
    }
    return this.sharedConflict;
}
Also used : IVecInt(org.sat4j.specs.IVecInt) IVecInt(org.sat4j.specs.IVecInt) VecInt(org.sat4j.core.VecInt)

Example 9 with IVecInt

use of org.sat4j.specs.IVecInt in project spoon by INRIA.

the class Solver method analyzeRemovable.

// Check if 'p' can be removed.' min_level' is used to abort early if
// visiting literals at a level that cannot be removed.
// 
private boolean analyzeRemovable(int p) {
    assert this.voc.getReason(p) != null;
    ILits lvoc = this.voc;
    IVecInt lanalyzestack = this.analyzestack;
    IVecInt lanalyzetoclear = this.analyzetoclear;
    lanalyzestack.clear();
    lanalyzestack.push(p);
    final boolean[] seen = this.mseen;
    int top = lanalyzetoclear.size();
    while (lanalyzestack.size() > 0) {
        int q = lanalyzestack.last();
        assert lvoc.getReason(q) != null;
        Constr c = lvoc.getReason(q);
        lanalyzestack.pop();
        if (c.canBePropagatedMultipleTimes()) {
            for (int j = top; j < lanalyzetoclear.size(); j++) {
                seen[lanalyzetoclear.get(j) >> 1] = false;
            }
            lanalyzetoclear.shrink(lanalyzetoclear.size() - top);
            return false;
        }
        for (int i = 0; i < c.size(); i++) {
            int l = c.get(i);
            if (!seen[var(l)] && lvoc.isFalsified(l) && lvoc.getLevel(l) != 0) {
                if (lvoc.getReason(l) == null) {
                    for (int j = top; j < lanalyzetoclear.size(); j++) {
                        seen[lanalyzetoclear.get(j) >> 1] = false;
                    }
                    lanalyzetoclear.shrink(lanalyzetoclear.size() - top);
                    return false;
                }
                seen[l >> 1] = true;
                lanalyzestack.push(l);
                lanalyzetoclear.push(l);
            }
        }
    }
    return true;
}
Also used : IVecInt(org.sat4j.specs.IVecInt) IConstr(org.sat4j.specs.IConstr)

Example 10 with IVecInt

use of org.sat4j.specs.IVecInt in project spoon by INRIA.

the class Solver method addClauseOnTheFly.

public IConstr addClauseOnTheFly(int[] literals) {
    List<Integer> lliterals = new ArrayList<Integer>();
    for (Integer d : literals) {
        lliterals.add(d);
    }
    Collections.sort(lliterals, dimacsLevel);
    IVecInt clause = new VecInt(literals.length);
    for (int d : lliterals) {
        clause.push(LiteralsUtils.toInternal(d));
    }
    this.sharedConflict = this.dsfactory.createUnregisteredClause(clause);
    this.sharedConflict.register();
    addConstr(this.sharedConflict);
    IVecInt reason = new VecInt();
    this.sharedConflict.calcReasonOnTheFly(ILits.UNDEFINED, trail, reason);
    Set<Integer> subset = fromLastDecisionLevel(reason);
    while (!trail.isEmpty() && !subset.contains(trail.last())) {
        undoOne();
        if (!trailLim.isEmpty() && trailLim.last() == trail.size()) {
            trailLim.pop();
        }
    }
    return this.sharedConflict;
}
Also used : IVecInt(org.sat4j.specs.IVecInt) IVecInt(org.sat4j.specs.IVecInt) VecInt(org.sat4j.core.VecInt) ArrayList(java.util.ArrayList)

Aggregations

IVecInt (org.sat4j.specs.IVecInt)11 VecInt (org.sat4j.core.VecInt)7 IConstr (org.sat4j.specs.IConstr)3 ArrayList (java.util.ArrayList)1 IteratorInt (org.sat4j.specs.IteratorInt)1 SearchListener (org.sat4j.specs.SearchListener)1