Search in sources :

Example 1 with IConstr

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

the class Solver method primeImplicant.

public int[] primeImplicant() {
    assert this.qhead == this.trail.size() + this.learnedLiterals.size();
    if (this.learnedLiterals.size() > 0) {
        this.qhead = trail.size();
    }
    if (isVerbose()) {
        System.out.printf("%s implied: %d, decision: %d %n", getLogPrefix(), implied.size(), decisions.size());
    }
    this.prime = new int[realNumberOfVariables() + 1];
    int p, d;
    for (int i = 0; i < this.prime.length; i++) {
        this.prime[i] = 0;
    }
    boolean noproblem;
    for (IteratorInt it = this.implied.iterator(); it.hasNext(); ) {
        d = it.next();
        p = toInternal(d);
        this.prime[Math.abs(d)] = d;
        noproblem = setAndPropagate(p);
        assert noproblem;
    }
    boolean canBeRemoved;
    int rightlevel;
    int removed = 0;
    int propagated = 0;
    int tested = 0;
    int l2propagation = 0;
    for (int i = 0; i < this.decisions.size(); i++) {
        d = this.decisions.get(i);
        assert !this.voc.isFalsified(toInternal(d));
        if (this.voc.isSatisfied(toInternal(d))) {
            // d has been propagated
            this.prime[Math.abs(d)] = d;
            propagated++;
        } else if (setAndPropagate(toInternal(-d))) {
            canBeRemoved = true;
            tested++;
            rightlevel = currentDecisionLevel();
            for (int j = i + 1; j < this.decisions.size(); j++) {
                l2propagation++;
                if (!setAndPropagate(toInternal(this.decisions.get(j)))) {
                    canBeRemoved = false;
                    break;
                }
            }
            cancelUntil(rightlevel);
            if (canBeRemoved) {
                // it is not a necessary literal
                forget(Math.abs(d));
                IConstr confl = propagate();
                assert confl == null;
                removed++;
            } else {
                this.prime[Math.abs(d)] = d;
                cancel();
                assert voc.isUnassigned(toInternal(d));
                noproblem = setAndPropagate(toInternal(d));
                assert noproblem;
            }
        } else {
            // conflict, literal is necessary
            this.prime[Math.abs(d)] = d;
            cancel();
            noproblem = setAndPropagate(toInternal(d));
            assert noproblem;
        }
    }
    cancelUntil(0);
    int[] implicant = new int[this.prime.length - removed - 1];
    int index = 0;
    for (int i : this.prime) {
        if (i != 0) {
            implicant[index++] = i;
        }
    }
    if (isVerbose()) {
        System.out.printf("%s prime implicant computation statistics%n", getLogPrefix());
        System.out.printf("%s implied: %d, decision: %d (removed %d, tested %d, propagated %d), l2 propagation:%d%n", getLogPrefix(), implied.size(), decisions.size(), removed, tested, propagated, l2propagation);
    }
    return implicant;
}
Also used : IteratorInt(org.sat4j.specs.IteratorInt) IConstr(org.sat4j.specs.IConstr)

Example 2 with IConstr

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

the class Solver method simpleSimplification.

// MiniSat -- Copyright (c) 2003-2005, Niklas Een, Niklas Sorensson
// 
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Taken from MiniSAT 1.14: Simplify conflict clause (a little):
private void simpleSimplification(IVecInt conflictToReduce) {
    int i, j, p;
    final boolean[] seen = this.mseen;
    IConstr r;
    for (i = j = 1; i < conflictToReduce.size(); i++) {
        r = this.voc.getReason(conflictToReduce.get(i));
        if (r == null || r.canBePropagatedMultipleTimes()) {
            conflictToReduce.moveTo(j++, i);
        } else {
            for (int k = 0; k < r.size(); k++) {
                p = r.get(k);
                if (!seen[p >> 1] && this.voc.isFalsified(p) && this.voc.getLevel(p) != 0) {
                    conflictToReduce.moveTo(j++, i);
                    break;
                }
            }
        }
    }
    conflictToReduce.shrink(i - j);
    this.stats.reducedliterals += i - j;
}
Also used : IConstr(org.sat4j.specs.IConstr)

Example 3 with IConstr

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

the class Solver method removeSubsumedConstr.

/**
 * @since 2.1
 */
public boolean removeSubsumedConstr(IConstr co) {
    if (co == null) {
        throw new IllegalArgumentException(// $NON-NLS-1$
        "Reference to the constraint to remove needed!");
    }
    if (this.constrs.last() != co) {
        throw new IllegalArgumentException(// $NON-NLS-1$
        "Can only remove latest added constraint!!!");
    }
    Constr c = (Constr) co;
    c.remove(this);
    this.constrs.pop();
    String type = c.getClass().getName();
    this.constrTypes.get(type).dec();
    return true;
}
Also used : IConstr(org.sat4j.specs.IConstr)

Example 4 with IConstr

use of org.sat4j.specs.IConstr 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 5 with IConstr

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

the class Solver method removeConstr.

public boolean removeConstr(IConstr co) {
    if (co == null) {
        throw new IllegalArgumentException(// $NON-NLS-1$
        "Reference to the constraint to remove needed!");
    }
    Constr c = (Constr) co;
    c.remove(this);
    this.constrs.remove(c);
    clearLearntClauses();
    String type = c.getClass().getName();
    this.constrTypes.get(type).dec();
    return true;
}
Also used : IConstr(org.sat4j.specs.IConstr)

Aggregations

IConstr (org.sat4j.specs.IConstr)5 IVecInt (org.sat4j.specs.IVecInt)1 IteratorInt (org.sat4j.specs.IteratorInt)1