org.sat4j.tools
Class SingleSolutionDetector

java.lang.Object
  extended by org.sat4j.tools.SolverDecorator
      extended by 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

Constructor Summary
SingleSolutionDetector(ISolver solver)
           
 
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, decorated, getStat, getTimeout, isSatisfiable, isSatisfiable, model, model, nConstraints, newVar, newVar, nVars, printStat, printStat, removeConstr, reset, setExpectedNumberOfClauses, setTimeout, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleSolutionDetector

public SingleSolutionDetector(ISolver solver)
Method Detail

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