Search in sources :

Example 6 with VecInt

use of org.sat4j.core.VecInt 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 7 with VecInt

use of org.sat4j.core.VecInt 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 8 with VecInt

use of org.sat4j.core.VecInt 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)

Example 9 with VecInt

use of org.sat4j.core.VecInt in project opt4j by felixreimann.

the class SAT4JSolver method toVecInt.

protected VecInt toVecInt(Iterable<Literal> list) {
    VecInt vector = new VecInt();
    for (Literal literal : list) {
        Object var = literal.variable();
        if (!variables.containsKey(var)) {
            variables.put(var, nextVariable++);
            if (variables.size() > solver.nVars()) {
                setNVars(variables.size() * 2);
            }
        }
        boolean phase = literal.phase();
        vector.push(variables.get(var) * (phase ? 1 : -1));
    }
    return vector;
}
Also used : VecInt(org.sat4j.core.VecInt) Literal(org.opt4j.satdecoding.Literal)

Aggregations

VecInt (org.sat4j.core.VecInt)9 IVecInt (org.sat4j.specs.IVecInt)7 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Operator (org.opt4j.satdecoding.Constraint.Operator)1 ContradictionException (org.opt4j.satdecoding.ContradictionException)1 Literal (org.opt4j.satdecoding.Literal)1 Vec (org.sat4j.core.Vec)1 IVec (org.sat4j.specs.IVec)1 IteratorInt (org.sat4j.specs.IteratorInt)1