org.sat4j.pb
Class OPBStringSolver

java.lang.Object
  extended by org.sat4j.tools.AbstractOutputSolver
      extended by org.sat4j.tools.DimacsStringSolver
          extended by org.sat4j.pb.OPBStringSolver
All Implemented Interfaces:
Serializable, IPBSolver, IProblem, ISolver

public class OPBStringSolver
extends DimacsStringSolver
implements IPBSolver

Solver used to display in a string the pb-instance in OPB format. That solver is useful to produce OPB files to be used by third party solvers.

Author:
parrain
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.sat4j.tools.AbstractOutputSolver
firstConstr, fixedNbClauses, nbclauses, nbvars
 
Constructor Summary
OPBStringSolver()
           
OPBStringSolver(int initSize)
           
 
Method Summary
 IConstr addAtLeast(IVecInt literals, int degree)
           
 IConstr addAtLeast(IVecInt literals, IVec<BigInteger> coeffs, BigInteger degree)
          Create a pseudo-boolean constraint of the type "at least".
 IConstr addAtLeast(IVecInt literals, IVecInt coeffs, int degree)
          Create a pseudo-boolean constraint of the type "at least".
 IConstr addAtMost(IVecInt literals, int degree)
           
 IConstr addAtMost(IVecInt literals, IVec<BigInteger> coeffs, BigInteger degree)
          Create a pseudo boolean constraint of the type "at most".
 IConstr addAtMost(IVecInt literals, IVecInt coeffs, int degree)
          Create a pseudo boolean constraint of the type "at most".
 IConstr addClause(IVecInt literals)
           
 IConstr addExactly(IVecInt literals, IVec<BigInteger> coeffs, BigInteger weight)
          Create a pseudo-boolean constraint of the type "subset sum".
 IConstr addExactly(IVecInt literals, IVecInt coeffs, int weight)
          Create a pseudo-boolean constraint of the type "subset sum".
 IConstr addPseudoBoolean(IVecInt lits, IVec<BigInteger> coeffs, boolean moreThan, BigInteger d)
          Create a Pseudo-Boolean constraint of the type "at least n or at most n of those literals must be satisfied"
 String getExplanation()
           
 ObjectiveFunction getObjectiveFunction()
          Retrieve the objective function from the solver.
 boolean isSatisfiable(IVecInt assumps)
           
 boolean isSatisfiable(IVecInt assumps, boolean global)
           
 int nConstraints()
           
 int newVar(int howmany)
           
 void setExpectedNumberOfClauses(int nb)
           
 void setListOfVariablesForExplanation(IVecInt listOfVariables)
           
 void setObjectiveFunction(ObjectiveFunction obj)
          Provide an objective function to the solver.
 String toString()
           
 String toString(String prefix)
           
 
Methods inherited from class org.sat4j.tools.DimacsStringSolver
addExactly, getOut, modelWithInternalVariables, newVar, nextFreeVarId, nVars, primeImplicant, realNumberOfVariables, registerLiteral, reset, setNbVars
 
Methods inherited from class org.sat4j.tools.AbstractOutputSolver
addAllClauses, addBlockingClause, clearLearntClauses, expireTimeout, findModel, findModel, getLogPrefix, getSearchListener, getStat, getTimeout, getTimeoutMs, isDBSimplificationAllowed, isSatisfiable, isSatisfiable, isSolverKeptHot, isVerbose, model, model, primeImplicant, printInfos, printStat, printStat, removeConstr, removeSubsumedConstr, setDBSimplificationAllowed, setKeepSolverHot, setLogPrefix, setSearchListener, setTimeout, setTimeoutMs, setTimeoutOnConflicts, setVerbose, unsatExplanation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.sat4j.specs.ISolver
addAllClauses, addBlockingClause, addExactly, clearLearntClauses, expireTimeout, getLogPrefix, getSearchListener, getStat, getTimeout, getTimeoutMs, isDBSimplificationAllowed, isSolverKeptHot, isVerbose, modelWithInternalVariables, newVar, nextFreeVarId, printStat, printStat, realNumberOfVariables, registerLiteral, removeConstr, removeSubsumedConstr, reset, setDBSimplificationAllowed, setKeepSolverHot, setLogPrefix, setSearchListener, setTimeout, setTimeoutMs, setTimeoutOnConflicts, setVerbose, unsatExplanation
 
