org.sat4j.tools
Class ModelIterator

java.lang.Object
  extended by org.sat4j.tools.SolverDecorator<ISolver>
      extended by org.sat4j.tools.ModelIterator
All Implemented Interfaces:
Serializable, IProblem, ISolver

public class ModelIterator
extends SolverDecorator<ISolver>

That class allows to iterate through all the models (implicants) of a formula.

 ISolver solver = new ModelIterator(SolverFactory.OneSolver());
 boolean unsat = true;
 while (solver.isSatisfiable()) {
        unsat = false;
        int[] model = solver.model();
        // do something with model
 }
 if (unsat) {
        // UNSAT case
 }
 
It is also possible to limit the number of models returned:
 ISolver solver = new ModelIterator(SolverFactory.OneSolver(), 10);
 
will return at most 10 models.

Author:
leberre
See Also:
Serialized Form

Constructor Summary
ModelIterator(ISolver solver)
           
ModelIterator(ISolver solver, long bound)
           
 
Method Summary
 boolean isSatisfiable()
          Check the satisfiability of the set of constraints contained inside the solver.
 boolean isSatisfiable(IVecInt assumps)
          Check the satisfiability of the set of constraints contained inside the solver.
 int[] model()
          Provide a model (if any) for a satisfiable formula.
 long numberOfModelsFoundSoFar()
          To know the number of models already found.
 int[] primeImplicant()
          Provide a prime implicant, i.e. a set of literal that is sufficient to satisfy all constraints of the problem.
 void reset()
          Clean up the internal state of the solver.
 
Methods inherited from class org.sat4j.tools.SolverDecorator
addAllClauses, addAtLeast, addAtMost, addBlockingClause, addClause, addExactly, clearDecorated, clearLearntClauses, decorated, expireTimeout, findModel, findModel, getLogPrefix, getSearchListener, getStat, getTimeout, getTimeoutMs, isDBSimplificationAllowed, isSatisfiable, isSatisfiable, isVerbose, model, modelWithInternalVariables, nConstraints, newVar, newVar, nextFreeVarId, nVars, printInfos, printStat, printStat, realNumberOfVariables, registerLiteral, removeConstr, removeSubsumedConstr, setDBSimplificationAllowed, setExpectedNumberOfClauses, setLogPrefix, setSearchListener, setTimeout, setTimeoutMs, setTimeoutOnConflicts, setVerbose, toString, toString, unsatExplanation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ModelIterator

public ModelIterator(ISolver solver)
Parameters:
solver -

ModelIterator

public ModelIterator(ISolver solver,
                     long bound)
Parameters:
solver -
bound -
Since:
2.1
Method Detail

model

public int[] model()
Description copied from interface: IProblem
Provide a model (if any) for a satisfiable formula. That method should be called AFTER isSatisfiable() or isSatisfiable(IVecInt) if the formula is satisfiable. Else an exception UnsupportedOperationException is launched.

Specified by:
model in interface IProblem
Overrides:
model in class SolverDecorator<ISolver>
Returns:
a model of the formula as an array of literals to satisfy.
See Also:
IProblem.isSatisfiable(), IProblem.isSatisfiable(IVecInt)

isSatisfiable

public boolean isSatisfiable()
                      throws TimeoutException
Description copied from interface: IProblem
Check the satisfiability of the set of constraints contained inside the solver.

Specified by:
isSatisfiable in interface IProblem
Overrides:
isSatisfiable in class SolverDecorator<ISolver>
Returns:
true if the set of constraints is satisfiable, else false.
Throws:
TimeoutException

isSatisfiable

public boolean isSatisfiable(IVecInt assumps)
                      throws TimeoutException
Description copied from interface: IProblem
Check the satisfiability of the set of constraints contained inside the solver.

Specified by:
isSatisfiable in interface IProblem
Overrides:
isSatisfiable in class SolverDecorator<ISolver>
Parameters:
assumps - a set of literals (represented by usual non null integers in Dimacs format).
Returns:
true if the set of constraints is satisfiable when literals are satisfied, else false.
Throws:
TimeoutException

reset

public void reset()
Description copied from interface: ISolver
Clean up the internal state of the solver.

Specified by:
reset in interface ISolver
Overrides:
reset in class SolverDecorator<ISolver>

primeImplicant

public int[] primeImplicant()
Description copied from interface: IProblem
Provide a prime implicant, i.e. a set of literal that is sufficient to satisfy all constraints of the problem. NOTE THAT THIS FEATURE IS HIGHLY EXPERIMENTAL FOR NOW.

Specified by:
primeImplicant in interface IProblem
Overrides:
primeImplicant in class SolverDecorator<ISolver>
Returns:
a prime implicant of the formula as an array of literal, Dimacs format.

numberOfModelsFoundSoFar

public long numberOfModelsFoundSoFar()
To know the number of models already found.

Returns:
the number of models found so far.
Since:
2.3


Copyright © 2011 Centre de Recherche en Informatique de Lens (CRIL). All Rights Reserved.