use of org.sat4j.specs.IVecInt 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.specs.IVecInt 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.specs.IVecInt 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.specs.IVecInt in project spoon by INRIA.
the class Solver method analyzeFinalConflictInTermsOfAssumptions.
/**
* Derive a subset of the assumptions causing the inconistency.
*
* @param confl
* the last conflict of the search, occuring at root level.
* @param assumps
* the set of assumption literals
* @param conflictingLiteral
* the literal detected conflicting while propagating
* assumptions.
* @return a subset of assumps causing the inconsistency.
* @since 2.2
*/
public IVecInt analyzeFinalConflictInTermsOfAssumptions(Constr confl, IVecInt assumps, int conflictingLiteral) {
if (assumps.size() == 0) {
return null;
}
while (!this.trailLim.isEmpty() && this.trailLim.last() == this.trail.size()) {
// conflict detected when assuming a value
this.trailLim.pop();
}
final boolean[] seen = this.mseen;
final IVecInt outLearnt = this.moutLearnt;
final IVecInt preason = this.mpreason;
outLearnt.clear();
if (this.trailLim.size() == 0) {
// conflict detected on unit clauses
return outLearnt;
}
assert outLearnt.size() == 0;
for (int i = 0; i < seen.length; i++) {
seen[i] = false;
}
if (confl == null) {
seen[conflictingLiteral >> 1] = true;
}
int p = ILits.UNDEFINED;
while (confl == null && this.trail.size() > 0 && this.trailLim.size() > 0) {
p = this.trail.last();
confl = this.voc.getReason(p);
undoOne();
if (confl == null && p == (conflictingLiteral ^ 1)) {
outLearnt.push(toDimacs(p));
}
if (this.trail.size() <= this.trailLim.last()) {
this.trailLim.pop();
}
}
if (confl == null) {
return outLearnt;
}
do {
preason.clear();
confl.calcReason(p, preason);
// Trace reason for p
for (int j = 0; j < preason.size(); j++) {
int q = preason.get(j);
if (!seen[q >> 1]) {
seen[q >> 1] = true;
if (this.voc.getReason(q) == null && this.voc.getLevel(q) > 0) {
assert assumps.contains(toDimacs(q));
outLearnt.push(toDimacs(q));
}
}
}
// select next reason to look at
do {
p = this.trail.last();
confl = this.voc.getReason(p);
undoOne();
if (decisionLevel() > 0 && this.trail.size() <= this.trailLim.last()) {
this.trailLim.pop();
}
} while (this.trail.size() > 0 && decisionLevel() > 0 && (!seen[p >> 1] || confl == null));
} while (decisionLevel() > 0);
return outLearnt;
}
use of org.sat4j.specs.IVecInt 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