use of kodkod.engine.satlab.SATSolver in project org.alloytools.alloy by AlloyTools.
the class Translator method toCNF.
/**
* Translates the given circuit to CNF, adds the clauses to a SATSolver returned
* by options.solver(), and returns a Translation object constructed from the
* solver and the provided arguments.
*
* @requires SAT(circuit) iff SAT(this.originalFormula, this.originalBounds,
* this.options)
* @requires circuit.factory = interpreter.factory
* @requires interpreter.universe = this.bounds.universe &&
* interpreter.relations = this.bounds.relations() && interpreter.ints
* = this.bounds.ints() && interpreter.lbounds =
* this.bounds.lowerBound && this.interpreter.ubounds =
* bounds.upperBound && interpreter.ibounds = bounds.intBound
* @requires log.originalFormula = this.originalFormula && log.bounds =
* this.bounds
* @ensures {@link #completeBounds()}
* @ensures this.options.reporter.translatingToCNF(circuit)
* @return some t: Translation | t.bounds = completeBounds() && t.originalBounds
* = this.originalBounds && t.vars = interpreter.vars &&
* t.vars[Relation].int in t.solver.variables && t.solver.solve() iff
* SAT(this.formula, this.bounds, this.options)
*/
private Translation toCNF(BooleanFormula circuit, LeafInterpreter interpreter, TranslationLog log) {
options.reporter().translatingToCNF(circuit);
final int maxPrimaryVar = interpreter.factory().maxVariable();
if (incremental) {
final Bool2CNFTranslator incrementer = Bool2CNFTranslator.translateIncremental(circuit, maxPrimaryVar, options.solver());
return new Translation.Incremental(completeBounds(), options, SymmetryDetector.partition(originalBounds), interpreter, incrementer);
} else {
final Map<Relation, IntSet> varUsage = interpreter.vars();
// enable gc
interpreter = null;
final SATSolver cnf = Bool2CNFTranslator.translate(circuit, maxPrimaryVar, options.solver());
return new Translation.Whole(completeBounds(), options, cnf, varUsage, maxPrimaryVar, log);
}
}
use of kodkod.engine.satlab.SATSolver in project org.alloytools.alloy by AlloyTools.
the class Translator method translateNext.
public static <T extends Translation> T translateNext(T transl) {
int primaryVars = transl.numPrimaryVariables();
SATSolver cnf = transl.cnf();
final int[] notModel = new int[primaryVars];
for (int i = 1; i <= primaryVars; i++) {
notModel[i - 1] = cnf.valueOf(i) ? -i : i;
}
cnf.addClause(notModel);
return transl;
}
use of kodkod.engine.satlab.SATSolver in project org.alloytools.alloy by AlloyTools.
the class SolutionIterator method nextNonTrivialSolution.
/**
* Solves {@code translation.cnf} and adds the negation of the found model to
* the set of clauses. The latter has the effect of forcing the solver to come
* up with the next solution or return UNSAT. If
* {@code this.translation.cnf.solve()} is false, sets {@code this.translation}
* to null.
*
* @requires this.translation != null
* @ensures this.translation.cnf is modified to eliminate the current solution
* from the set of possible solutions
* @return current solution
*/
private Solution nextNonTrivialSolution() {
final Translation.Whole transl = translation;
final SATSolver cnf = transl.cnf();
final int primaryVars = transl.numPrimaryVariables();
transl.options().reporter().solvingCNF(primaryVars, cnf.numberOfVariables(), cnf.numberOfClauses());
final long startSolve = System.currentTimeMillis();
final boolean isSat = cnf.solve();
final long endSolve = System.currentTimeMillis();
final Statistics stats = new Statistics(transl, translTime, endSolve - startSolve);
final Solution sol;
if (isSat) {
// extract the current solution; can't use the sat(..) method
// because it frees the sat solver
sol = Solution.satisfiable(stats, transl.interpret());
// add the negation of the current model to the solver
final int[] notModel = new int[primaryVars];
for (int i = 1; i <= primaryVars; i++) {
notModel[i - 1] = cnf.valueOf(i) ? -i : i;
}
cnf.addClause(notModel);
} else {
// this also frees up solver
sol = Solver.unsat(transl, stats);
// resources, if any
// unsat, no more solutions
translation = null;
}
return sol;
}
Aggregations