- java.lang.Object
-
- org.logicng.solvers.SATSolver
-
- org.logicng.solvers.MiniSat
-
public class MiniSat extends SATSolver
Wrapper for the MiniSAT-style SAT solvers.- Since:
- 1.0
- Version:
- 2.4.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMiniSat.SolverStyle
-
Field Summary
Fields Modifier and Type Field Description protected CCEncoderccEncoderprotected MiniSatConfigconfigprotected PlaistedGreenbaumTransformationSolverfullPgTransformationprotected booleanincrementalprotected booleaninitialPhaseprotected booleanlastComputationWithAssumptionsprotected intnextStateIdprotected PlaistedGreenbaumTransformationSolverpgTransformationprotected MiniSatStyleSolversolverprotected MiniSat.SolverStylestyleprotected LNGIntVectorvalidStates
-
Constructor Summary
Constructors Modifier Constructor Description protectedMiniSat(FormulaFactory f, MiniSat.SolverStyle solverStyle, MiniSatConfig miniSatConfig, GlucoseConfig glucoseConfig)Constructs a new SAT solver instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Formula formula, Proposition proposition)Adds a formula to the solver.protected voidaddClause(Formula formula, Proposition proposition)Adds a formula which must be a clause to the solver.protected voidaddFormulaAsCNF(Formula formula, Proposition proposition)CCIncrementalDataaddIncrementalCC(CardinalityConstraint cc)Adds a cardinality constraint and returns its incremental data in order to refine the constraint on the solver.voidaddWithoutUnknown(Formula formula)Adds a formula to the solver, but sets all variables to false which are not known to the solver.booleancanGenerateProof()Returns whether this solver instance can generate proofs.booleancanSaveLoadState()Returns whether this solver instance can save and load solver states.AssignmentcreateAssignment(LNGBooleanVector vec, LNGIntVector relevantIndices)Creates an assignment from a Boolean vector of the solver.AssignmentcreateAssignment(LNGBooleanVector vec, LNGIntVector relevantIndices, boolean fastEvaluable)Creates an assignment from a Boolean vector of the solver.<RESULT> RESULTexecute(SolverFunction<RESULT> function)Executes a solver function on this solver.protected LNGIntVectorgenerateClauseVector(Collection<? extends Literal> literals)Generates a clause vector of a collection of literals.MiniSatConfiggetConfig()Returns this solver's configuration.protected intgetOrAddIndex(Literal lit)TristategetResult()Returns the current result, e.g.MiniSat.SolverStylegetStyle()Returns this solver's style.static MiniSatglucose(FormulaFactory f)Returns a new Glucose solver with the MiniSat and Glucose configuration from the formula factory.static MiniSatglucose(FormulaFactory f, MiniSatConfig miniSatConfig, GlucoseConfig glucoseConfig)Returns a new Glucose solver with a given configuration.booleaninitialPhase()Returns the initial phase of literals of this solver.booleanisIncremental()Returns whether this solver is incrementalbooleanisLastComputationWithAssumptions()Returns whether the last computation was using assumption literals.booleanisRelevantVariable(String name)Returns whether a variable on the solver is relevant or an auxiliary variable.SortedSet<Variable>knownVariables()Returns the set of variables currently known by the solver.protected booleanlastResultIsUsable()voidloadState(SolverState state)Loads a given solver state.static MiniSatminiCard(FormulaFactory f)Returns a new MiniCard solver with the MiniSat configuration from the formula factory.static MiniSatminiCard(FormulaFactory f, MiniSatConfig config)Returns a new MiniCard solver with a given configuration.static MiniSatminiSat(FormulaFactory f)Returns a new MiniSat solver with the MiniSat configuration from the formula factory.static MiniSatminiSat(FormulaFactory f, MiniSatConfig config)Returns a new MiniSat solver with a given configuration.static MiniSatmk(FormulaFactory f, MiniSat.SolverStyle style)Returns a new solver depending on the given solver style with the configuration from the formula factory.static MiniSatmk(FormulaFactory f, MiniSat.SolverStyle solverStyle, MiniSatConfig miniSatConfig, GlucoseConfig glucoseConfig)Returns a new solver depending on the given solver style with the given configuration.Assignmentmodel(Collection<Variable> variables)Returns a model of the current formula on the solver wrt.voidreset()Resets the SAT solver.voidresetSelectionOrder()Resets the selection order on the solver.Tristatesat(SATHandler handler)ReturnsTristate.TRUEif the current formula in the solver is satisfiable, @{code Tristate.FALSE} if it is unsatisfiable, orUNDEFif the solving process was aborted.Tristatesat(SATHandler handler, Collection<? extends Literal> assumptions)ReturnsTristate.TRUEif the current formula in the solver and a given collection of assumed literals are satisfiable,Tristate.FALSEif it is unsatisfiable, orUNDEFif the solving process was aborted.Tristatesat(SATHandler handler, Literal literal)ReturnsTristate.TRUEif the current formula in the solver and a given literal are satisfiable,Tristate.FALSEif it is unsatisfiable, orUNDEFif the solving process was aborted.SolverStatesaveState()Saves the current solver state.protected voidsetResult(Tristate tristate)voidsetSelectionOrder(List<? extends Literal> selectionOrder)Sets the selection order of the variables and their polarity.StringtoString()MiniSatStyleSolverunderlyingSolver()Returns the underlying core solver.-
Methods inherited from class org.logicng.solvers.SATSolver
add, add, add, addPropositions, addPropositions, addWithRelaxation, addWithRelaxation, addWithRelaxation, backbone, backbone, enumerateAllModels, enumerateAllModels, enumerateAllModels, factory, model, model, sat, sat, sat, satWithSelectionOrder, satWithSelectionOrder, setSolverToUndef, unsatCore
-
-
-
-
Field Detail
-
config
protected final MiniSatConfig config
-
solver
protected final MiniSatStyleSolver solver
-
ccEncoder
protected final CCEncoder ccEncoder
-
style
protected final MiniSat.SolverStyle style
-
validStates
protected final LNGIntVector validStates
-
initialPhase
protected final boolean initialPhase
-
incremental
protected final boolean incremental
-
nextStateId
protected int nextStateId
-
pgTransformation
protected final PlaistedGreenbaumTransformationSolver pgTransformation
-
fullPgTransformation
protected final PlaistedGreenbaumTransformationSolver fullPgTransformation
-
lastComputationWithAssumptions
protected boolean lastComputationWithAssumptions
-
-
Constructor Detail
-
MiniSat
protected MiniSat(FormulaFactory f, MiniSat.SolverStyle solverStyle, MiniSatConfig miniSatConfig, GlucoseConfig glucoseConfig)
Constructs a new SAT solver instance.- Parameters:
f- the formula factorysolverStyle- the solver styleminiSatConfig- the MiniSat configuration, must not benullglucoseConfig- the Glucose configuration, must not benullfor solver typeMiniSat.SolverStyle.GLUCOSE- Throws:
IllegalArgumentException- if the solver style is unknown
-
-
Method Detail
-
miniSat
public static MiniSat miniSat(FormulaFactory f)
Returns a new MiniSat solver with the MiniSat configuration from the formula factory.- Parameters:
f- the formula factory- Returns:
- the solver
-
miniSat
public static MiniSat miniSat(FormulaFactory f, MiniSatConfig config)
Returns a new MiniSat solver with a given configuration.- Parameters:
f- the formula factoryconfig- the configuration, must not benull- Returns:
- the solver
-
glucose
public static MiniSat glucose(FormulaFactory f)
Returns a new Glucose solver with the MiniSat and Glucose configuration from the formula factory.- Parameters:
f- the formula factory- Returns:
- the solver
-
glucose
public static MiniSat glucose(FormulaFactory f, MiniSatConfig miniSatConfig, GlucoseConfig glucoseConfig)
Returns a new Glucose solver with a given configuration.- Parameters:
f- the formula factoryminiSatConfig- the MiniSat configuration, must not benullglucoseConfig- the Glucose configuration, must not benull- Returns:
- the solver
-
miniCard
public static MiniSat miniCard(FormulaFactory f)
Returns a new MiniCard solver with the MiniSat configuration from the formula factory.- Parameters:
f- the formula factory- Returns:
- the solver
-
miniCard
public static MiniSat miniCard(FormulaFactory f, MiniSatConfig config)
Returns a new MiniCard solver with a given configuration.- Parameters:
f- the formula factoryconfig- the configuration, must not benull- Returns:
- the solver
-
mk
public static MiniSat mk(FormulaFactory f, MiniSat.SolverStyle style)
Returns a new solver depending on the given solver style with the configuration from the formula factory.- Parameters:
f- the formula factorystyle- the solver style, must not benull- Returns:
- the solver
-
mk
public static MiniSat mk(FormulaFactory f, MiniSat.SolverStyle solverStyle, MiniSatConfig miniSatConfig, GlucoseConfig glucoseConfig)
Returns a new solver depending on the given solver style with the given configuration.- Parameters:
f- the formula factorysolverStyle- the solver style, must not benullminiSatConfig- the configuration, must not benullglucoseConfig- the Glucose configuration, must not benullfor solver typeMiniSat.SolverStyle.GLUCOSE- Returns:
- the solver
-
add
public void add(Formula formula, Proposition proposition)
Description copied from class:SATSolverAdds a formula to the solver. The formula is first converted to CNF.
-
addFormulaAsCNF
protected void addFormulaAsCNF(Formula formula, Proposition proposition)
-
addWithoutUnknown
public void addWithoutUnknown(Formula formula)
Description copied from class:SATSolverAdds a formula to the solver, but sets all variables to false which are not known to the solver.- Specified by:
addWithoutUnknownin classSATSolver- Parameters:
formula- the formula
-
addIncrementalCC
public CCIncrementalData addIncrementalCC(CardinalityConstraint cc)
Description copied from class:SATSolverAdds a cardinality constraint and returns its incremental data in order to refine the constraint on the solver.Usage constraints: - "<": Cannot be used with right-hand side 2, returns null for right-hand side 1, but constraint is added to solver. - "<=": Cannot be used with right-hand side 1, returns null for right-hand side 0, but constraint is added to solver. - ">": Returns null for right-hand side 0 or number of variables -1, but constraint is added to solver. Adds false to solver for right-hand side >= number of variables. - ">=": Returns null for right-hand side 1 or number of variables, but constraint is added to solver. Adds false to solver for right-hand side > number of variables.
- Specified by:
addIncrementalCCin classSATSolver- Parameters:
cc- the cardinality constraint- Returns:
- the incremental data of this constraint, or null if the right-hand side of cc is 1
-
addClause
protected void addClause(Formula formula, Proposition proposition)
Description copied from class:SATSolverAdds a formula which must be a clause to the solver.
-
sat
public Tristate sat(SATHandler handler)
Description copied from class:SATSolverReturnsTristate.TRUEif the current formula in the solver is satisfiable, @{code Tristate.FALSE} if it is unsatisfiable, orUNDEFif the solving process was aborted.
-
sat
public Tristate sat(SATHandler handler, Literal literal)
Description copied from class:SATSolverReturnsTristate.TRUEif the current formula in the solver and a given literal are satisfiable,Tristate.FALSEif it is unsatisfiable, orUNDEFif the solving process was aborted.
-
sat
public Tristate sat(SATHandler handler, Collection<? extends Literal> assumptions)
Description copied from class:SATSolverReturnsTristate.TRUEif the current formula in the solver and a given collection of assumed literals are satisfiable,Tristate.FALSEif it is unsatisfiable, orUNDEFif the solving process was aborted. The assumptions can be seen as an additional conjunction of literals. Note: Use ordered collections to ensure determinism in the solving process and thus in the resulting model or conflict.
-
reset
public void reset()
Description copied from class:SATSolverResets the SAT solver.
-
model
public Assignment model(Collection<Variable> variables)
Description copied from class:SATSolverReturns a model of the current formula on the solver wrt. a given set of variables. If the set isnull, all variables are considered relevant. If the formula is UNSAT,nullwill be returned.
-
execute
public <RESULT> RESULT execute(SolverFunction<RESULT> function)
Description copied from class:SATSolverExecutes a solver function on this solver.
-
saveState
public SolverState saveState()
Description copied from class:SATSolverSaves the current solver state.
-
loadState
public void loadState(SolverState state)
Description copied from class:SATSolverLoads a given solver state.
-
knownVariables
public SortedSet<Variable> knownVariables()
Description copied from class:SATSolverReturns the set of variables currently known by the solver. NOTE: Due to the incremental/decremental interface of some solvers, this set is generated each time, the method is called. So if you can maintain a list of relevant/known variables in your own application, this is recommended.- Specified by:
knownVariablesin classSATSolver- Returns:
- the set of variables currently known by the solver
-
generateClauseVector
protected LNGIntVector generateClauseVector(Collection<? extends Literal> literals)
Generates a clause vector of a collection of literals.- Parameters:
literals- the literals- Returns:
- the clause vector
-
getOrAddIndex
protected int getOrAddIndex(Literal lit)
-
createAssignment
public Assignment createAssignment(LNGBooleanVector vec, LNGIntVector relevantIndices)
Creates an assignment from a Boolean vector of the solver. The created assignment is not fast evaluable.- Parameters:
vec- the vector of the solverrelevantIndices- the solver's indices of the relevant variables for the model. Ifnull, all variables are relevant.- Returns:
- the assignment
-
createAssignment
public Assignment createAssignment(LNGBooleanVector vec, LNGIntVector relevantIndices, boolean fastEvaluable)
Creates an assignment from a Boolean vector of the solver. The flagfastEvaluabledetermines if the created assignment isfast evaluableassignment.- Parameters:
vec- the vector of the solverrelevantIndices- the solver's indices of the relevant variables for the model. Ifnull, all variables are relevant.fastEvaluable-trueif the created assignment should be fast evaluable, otherwisefalse- Returns:
- the assignment
-
isRelevantVariable
public boolean isRelevantVariable(String name)
Returns whether a variable on the solver is relevant or an auxiliary variable.- Parameters:
name- the name of the variable- Returns:
- true if it is relevant, false if it is an auxiliary variable
-
underlyingSolver
public MiniSatStyleSolver underlyingSolver()
Returns the underlying core solver.ATTENTION: by influencing the underlying solver directly, you can mess things up completely! You should really know what you are doing.
- Returns:
- the underlying core solver
-
initialPhase
public boolean initialPhase()
Returns the initial phase of literals of this solver.- Returns:
- the initial phase of literals of this solver
-
lastResultIsUsable
protected boolean lastResultIsUsable()
-
getConfig
public MiniSatConfig getConfig()
Returns this solver's configuration.- Returns:
- this solver's configuration
-
setSelectionOrder
public void setSelectionOrder(List<? extends Literal> selectionOrder)
Description copied from class:SATSolverSets the selection order of the variables and their polarity.- Specified by:
setSelectionOrderin classSATSolver- Parameters:
selectionOrder- the variable order and their polarity that should be checked first
-
resetSelectionOrder
public void resetSelectionOrder()
Description copied from class:SATSolverResets the selection order on the solver. The internal activity heuristics for the variable ordering will be used again.- Specified by:
resetSelectionOrderin classSATSolver
-
canSaveLoadState
public boolean canSaveLoadState()
Description copied from class:SATSolverReturns whether this solver instance can save and load solver states.- Specified by:
canSaveLoadStatein classSATSolver- Returns:
- true when the solver can save and load states, false otherwise
-
canGenerateProof
public boolean canGenerateProof()
Description copied from class:SATSolverReturns whether this solver instance can generate proofs.- Specified by:
canGenerateProofin classSATSolver- Returns:
- true when the solver can generate proofs, false otherwise
-
getStyle
public MiniSat.SolverStyle getStyle()
Returns this solver's style.- Returns:
- this solver's style
-
isIncremental
public boolean isIncremental()
Returns whether this solver is incremental- Returns:
trueif this solver is incremental,falseotherwise
-
getResult
public Tristate getResult()
Returns the current result, e.g. the result of the lastSATSolver.sat()call.- Returns:
- the current result
-
setResult
protected void setResult(Tristate tristate)
-
isLastComputationWithAssumptions
public boolean isLastComputationWithAssumptions()
Returns whether the last computation was using assumption literals.- Returns:
trueif the last computation used assumption literals,falseotherwise
-
-