- java.lang.Object
-
- org.logicng.solvers.sat.MiniSatStyleSolver
-
- org.logicng.solvers.sat.MiniCard
-
public class MiniCard extends MiniSatStyleSolver
A cardinality solver based on MiniCard.- Since:
- 1.0
- Version:
- 2.1.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.logicng.solvers.sat.MiniSatStyleSolver
MiniSatStyleSolver.ProofInformation
-
-
Field Summary
Fields Modifier and Type Field Description protected static intLIT_ERRORprotected LNGIntVectorunitClauses-
Fields inherited from class org.logicng.solvers.sat.MiniSatStyleSolver
analyzeBtLevel, analyzeStack, analyzeToClear, assumptions, backboneAssumptions, backboneCandidates, backboneMap, canceledByHandler, ccminMode, claInc, clauseDecay, clauses, clausesLiterals, computingBackbone, config, conflict, handler, idx2name, incremental, learnts, learntsizeAdjustCnt, learntsizeAdjustConfl, learntsizeAdjustInc, learntsizeAdjustStartConfl, learntsizeFactor, learntsizeInc, learntsLiterals, LIT_UNDEF, maxLearnts, model, name2idx, ok, orderHeap, pgOriginalClauses, pgProof, qhead, restartFirst, restartInc, seen, selectionOrder, selectionOrderIdx, shouldRemoveSatsisfied, simpDBAssigns, simpDBProps, trail, trailLim, varDecay, varInc, vars, watches
-
-
Constructor Summary
Constructors Constructor Description MiniCard()Constructs a new MiniSAT 2 solver with the default values for solver configuration.MiniCard(MiniSatConfig config)Constructs a new MiniSAT 2 solver with a given solver configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddAtMost(LNGIntVector ps, int rhs)Adds an at-most k constraint.booleanaddClause(LNGIntVector ps, Proposition proposition)Adds a clause to the solver.protected voidanalyze(MSClause conflictClause, LNGIntVector outLearnt)Analyzes a given conflict clause wrt.protected voidanalyzeFinal(int p, LNGIntVector outConflict)Analysis the final conflict if there were assumptions.protected voidattachClause(MSClause c)Attaches a given clause to the solver (i.e.protected voidcompleteBacktrack()Performs an unconditional backtrack to level zero.protected voiddetachAtMost(MSClause c)Detaches a given at-most clause.protected voiddetachClause(MSClause c)Detaches a given clause (e.g.protected intfindNewWatch(MSClause c, int p)protected voidinitializeMiniSAT()Initializes the additional parameters.protected booleanlitRedundant(int p, int abstractLevels)Returnstrueif a given literal is redundant in the current conflict analysis,falseotherwise.voidloadState(int[] state)Loads a given state in the solver.intnewVar(boolean sign, boolean dvar)Adds a new variable to the solver.protected MSClausepropagate()Performs unit propagation.protected voidreduceDB()Reduces the database of learnt clauses.protected voidremoveClause(MSClause c)Removes a given clause.protected voidremoveSatisfied(LNGVector<MSClause> cs)Removes all clauses which are satisfied under the current assignment of a set of clauses.voidreset()Resets the solver state.protected booleansatisfied(MSClause c)Returnstrueif a given clause is satisfied under the current assignment,falseotherwise.int[]saveState()Saves and returns the solver state expressed as an integer array which stores the length of the internal data structures.protected Tristatesearch(int nofConflicts)The main search procedure of the CDCL algorithm.protected voidsimpleRemoveClause(MSClause c)Performs a simple removal of clauses used during the loading of an older state.protected booleansimplify()Simplifies the database of clauses.protected voidsimplifyClause(LNGIntVector outLearnt)Minimizes a given learnt clause depending on the minimization method of the solver configuration.Tristatesolve(SATHandler handler)Solves the formula currently stored in the solver.protected voiduncheckedEnqueue(int lit, MSClause reason)Assigns a literal (= a variable to the respective value).-
Methods inherited from class org.logicng.solvers.sat.MiniSatStyleSolver
abstractLevel, addBackboneLiteral, addClause, addName, buildBackbone, cancelUntil, claBumpActivity, claDecayActivity, clauses, computeBackbone, computeBackbone, computeBackbone, conflict, createInitialCandidates, decayActivities, decisionLevel, getName2idx, getRelevantVarIndices, idxForName, initBackboneDS, initialize, initializeConfig, insertVarOrder, isBothOrNegativeType, isBothOrPositiveType, isBothType, isRotatable, isUnit, isUPZeroLit, locked, lt, luby, mkLit, model, name2idx, nameForIdx, nAssigns, not, nVars, ok, pgOriginalClauses, pgProof, pickBranchLit, rebuildOrderHeap, refineUpperBound, resetSelectionOrder, setSelectionOrder, sign, solve, solveWithLit, toString, upZeroLiterals, v, value, var, varBumpActivity, varBumpActivity, varDecayActivity, variables
-
-
-
-
Field Detail
-
LIT_ERROR
protected static final int LIT_ERROR
- See Also:
- Constant Field Values
-
unitClauses
protected LNGIntVector unitClauses
-
-
Constructor Detail
-
MiniCard
public MiniCard()
Constructs a new MiniSAT 2 solver with the default values for solver configuration. By default, incremental mode is activated.
-
MiniCard
public MiniCard(MiniSatConfig config)
Constructs a new MiniSAT 2 solver with a given solver configuration.- Parameters:
config- the solver configuration
-
-
Method Detail
-
initializeMiniSAT
protected void initializeMiniSAT()
Initializes the additional parameters.
-
newVar
public int newVar(boolean sign, boolean dvar)Description copied from class:MiniSatStyleSolverAdds a new variable to the solver.- Specified by:
newVarin classMiniSatStyleSolver- Parameters:
sign- the initial polarity of the new variable,trueif negative,falseif positivedvar-trueif this variable can be used as a decision variable,falseif it should not be used as a decision variable- Returns:
- the index of the new variable
-
addClause
public boolean addClause(LNGIntVector ps, Proposition proposition)
Description copied from class:MiniSatStyleSolverAdds a clause to the solver.- Specified by:
addClausein classMiniSatStyleSolver- Parameters:
ps- the literals of the clauseproposition- a proposition (if required for proof tracing)- Returns:
trueif the clause was added successfully,falseotherwise
-
solve
public Tristate solve(SATHandler handler)
Description copied from class:MiniSatStyleSolverSolves the formula currently stored in the solver. ReturnsTristate.TRUEif the formula is satisfiable (SAT),Tristate.FALSEif the formula is unsatisfiable (UNSAT), orTristate.UNDEFif the computation was canceled by aSATHandler. Ifnullis passed as handler, the solver will run until the satisfiability is decided.- Specified by:
solvein classMiniSatStyleSolver- Parameters:
handler- a sat handler- Returns:
Tristate.TRUEif the formula is satisfiable,Tristate.FALSEif the formula is not satisfiable, orTristate.UNDEFif the computation was canceled.
-
reset
public void reset()
Description copied from class:MiniSatStyleSolverResets the solver state.- Specified by:
resetin classMiniSatStyleSolver
-
saveState
public int[] saveState()
Saves and returns the solver state expressed as an integer array which stores the length of the internal data structures. The array has length 5 and has the following layout:| current solver state | #vars | #clauses | #learnt clauses | #unit clauses |- Specified by:
saveStatein classMiniSatStyleSolver- Returns:
- the current solver state
-
loadState
public void loadState(int[] state)
Description copied from class:MiniSatStyleSolverLoads a given state in the solver.ATTENTION: You can only load a state which was created by this instance of the solver before the current state. Only the sizes of the internal data structures are stored, meaning you can track back in time and restore a solver state with fewer variables and/or fewer clauses. It is not possible to import a solver state from another solver or another solving execution.
- Specified by:
loadStatein classMiniSatStyleSolver- Parameters:
state- the solver state to load
-
uncheckedEnqueue
protected void uncheckedEnqueue(int lit, MSClause reason)Description copied from class:MiniSatStyleSolverAssigns a literal (= a variable to the respective value).- Specified by:
uncheckedEnqueuein classMiniSatStyleSolver- Parameters:
lit- the literalreason- the reason clause of the assignment (conflict resolution) ornullif it was a decision
-
attachClause
protected void attachClause(MSClause c)
Description copied from class:MiniSatStyleSolverAttaches a given clause to the solver (i.e. the watchers for this clause are initialized).- Specified by:
attachClausein classMiniSatStyleSolver- Parameters:
c- the clause
-
detachClause
protected void detachClause(MSClause c)
Description copied from class:MiniSatStyleSolverDetaches a given clause (e.g. removes all watchers pointing to this clause).- Specified by:
detachClausein classMiniSatStyleSolver- Parameters:
c- the clause
-
removeClause
protected void removeClause(MSClause c)
Description copied from class:MiniSatStyleSolverRemoves a given clause.- Specified by:
removeClausein classMiniSatStyleSolver- Parameters:
c- the clause to remove
-
propagate
protected MSClause propagate()
Description copied from class:MiniSatStyleSolverPerforms unit propagation.- Specified by:
propagatein classMiniSatStyleSolver- Returns:
- the conflicting clause if a conflict arose during unit propagation or
nullif there was none
-
litRedundant
protected boolean litRedundant(int p, int abstractLevels)Description copied from class:MiniSatStyleSolverReturnstrueif a given literal is redundant in the current conflict analysis,falseotherwise.- Specified by:
litRedundantin classMiniSatStyleSolver- Parameters:
p- the literalabstractLevels- an abstraction of levels- Returns:
trueif a given literal is redundant in the current conflict analysis
-
analyzeFinal
protected void analyzeFinal(int p, LNGIntVector outConflict)Description copied from class:MiniSatStyleSolverAnalysis the final conflict if there were assumptions.- Specified by:
analyzeFinalin classMiniSatStyleSolver- Parameters:
p- the conflicting literaloutConflict- the vector to store the final conflict
-
reduceDB
protected void reduceDB()
Description copied from class:MiniSatStyleSolverReduces the database of learnt clauses. Only clauses of the first half of the clauses with the most activity are possibly removed. A clause is only removed if it is not locked, i.e. is the reason of an assignment for a variable.- Specified by:
reduceDBin classMiniSatStyleSolver
-
removeSatisfied
protected void removeSatisfied(LNGVector<MSClause> cs)
Description copied from class:MiniSatStyleSolverRemoves all clauses which are satisfied under the current assignment of a set of clauses.- Specified by:
removeSatisfiedin classMiniSatStyleSolver- Parameters:
cs- the set of clauses
-
satisfied
protected boolean satisfied(MSClause c)
Description copied from class:MiniSatStyleSolverReturnstrueif a given clause is satisfied under the current assignment,falseotherwise.- Specified by:
satisfiedin classMiniSatStyleSolver- Parameters:
c- the clause- Returns:
trueif a given clause is satisfied under the current assignment
-
simplify
protected boolean simplify()
Description copied from class:MiniSatStyleSolverSimplifies the database of clauses. This method is only executed on level 0. All learnt clauses which are satisfied on level 0 are removed. Depending on the configuration of the solver, also original clauses which are satisfied at level 0 are removed.- Specified by:
simplifyin classMiniSatStyleSolver- Returns:
trueif simplification was successful and no conflict was found,falseif a conflict was found during the simplification
-
addAtMost
public boolean addAtMost(LNGIntVector ps, int rhs)
Adds an at-most k constraint.- Parameters:
ps- the literals of the constraintrhs- the right-hand side of the constraint- Returns:
trueif the constraint was added,falseotherwise
-
detachAtMost
protected void detachAtMost(MSClause c)
Detaches a given at-most clause.- Parameters:
c- the at-most clause.
-
search
protected Tristate search(int nofConflicts)
The main search procedure of the CDCL algorithm.- Parameters:
nofConflicts- the number of conflicts till the next restart- Returns:
- a
Tristaterepresenting the result.FALSEif the formula is UNSAT,TRUEif the formula is SAT, andUNKNOWNif the state is not known yet (restart)
-
findNewWatch
protected int findNewWatch(MSClause c, int p)
-
analyze
protected void analyze(MSClause conflictClause, LNGIntVector outLearnt)
Analyzes a given conflict clause wrt. the current solver state. A 1-UIP clause is created during this procedure and the new backtracking level is stored in the solver state.- Parameters:
conflictClause- the conflict clause to start the resolution analysis withoutLearnt- the vector where the new learnt 1-UIP clause is stored
-
simplifyClause
protected void simplifyClause(LNGIntVector outLearnt)
Minimizes a given learnt clause depending on the minimization method of the solver configuration.- Parameters:
outLearnt- the learnt clause which should be minimized
-
completeBacktrack
protected void completeBacktrack()
Performs an unconditional backtrack to level zero.
-
simpleRemoveClause
protected void simpleRemoveClause(MSClause c)
Performs a simple removal of clauses used during the loading of an older state.- Parameters:
c- the clause to remove
-
-