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);
}
}
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);
}
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;
}
}
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);
}
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);
}
Aggregations