Package org.chocosolver.sat
Class PropSat
- java.lang.Object
-
- org.chocosolver.solver.constraints.Propagator<BoolVar>
-
- org.chocosolver.sat.PropSat
-
- All Implemented Interfaces:
Comparable<Propagator>,ICause,Identity
public class PropSat extends Propagator<BoolVar>
A propagator to deal with clauses and interface aSatSolver.- Since:
- 12/07/13
- Author:
- Charles Prud'homme
-
-
Field Summary
-
Fields inherited from class org.chocosolver.solver.constraints.Propagator
constraint, model, priority, reactToFineEvt, vars
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddClause(gnu.trove.list.TIntList lits)Add a clause to SAT solvervoidaddLearnt(int... lits)Add learnt clause to SAT solvervoidafterAddingClauses()voidbeforeAddingClauses()intgetPropagationConditions(int vIdx)Returns the specific mask indicating the variable events on which thisPropagatorobject can react.
A mask is a bitwise OR operations overIEventTypethis can react on.org.chocosolver.sat.SatSolvergetSatSolver()voidinitialize()Initializes this propagatorESatisEntailed()Check wetherthisis entailed according to the current state of its internal structure.intmakeLiteral(BoolVar expr, boolean sign)Creates, or returns if already existing, the literal corresponding to :intmakeVar(BoolVar expr)Creates, or returns if already existing, the literal corresponding to :voidpropagate(int evtmask)Call the main filtering algorithm to apply to theDomainof theVariableobjects.voidpropagate(int idxVarInProp, int mask)Incremental filtering algorithm defined within thePropagator, called whenever the variable of index idxVarInProp has changed.booleanwhy(RuleStore ruleStore, IntVar bvar, IEventType evt, int bvalue)Add new rules to the rule store-
Methods inherited from class org.chocosolver.solver.constraints.Propagator
addVariable, arity, compareTo, doFinePropagation, doFlush, doSchedule, doScheduleEvent, dynPriority, equals, fails, forcePropagate, forcePropagationOnBacktrack, getConstraint, getId, getModel, getNbVars, getPosition, getPriority, getVar, getVars, getVIndice, getVIndices, hashCode, isActive, isCompletelyInstantiated, isPassive, isReifiedAndSilent, isStateLess, linkVariables, reactToFineEvent, setActive, setPassive, setPosition, setReifiedSilent, setReifiedTrue, setVIndices, toString, unlinkVariables, unschedule
-
-
-
-
Constructor Detail
-
PropSat
public PropSat(Model model)
Create a (unique) propagator for clauses recording and propagation.- Parameters:
model- the solver that declares the propagator
-
-
Method Detail
-
getPropagationConditions
public int getPropagationConditions(int vIdx)
Description copied from class:PropagatorReturns the specific mask indicating the variable events on which thisPropagatorobject can react.
A mask is a bitwise OR operations overIEventTypethis can react on. For example, consider a propagator that can deduce filtering based on the lower bound of the integer variable X. Then, for this variable, the mask should be equal to :int mask = IntEventType.INCLOW.getMask() | IntEventType.INSTANTIATE.getMask();or, in a more convenient way:int mask = IntEvtType.combine(IntEventType.INCLOW,IntEventType.INSTANTIATE);That indicates the following behavior:- if X is instantiated, this propagator will be executed,
- if the lower bound of X is modified, this propagator will be executed,
- if the lower bound of X is removed, the event is promoted from REMOVE to INCLOW and this propagator will NOT be executed,
- otherwise, this propagator will NOT be executed
IntEventType.VOIDwhich states that this propagator should not be aware of modifications applied to the variable in position vIdx.- Overrides:
getPropagationConditionsin classPropagator<BoolVar>- Parameters:
vIdx- index of the variable within the propagator- Returns:
- an int composed of
REMOVEand/orINSTANTIATEand/orDECUPPand/orINCLOW
-
propagate
public void propagate(int evtmask) throws ContradictionExceptionDescription copied from class:PropagatorCall the main filtering algorithm to apply to theDomainof theVariableobjects. It considers the current state of this objects to remove some values from domains and/or instantiate some variables. Calling this method is done from 2 (and only 2) steps:
- at the initial propagation step,
- when involved in a reified constraint.
It should initialized the internal data structure and apply filtering algorithm from scratch.- Specified by:
propagatein classPropagator<BoolVar>- Parameters:
evtmask- type of propagation eventthismust consider.- Throws:
ContradictionException- when a contradiction occurs, like domain wipe out or other incoherencies.
-
propagate
public void propagate(int idxVarInProp, int mask) throws ContradictionExceptionDescription copied from class:PropagatorIncremental filtering algorithm defined within thePropagator, called whenever the variable of index idxVarInProp has changed. This method calls a CUSTOM_PROPAGATION (coarse-grained) by default.This method should be overridden if the argument
reactToFineEvtis set totruein the constructor. Otherwise, it executespropagate(PropagatorEventType.CUSTOM_PROPAGATION.getStrengthenedMask());- Overrides:
propagatein classPropagator<BoolVar>- Parameters:
idxVarInProp- index of the variablevarinthismask- type of event- Throws:
ContradictionException- if a contradiction occurs
-
isEntailed
public ESat isEntailed()
Description copied from class:PropagatorCheck wetherthisis entailed according to the current state of its internal structure. At least, should check the satisfaction ofthis(when all is instantiated).- Specified by:
isEntailedin classPropagator<BoolVar>- Returns:
- ESat.TRUE if entailed, ESat.FALSE if not entailed, ESat.UNDEFINED if unknown
-
getSatSolver
public org.chocosolver.sat.SatSolver getSatSolver()
- Returns:
- the underlying SAT solver
-
initialize
public void initialize()
Initializes this propagator
-
makeVar
public int makeVar(BoolVar expr)
Creates, or returns if already existing, the literal corresponding to :expris trueThe negation of the literal is managed outside.
- Parameters:
expr- a boolean variable- Returns:
- its literal
-
makeLiteral
public int makeLiteral(BoolVar expr, boolean sign)
Creates, or returns if already existing, the literal corresponding to :expris trueThe negation of the literal is managed outside.
- Parameters:
expr- a boolean variablesign- true for even- Returns:
- its literal
-
beforeAddingClauses
public void beforeAddingClauses()
-
afterAddingClauses
public void afterAddingClauses()
-
addClause
public boolean addClause(gnu.trove.list.TIntList lits)
Add a clause to SAT solver- Parameters:
lits- clause- Returns:
- false if failure is detected
-
addLearnt
public void addLearnt(int... lits)
Add learnt clause to SAT solver- Parameters:
lits- clause
-
why
public boolean why(RuleStore ruleStore, IntVar bvar, IEventType evt, int bvalue)
Description copied from interface:ICauseAdd new rules to the rule store- Specified by:
whyin interfaceICause- Overrides:
whyin classPropagator<BoolVar>- Parameters:
ruleStore- the rule storebvar- the modified variableevt- the undergoing eventbvalue- the value (for REMOVE only)- Returns:
- true if at least one rule has been added to the rule store
-
-