Search in sources :

Example 1 with VecInt

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

the class SAT4JSolver method addConstraintToSolver.

protected void addConstraintToSolver(Constraint constraint) {
    VecInt lits = toVecInt(constraint.getLiterals());
    IVec<BigInteger> coeffs = new Vec<BigInteger>();
    for (Integer value : constraint.getCoefficients()) {
        coeffs.push(BigInteger.valueOf(value));
    }
    BigInteger d = BigInteger.valueOf(constraint.getRhs());
    Operator operator = constraint.getOperator();
    try {
        if (operator == LE || operator == EQ) {
            solver.addPseudoBoolean(lits, coeffs, false, d);
        }
        if (operator == GE || operator == EQ) {
            solver.addPseudoBoolean(lits, coeffs, true, d);
        }
    } catch (org.sat4j.specs.ContradictionException e) {
        solverValid = false;
        throw new ContradictionException(e);
    }
}
Also used : BigInteger(java.math.BigInteger) Operator(org.opt4j.satdecoding.Constraint.Operator) VecInt(org.sat4j.core.VecInt) Vec(org.sat4j.core.Vec) IVec(org.sat4j.specs.IVec) ContradictionException(org.opt4j.satdecoding.ContradictionException) BigInteger(java.math.BigInteger)

Example 2 with VecInt

use of org.sat4j.core.VecInt in project spoon by INRIA.

the class Solver method addAtMost.

public IConstr addAtMost(IVecInt literals, int degree) throws ContradictionException {
    int n = literals.size();
    IVecInt opliterals = new VecInt(n);
    for (IteratorInt iterator = literals.iterator(); iterator.hasNext(); ) {
        opliterals.push(-iterator.next());
    }
    return addAtLeast(opliterals, n - degree);
}
Also used : IVecInt(org.sat4j.specs.IVecInt) IteratorInt(org.sat4j.specs.IteratorInt) IVecInt(org.sat4j.specs.IVecInt) VecInt(org.sat4j.core.VecInt)

Example 3 with VecInt

use of org.sat4j.core.VecInt in project spoon by INRIA.

the class Solver method modelFound.

/**
 */
void modelFound() {
    IVecInt tempmodel = new VecInt(nVars());
    this.userbooleanmodel = new boolean[realNumberOfVariables()];
    this.fullmodel = null;
    for (int i = 1; i <= nVars(); i++) {
        if (this.voc.belongsToPool(i)) {
            int p = this.voc.getFromPool(i);
            if (!this.voc.isUnassigned(p)) {
                tempmodel.push(this.voc.isSatisfied(p) ? i : -i);
                this.userbooleanmodel[i - 1] = this.voc.isSatisfied(p);
                if (this.voc.getReason(p) == null && voc.getLevel(p) > 0) {
                    this.decisions.push(tempmodel.last());
                } else {
                    this.implied.push(tempmodel.last());
                }
            }
        }
    }
    this.model = new int[tempmodel.size()];
    tempmodel.copyTo(this.model);
    if (realNumberOfVariables() > nVars()) {
        for (int i = nVars() + 1; i <= realNumberOfVariables(); i++) {
            if (this.voc.belongsToPool(i)) {
                int p = this.voc.getFromPool(i);
                if (!this.voc.isUnassigned(p)) {
                    tempmodel.push(this.voc.isSatisfied(p) ? i : -i);
                    this.userbooleanmodel[i - 1] = this.voc.isSatisfied(p);
                    if (this.voc.getReason(p) == null) {
                        this.decisions.push(tempmodel.last());
                    } else {
                        this.implied.push(tempmodel.last());
                    }
                }
            }
        }
        this.fullmodel = new int[tempmodel.size()];
        tempmodel.moveTo(this.fullmodel);
    } else {
        this.fullmodel = this.model;
    }
}
Also used : IVecInt(org.sat4j.specs.IVecInt) IVecInt(org.sat4j.specs.IVecInt) VecInt(org.sat4j.core.VecInt)

Example 4 with VecInt

use of org.sat4j.core.VecInt in project spoon by INRIA.

the class Solver method preventTheSameDecisionsToBeMade.

private Constr preventTheSameDecisionsToBeMade() {
    IVecInt clause = new VecInt(nVars());
    int p;
    for (int i = this.trail.size() - 1; i >= this.rootLevel; i--) {
        p = this.trail.get(i);
        if (this.voc.getReason(p) == null) {
            clause.push(p ^ 1);
        }
    }
    return this.dsfactory.createUnregisteredClause(clause);
}
Also used : IVecInt(org.sat4j.specs.IVecInt) IVecInt(org.sat4j.specs.IVecInt) VecInt(org.sat4j.core.VecInt)

Example 5 with VecInt

use of org.sat4j.core.VecInt in project spoon by INRIA.

the class Solver method backtrack.

/**
 * @since 2.3.2
 */
public void backtrack(int[] reason) {
    IVecInt clause = new VecInt(reason.length);
    for (int d : reason) {
        clause.push(LiteralsUtils.toInternal(d));
    }
    this.sharedConflict = this.dsfactory.createUnregisteredClause(clause);
    learn(this.sharedConflict);
}
Also used : IVecInt(org.sat4j.specs.IVecInt) IVecInt(org.sat4j.specs.IVecInt) VecInt(org.sat4j.core.VecInt)

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