Search in sources :

Example 1 with Operator

use of org.opt4j.satdecoding.Constraint.Operator 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)

Aggregations

BigInteger (java.math.BigInteger)1 Operator (org.opt4j.satdecoding.Constraint.Operator)1 ContradictionException (org.opt4j.satdecoding.ContradictionException)1 Vec (org.sat4j.core.Vec)1 VecInt (org.sat4j.core.VecInt)1 IVec (org.sat4j.specs.IVec)1