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