org.sat4j.tools
Class SingleSolutionDetector
java.lang.Object
org.sat4j.tools.SolverDecorator
org.sat4j.tools.SingleSolutionDetector
- All Implemented Interfaces:
- java.io.Serializable, IProblem, ISolver
public class SingleSolutionDetector
- extends SolverDecorator
This solver decorator allows to detect whether or not the set of constraints
available in the solver has only one solution or not.
NOTE THAT THIS DECORATOR CANNOT BE USED WITH SOLVERS USING SPECIFIC DATA
STRUCTURES FOR BINARY OR TERNARY CLAUSES!
SingleSolutionDetector problem =
new SingleSolutionDetector(SolverFactory.newMiniSAT());
// feed problem/solver as usual
if (problem.isSatisfiable()) {
if (problem.hasASingleSolution()) {
// great, the instance has a unique solution
int [] uniquesolution = problem.getModel();
} else {
// too bad, got more than one
}
}
- Author:
- leberre
- See Also:
- Serialized Form
Method Summary |
boolean |
hasASingleSolution()
Please use that method only after a positive answer from isSatisfiable()
(else a runtime exception will be launched). |
boolean |
hasASingleSolution(IVecInt assumptions)
Please use that method only after a positive answer from
isSatisfiable(assumptions) (else a runtime exception will be launched). |
Methods inherited from class org.sat4j.tools.SolverDecorator |
addAllClauses, addAtLeast, addAtMost, addClause, addPseudoBoolean, clearLearntClauses, decorated, findModel, findModel, getStat, getTimeout, isSatisfiable, isSatisfiable, model, model, nConstraints, newVar, newVar, nVars, printStat, printStat, removeConstr, reset, setExpectedNumberOfClauses, setTimeout, setTimeoutMs, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SingleSolutionDetector
public SingleSolutionDetector(ISolver solver)
hasASingleSolution
public boolean hasASingleSolution()
throws TimeoutException
- Please use that method only after a positive answer from isSatisfiable()
(else a runtime exception will be launched).
- Returns:
- true iff there is only one way to satisfy all the constraints in
the solver.
- Throws:
TimeoutException
hasASingleSolution
public boolean hasASingleSolution(IVecInt assumptions)
throws TimeoutException
- Please use that method only after a positive answer from
isSatisfiable(assumptions) (else a runtime exception will be launched).
- Parameters:
assumptions
- a set of literals (dimacs numbering) that must be satisfied.
- Returns:
- true iff there is only one way to satisfy all the constraints in
the solver using the provided set of assumptions.
- Throws:
TimeoutException
Copyright © 2007 Centre de Recherche en Informatique de Lens (CRIL). All Rights Reserved.