- java.lang.Object
-
- org.logicng.solvers.sat.MiniSatStyleSolver
-
- org.logicng.solvers.sat.GlucoseSyrup
-
public class GlucoseSyrup extends MiniSatStyleSolver
Glucose 4.0 solver.- 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 longanalyzeLBDprotected intanalyzeSzWithoutSelectorsprotected LNGBooleanVectorassumpprotected intconflictsprotected intconflictsRestartsprotected intcurRestartprotected doublefactorKprotected doublefactorRprotected intfirstReduceDBprotected GlucoseConfigglucoseConfigprotected intincReduceDBprotected LNGIntVectorlastDecisionLevelprotected static intLB_BLOCKING_RESTARTthe lower bound for blocking restartsprotected LNGBoundedLongQueuelbdQueueprotected intlbLBDFrozenClauseprotected intlbLBDMinimizingClauseprotected intlbSizeMinimizingClauseprotected doublemaxVarDecayprotected intmyflagprotected intnbclausesbeforereduceprotected LNGIntVectorpermDiffprotected static intRATIO_REMOVE_CLAUSESthe ratio of clauses which will be removedprotected booleanreduceOnSizeprotected intreduceOnSizeSizeprotected intsizeLBDQueueprotected intsizeTrailQueueprotected intspecialIncReduceDBprotected doublesumLBDprotected LNGBoundedIntQueuetrailQueueprotected LNGVector<LNGVector<MSWatcher>>watchesBin-
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 GlucoseSyrup(MiniSatConfig config, GlucoseConfig glucoseConfig)Constructs a new Glucose solver with a given solver configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddClause(LNGIntVector ps, Proposition proposition)Adds a clause to the solver.protected voidanalyze(MSClause conflictClause, LNGIntVector outLearnt, LNGIntVector selectors)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 longcomputeLBD(LNGIntVector lits, int e)Computes the LBD for a given vector of literals.protected longcomputeLBD(MSClause c)Computes the LBD for a given clauseprotected voiddetachClause(MSClause c)Detaches a given clause (e.g.protected voidinitializeGlucose()Initializes the additional parameters.protected voidinitializeGlucoseConfig()Initializes the glucose configuration.protected booleanisRotatable(int lit)Tests the given literal whether it is rotatable in the current model.protected booleanisSelector(int v)Returnstrueif a given variable is a selector variable,falseotherwise.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.protected voidminimisationWithBinaryResolution(LNGIntVector outLearnt)A special clause minimization by binary resolution for small clauses.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()The main search procedure of the CDCL algorithm.protected booleansimplify()Simplifies the database of clauses.protected voidsimplifyClause(LNGIntVector outLearnt, LNGIntVector selectors)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, 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
-
RATIO_REMOVE_CLAUSES
protected static final int RATIO_REMOVE_CLAUSES
the ratio of clauses which will be removed- See Also:
- Constant Field Values
-
LB_BLOCKING_RESTART
protected static final int LB_BLOCKING_RESTART
the lower bound for blocking restarts- See Also:
- Constant Field Values
-
glucoseConfig
protected final GlucoseConfig glucoseConfig
-
permDiff
protected LNGIntVector permDiff
-
lastDecisionLevel
protected LNGIntVector lastDecisionLevel
-
lbdQueue
protected LNGBoundedLongQueue lbdQueue
-
trailQueue
protected LNGBoundedIntQueue trailQueue
-
assump
protected LNGBooleanVector assump
-
myflag
protected int myflag
-
analyzeLBD
protected long analyzeLBD
-
analyzeSzWithoutSelectors
protected int analyzeSzWithoutSelectors
-
nbclausesbeforereduce
protected int nbclausesbeforereduce
-
conflicts
protected int conflicts
-
conflictsRestarts
protected int conflictsRestarts
-
sumLBD
protected double sumLBD
-
curRestart
protected int curRestart
-
lbLBDMinimizingClause
protected int lbLBDMinimizingClause
-
lbLBDFrozenClause
protected int lbLBDFrozenClause
-
lbSizeMinimizingClause
protected int lbSizeMinimizingClause
-
firstReduceDB
protected int firstReduceDB
-
specialIncReduceDB
protected int specialIncReduceDB
-
incReduceDB
protected int incReduceDB
-
factorK
protected double factorK
-
factorR
protected double factorR
-
sizeLBDQueue
protected int sizeLBDQueue
-
sizeTrailQueue
protected int sizeTrailQueue
-
reduceOnSize
protected boolean reduceOnSize
-
reduceOnSizeSize
protected int reduceOnSizeSize
-
maxVarDecay
protected double maxVarDecay
-
-
Constructor Detail
-
GlucoseSyrup
public GlucoseSyrup(MiniSatConfig config, GlucoseConfig glucoseConfig)
Constructs a new Glucose solver with a given solver configuration.- Parameters:
config- the MiniSat configurationglucoseConfig- the Glucose configuration
-
-
Method Detail
-
initializeGlucose
protected void initializeGlucose()
Initializes the additional parameters.
-
initializeGlucoseConfig
protected void initializeGlucoseConfig()
Initializes the glucose configuration.
-
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()
Description copied from class:MiniSatStyleSolverSaves and returns the solver state expressed as an integer array which stores the length of the internal data structures.- 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
-
computeLBD
protected long computeLBD(LNGIntVector lits, int e)
Computes the LBD for a given vector of literals.- Parameters:
lits- the vector of literalse- parameter for incremental mode- Returns:
- the LBD
-
computeLBD
protected long computeLBD(MSClause c)
Computes the LBD for a given clause- Parameters:
c- the clause- Returns:
- the LBD
-
isSelector
protected boolean isSelector(int v)
Returnstrueif a given variable is a selector variable,falseotherwise.- Parameters:
v- the variable- Returns:
trueif the given variable is a selector variable
-
minimisationWithBinaryResolution
protected void minimisationWithBinaryResolution(LNGIntVector outLearnt)
A special clause minimization by binary resolution for small clauses.- Parameters:
outLearnt- the vector where the new learnt 1-UIP clause is stored
-
search
protected Tristate search()
The main search procedure of the CDCL algorithm.- Returns:
- a
Tristaterepresenting the result.FALSEif the formula is UNSAT,TRUEif the formula is SAT, andUNKNOWNif the state is not known yet (restart)
-
analyze
protected void analyze(MSClause conflictClause, LNGIntVector outLearnt, LNGIntVector selectors)
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 storedselectors- a vector of selector variables
-
simplifyClause
protected void simplifyClause(LNGIntVector outLearnt, LNGIntVector selectors)
Minimizes a given learnt clause depending on the minimization method of the solver configuration.- Parameters:
outLearnt- the learnt clause which should be minimizedselectors- a vector of selector variables
-
isRotatable
protected boolean isRotatable(int lit)
Description copied from class:MiniSatStyleSolverTests the given literal whether it is rotatable in the current model.- Overrides:
isRotatablein classMiniSatStyleSolver- Parameters:
lit- literal to test- Returns:
trueif the literal is rotatable, otherwisefalse
-
-