Methods inherited from interface org.sat4j.specs.IProblem
findModel, findModel, isSatisfiable, isSatisfiable, model, model, nVars, primeImplicant, primeImplicant, printInfos
 

Constructor Detail

OPBStringSolver

public OPBStringSolver()

OPBStringSolver

public OPBStringSolver(int initSize)
Parameters:
initSize -
Method Detail

isSatisfiable

public boolean isSatisfiable(IVecInt assumps)
                      throws TimeoutException
Specified by:
isSatisfiable in interface IProblem
Overrides:
isSatisfiable in class AbstractOutputSolver
Throws:
TimeoutException

isSatisfiable

public boolean isSatisfiable(IVecInt assumps,
                             boolean global)
                      throws TimeoutException
Specified by:
isSatisfiable in interface IProblem
Overrides:
isSatisfiable in class AbstractOutputSolver
Throws:
TimeoutException

addPseudoBoolean

public IConstr addPseudoBoolean(IVecInt lits,
                                IVec<BigInteger> coeffs,
                                boolean moreThan,
                                BigInteger d)
                         throws ContradictionException
Description copied from interface: IPBSolver
Create a Pseudo-Boolean constraint of the type "at least n or at most n of those literals must be satisfied"

Specified by:
addPseudoBoolean in interface IPBSolver
Parameters:
lits - a set of literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
coeffs - the coefficients of the literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
moreThan - true if it is a constraint >= degree, false if it is a constraint <= degree
d - the degree of the cardinality constraint
Returns:
a reference to the constraint added in the solver, to use in removeConstr().
Throws:
ContradictionException - iff the vector of literals is empty or if the constraint is falsified after unit propagation
See Also:
ISolver.removeConstr(IConstr)

setObjectiveFunction

public void setObjectiveFunction(ObjectiveFunction obj)
Description copied from interface: IPBSolver
Provide an objective function to the solver.

Specified by:
setObjectiveFunction in interface IPBSolver
Parameters:
obj - the objective function

addAtLeast

public IConstr addAtLeast(IVecInt literals,
                          int degree)
                   throws ContradictionException
Specified by:
addAtLeast in interface ISolver
Overrides:
addAtLeast in class DimacsStringSolver
Throws:
ContradictionException

addAtMost

public IConstr addAtMost(IVecInt literals,
                         int degree)
                  throws ContradictionException
Specified by:
addAtMost in interface ISolver
Overrides:
addAtMost in class DimacsStringSolver
Throws:
ContradictionException

addClause

public IConstr addClause(IVecInt literals)
                  throws ContradictionException
Specified by:
addClause in interface ISolver
Overrides:
addClause in class DimacsStringSolver
Throws:
ContradictionException

getExplanation

public String getExplanation()

setListOfVariablesForExplanation

public void setListOfVariablesForExplanation(IVecInt listOfVariables)

toString

public String toString()
Overrides:
toString in class DimacsStringSolver

toString

public String toString(String prefix)
Specified by:
toString in interface ISolver
Overrides:
toString in class DimacsStringSolver

newVar

public int newVar(int howmany)
Specified by:
newVar in interface IProblem
Overrides:
newVar in class DimacsStringSolver

setExpectedNumberOfClauses

public void setExpectedNumberOfClauses(int nb)
Specified by:
setExpectedNumberOfClauses in interface ISolver
Overrides:
setExpectedNumberOfClauses in class DimacsStringSolver

getObjectiveFunction

public ObjectiveFunction getObjectiveFunction()
Description copied from interface: IPBSolver
Retrieve the objective function from the solver.

Specified by:
getObjectiveFunction in interface IPBSolver
Returns:
the objective function

nConstraints

