V
- type of variables involved in this propagatorpublic abstract class Propagator<V extends Variable> extends Object implements ICause, Identity, Comparable<Propagator>
Propagator
class defines methods to react on a Variable
objects modifications.
It is observed by Constraint
objects and can notify them when a Variable
event occurs.
A Propagator
declares a filtering algorithm to apply to the Variables
objects
in scope in order to reduce their Domain
objects.
That's why the propagate
method should be adapted to the expected filtering algorithm.
This method is called through Constraint
observers when an event occurs on a scoped Variable
object. propagate
method can throw a ContradictionException
when this Propagator
object detects a contradiction, within its filtering algorithm, like domain wipe out,
out of domain value instantiation or other incoherence.
Furthermore, a Propagator
object can be entailed : considering the current state of its Variable
objects, the internal filtering algorithm becomes useless (for example: NEQ propagator and a couple of Variable
objects with disjoint domains). In other words, whatever are the future events occurring on Variable
objects,
new calls to propagate
method would be useless.
this
can be deactivated using the setPassive
method.
It automatically informs Constraint
observers of this new "state".
The developer of a propagator must respect some rules to create a efficient propagator:
- internal references to variables must be achieved referencing the this.vars
after the call to super,
this prevents from wrong references when a variable occurs more than once in the scope (See PropCount_AC
for instance).
- //to complete
Variable
,
Constraint
Modifier and Type | Field and Description |
---|---|
protected static short |
ACTIVE
Status of the propagator when activated (ie, after initial propagation).
|
protected Constraint |
constraint
Encapsuling constraint.
|
static boolean |
DEFAULT_EXPL
For debugging purpose only, set to true to use default explanation schema, false to fail
|
protected Model |
model
Reference to the model declaring this propagator.
|
protected IOperation[] |
operations
Backtrackable operations to maintain the status on backtrack.
|
static boolean |
OUTPUT_DEFAULT_EXPL
Set to true to output the name of the constraint that use the default explanation schema
|
protected PropagatorPriority |
priority
Priority of this propagator.
|
protected boolean |
reactToFineEvt
Set to true to indidates that this propagator reacts to fine event.
|
protected short |
state
Current status of this propagator.
|
protected V[] |
vars
List of variables this propagators deal with.
|
Modifier | Constructor and Description |
---|---|
protected |
Propagator(V... vars)
Creates a non-incremental propagator which does not react to fine events but simply calls a
coarse propagation any time a variable in vars has changed.
|
protected |
Propagator(V[] vars,
PropagatorPriority priority,
boolean reactToFineEvt)
Creates a new propagator to filter the domains of vars.
|
protected |
Propagator(V[] vars,
PropagatorPriority priority,
boolean reactToFineEvt,
boolean swapOnPassivate)
Creates a new propagator to filter the domains of vars.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addVariable(V... nvars)
Enlarges the variable scope of this propagator
Should not be called by the user.
|
int |
arity() |
int |
compareTo(Propagator o) |
static void |
defaultExplain(Propagator prop,
ExplanationForSignedClause explanation,
ValueSortedMap<IntVar> front,
Implications ig,
int p) |
void |
doFinePropagation()
Apply fine event propagation of this.
|
void |
doFlush()
Flush pending events
|
int |
doSchedule(CircularQueue<Propagator>[] queues)
Apply scheduling instruction
|
void |
doScheduleEvent(int pindice,
int mask) |
int |
dynPriority()
Return the dynamic priority of this propagator.
|
boolean |
equals(Object o) |
void |
explain(ExplanationForSignedClause explanation,
ValueSortedMap<IntVar> front,
Implications ig,
int p)
Clausal explanation for this cause.
|
void |
fails()
Throws a contradiction exception
|
void |
forcePropagate(PropagatorEventType evt)
Schedules a coarse propagation to filter all variables at once.
|
protected void |
forcePropagationOnBacktrack()
Call this method when either the propagator has to be awake on backtrack.
|
void |
forEachIntVar(Consumer<IntVar> action)
Apply an action on each variable declared on the scope of this cause, if any.
|
Constraint |
getConstraint() |
int |
getId() |
Model |
getModel() |
int |
getNbVars() |
int |
getPosition() |
PropagatorPriority |
getPriority() |
int |
getPropagationConditions(int vIdx)
Returns the specific mask indicating the variable events on which this
Propagator object can react.A mask is a bitwise OR operations over IEventType this can react on. |
V |
getVar(int i)
Returns the element at the specified position in this internal list of
V objects. |
V[] |
getVars() |
int |
getVIndice(int idx) |
int[] |
getVIndices() |
int |
hashCode() |
boolean |
isActive() |
boolean |
isCompletelyInstantiated() |
abstract ESat |
isEntailed()
Check wether
this is entailed according to the current state of its internal structure. |
boolean |
isPassive() |
boolean |
isReified() |
boolean |
isReifiedAndSilent() |
boolean |
isScheduled() |
boolean |
isStateLess() |
void |
linkVariables()
Creates links between this propagator and its variables.
|
abstract void |
propagate(int evtmask)
Call the main filtering algorithm to apply to the
Domain of the Variable objects. |
void |
propagate(int idxVarInProp,
int mask)
Incremental filtering algorithm defined within the
Propagator , called whenever the variable
of index idxVarInProp has changed. |
boolean |
reactToFineEvent() |
BoolVar |
reifiedWith() |
void |
setActive()
informs that this propagator is now active.
|
protected void |
setActive0() |
void |
setPassive()
informs that this propagator is now passive : it holds but no further filtering can occur,
so it is useless to propagate it.
|
void |
setPosition(int p)
Set the position of this in the propagation engine or -1 if removed.
|
void |
setReifiedSilent(BoolVar boolVar)
informs that this reified propagator may not hold.
|
void |
setReifiedTrue()
informs that this reified propagator must hold.
|
void |
setVIndices(int idx,
int val)
Changes the index of a variable in this propagator.
|
String |
toString() |
void |
unlinkVariables()
Destroy links between this propagator and its variables.
|
void |
unschedule()
Set this as unscheduled
|
protected static final short ACTIVE
public static boolean DEFAULT_EXPL
public static boolean OUTPUT_DEFAULT_EXPL
protected short state
protected IOperation[] operations
protected final PropagatorPriority priority
protected final boolean reactToFineEvt
propagate(int, int)
will never be called.protected Constraint constraint
protected final Model model
protected Propagator(V[] vars, PropagatorPriority priority, boolean reactToFineEvt, boolean swapOnPassivate)
To limit memory consumption, the array of variables is referenced directly (no clone).
This is the responsibility of the propagator's developer to take care of that point.
vars
- variables of the propagator. Their modification will trigger
filteringpriority
- priority of this propagator (lowest priority propagators are called
first)reactToFineEvt
- indicates whether or not this propagator must be informed of every
variable modification, i.e. if it should be incremental or notswapOnPassivate
- indicates if, on propagator passivation, the propagator should be
ignored in its variables' propagators list.protected Propagator(V[] vars, PropagatorPriority priority, boolean reactToFineEvt)
To limit memory consumption, the array of variables is referenced directly (no clone).
This is the responsibility of the propagator's developer to take care of that point.
vars
- variables of the propagator. Their modification will trigger filteringpriority
- priority of this propagator (lowest priority propagators are called
first)reactToFineEvt
- indicates whether or not this propagator must be informed of every
variable modification, i.e. if it should be incremental or not@SafeVarargs protected Propagator(V... vars)
vars
- variables of the propagator. Their modification will trigger filtering@SafeVarargs protected final void addVariable(V... nvars)
nvars
- variables to be added to this propagatorpublic final void linkVariables()
public final void unlinkVariables()
public int getPropagationConditions(int vIdx)
Propagator
object can react.IEventType
this 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:
IntEventType.VOID
which states
that this propagator should not be aware of modifications applied to the variable in position vIdx.vIdx
- index of the variable within the propagatorREMOVE
and/or INSTANTIATE
and/or DECUPP
and/or INCLOW
public abstract void propagate(int evtmask) throws ContradictionException
Domain
of the Variable
objects.
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:
evtmask
- type of propagation event this
must consider.ContradictionException
- when a contradiction occurs, like domain wipe out or other incoherencies.public void propagate(int idxVarInProp, int mask) throws ContradictionException
Propagator
, 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 reactToFineEvt
is set to true
in the constructor.
Otherwise, it executes propagate(PropagatorEventType.CUSTOM_PROPAGATION.getStrengthenedMask());
idxVarInProp
- index of the variable var
in this
mask
- type of eventContradictionException
- if a contradiction occurspublic final void forcePropagate(PropagatorEventType evt) throws ContradictionException
Add the coarse event recorder into the engine
evt
- event typeContradictionException
- if the propagation encounters inconsistency.public void setActive() throws SolverException
SolverException
- if the propagator cannot be activated due to its current stateprotected void setActive0()
public void setReifiedTrue() throws SolverException
SolverException
- if the propagator cannot be activated due to its current statepublic void setReifiedSilent(BoolVar boolVar) throws SolverException
boolVar
- the reifying variableSolverException
- if the propagator cannot be reified due to its current statepublic void setPassive() throws SolverException
SolverException
- if the propagator cannot be set passive due to its current stateprotected void forcePropagationOnBacktrack()
public abstract ESat isEntailed()
this
is entailed according to the current state of its internal structure.
At least, should check the satisfaction of this
(when all is instantiated).public boolean isCompletelyInstantiated()
public int arity()
public int dynPriority()
public void fails() throws ContradictionException
ContradictionException
- expected behaviorpublic int compareTo(Propagator o)
compareTo
in interface Comparable<Propagator>
public BoolVar reifiedWith()
public boolean isReified()
reifiedWith()
to get the reifying variable.public Model getModel()
public final V getVar(int i)
V
objects.i
- index of the elementV
objectpublic final V[] getVars()
public int[] getVIndices()
public int getVIndice(int idx)
public void setVIndices(int idx, int val)
idx
- old indexval
- new indexpublic final int getNbVars()
this
.public final Constraint getConstraint()
public final PropagatorPriority getPriority()
public boolean isStateLess()
public boolean isReifiedAndSilent()
public boolean isActive()
public boolean isPassive()
public final boolean reactToFineEvent()
public void explain(ExplanationForSignedClause explanation, ValueSortedMap<IntVar> front, Implications ig, int p)
ICause
This method must filled explanations with inferred literals. These literals are inferred from the analysis of (a subset of) conflicting nodes stored in front, the implication graph ig and the current node in conflict, not yet contained in front.
Optionally, this method can update front by looking for a predecessor of any node that seems more relevant than the declared one.
public static void defaultExplain(Propagator prop, ExplanationForSignedClause explanation, ValueSortedMap<IntVar> front, Implications ig, int p)
public void forEachIntVar(Consumer<IntVar> action)
ICause
forEachIntVar
in interface ICause
action
- action to perform on each variable declared in this cause.public int getPosition()
public void setPosition(int p)
p
- position of this in the propagation engine or -1 if removed.public final void unschedule()
public final boolean isScheduled()
public int doSchedule(CircularQueue<Propagator>[] queues)
queues
- array of queues in which this can be scheduledpublic void doScheduleEvent(int pindice, int mask)
public void doFinePropagation() throws ContradictionException
ContradictionException
- if a contradiction occurred.public void doFlush()
Copyright © 2018. All rights reserved.