public int nConstraints()
Specified by:
nConstraints in interface IProblem
Overrides:
nConstraints in class DimacsStringSolver

addAtMost

public IConstr addAtMost(IVecInt literals,
                         IVecInt coeffs,
                         int degree)
                  throws ContradictionException
Description copied from interface: IPBSolver
Create a pseudo boolean constraint of the type "at most".

Specified by:
addAtMost in interface IPBSolver
Parameters:
literals - a set of literals The vector can be reused since the solver is not supposed to keep a reference to that vector.
coeffs - the coefficients of the literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
degree - the degree of the pseudo-boolean constraint
Returns:
a reference to the constraint added in the solver, to use in removeConstr().
Throws:
ContradictionException - iff the constraint is found trivially unsat.
See Also:
ISolver.removeConstr(IConstr)

addAtMost

public IConstr addAtMost(IVecInt literals,
                         IVec<BigInteger> coeffs,
                         BigInteger degree)
                  throws ContradictionException
Description copied from interface: IPBSolver
Create a pseudo boolean constraint of the type "at most".

Specified by:
addAtMost in interface IPBSolver
Parameters:
literals - a set of literals The vector can be reused since the solver is not supposed to keep a reference to that vector.
coeffs - the coefficients of the literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
degree - the degree of the pseudo-boolean constraint
Returns:
a reference to the constraint added in the solver, to use in removeConstr().
Throws:
ContradictionException - iff the constraint is found trivially unsat.
See Also:
ISolver.removeConstr(IConstr)

addAtLeast

public IConstr addAtLeast(IVecInt literals,
                          IVecInt coeffs,
                          int degree)
                   throws ContradictionException
Description copied from interface: IPBSolver
Create a pseudo-boolean constraint of the type "at least".

Specified by:
addAtLeast in interface IPBSolver
Parameters:
literals - a set of literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
coeffs - the coefficients of the literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
degree - the degree of the pseudo-boolean constraint
Returns:
a reference to the constraint added in the solver, to use in removeConstr().
Throws:
ContradictionException - iff the constraint is found trivially unsat.
See Also:
ISolver.removeConstr(IConstr)

addAtLeast

public IConstr addAtLeast(IVecInt literals,
                          IVec<BigInteger> coeffs,
                          BigInteger degree)
                   throws ContradictionException
Description copied from interface: IPBSolver
Create a pseudo-boolean constraint of the type "at least".

Specified by:
addAtLeast in interface IPBSolver
Parameters:
literals - a set of literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
coeffs - the coefficients of the literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
degree - the degree of the pseudo-boolean constraint
Returns:
a reference to the constraint added in the solver, to use in removeConstr().
Throws:
ContradictionException - iff the constraint is found trivially unsat.
See Also:
ISolver.removeConstr(IConstr)

addExactly

public IConstr addExactly(IVecInt literals,
                          IVecInt coeffs,
                          int weight)
                   throws ContradictionException
Description copied from interface: IPBSolver
Create a pseudo-boolean constraint of the type "subset sum".

Specified by:
addExactly in interface IPBSolver
Parameters:
literals - a set of literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
coeffs - the coefficients of the literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
weight - the number of literals that must be satisfied
Returns:
a reference to the constraint added to the solver. It might return an object representing a group of constraints.
Throws:
ContradictionException - iff the constraint is trivially unsatisfiable.

addExactly

public IConstr addExactly(IVecInt literals,
                          IVec<BigInteger> coeffs,
                          BigInteger weight)
                   throws ContradictionException
Description copied from interface: IPBSolver
Create a pseudo-boolean constraint of the type "subset sum".

Specified by:
addExactly in interface IPBSolver
Parameters:
literals - a set of literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
coeffs - the coefficients of the literals. The vector can be reused since the solver is not supposed to keep a reference to that vector.
weight - the number of literals that must be satisfied
Returns:
a reference to the constraint added to the solver. It might return an object representing a group of constraints.
Throws:
ContradictionException - iff the constraint is trivially unsatisfiable.


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