public abstract class Propagator<V extends Variable> extends Object implements Serializable, 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
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected Propagator |
aCause |
protected static short |
ACTIVE |
protected Constraint |
constraint |
protected static org.slf4j.Logger |
LOGGER |
protected static short |
NEW |
protected static short |
PASSIVE |
protected PropagatorPriority |
priority |
protected boolean |
reactToFineEvt |
protected static short |
REIFIED |
protected Solver |
solver |
protected V[] |
vars |
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.
|
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.
|
boolean |
advise(int idxVarInProp,
int mask)
Advise a propagator of a modification occurring on one of its variables,
and decide if
this should be scheduled. |
int |
arity() |
int |
compareTo(Propagator o) |
void |
contradiction(Variable variable,
String message)
Throws a contradiction exception based on
|
void |
decNbPendingEvt()
informs that a fine event has been treated.
|
void |
defineIn(Constraint c)
Informs this propagator the (unique) constraint it filters.
|
void |
duplicate(Solver solver,
gnu.trove.map.hash.THashMap<Object,Object> identitymap)
Duplicate the current propagator.
|
int |
dynPriority() |
void |
flushPendingEvt()
informs that all fine events have been treated.
|
void |
forcePropagate(PropagatorEventType evt)
Schedules a coarse propagation to filter all variables at once.
|
Constraint |
getConstraint() |
int |
getId() |
int |
getNbPendingEvt() |
int |
getNbVars() |
PropagatorPriority |
getPriority() |
protected int |
getPropagationConditions(int vIdx)
Return the specific mask indicating the variable events on which this
Propagator object can react. |
Solver |
getSolver() |
V |
getVar(int i)
Returns the element at the specified position in this internal list of
V objects. |
V[] |
getVars() |
int[] |
getVIndices() |
int |
hashCode() |
void |
incNbPendingEvt()
informs that a new fine event has to be treated.
|
boolean |
isActive() |
boolean |
isCompletelyInstantiated() |
abstract ESat |
isEntailed()
Check wether
this is entailed according to the current state of its internal structure. |
boolean |
isPassive() |
boolean |
isReifiedAndSilent() |
boolean |
isStateLess() |
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() |
void |
setActive()
informs that this propagator is now active.
|
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 |
setReifiedSilent()
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() |
boolean |
why(RuleStore ruleStore,
IntVar var,
IEventType evt,
int value)
Add new rules to the rule store
|
protected static final org.slf4j.Logger LOGGER
protected static final short NEW
protected static final short REIFIED
protected static final short ACTIVE
protected static final short PASSIVE
protected Propagator aCause
protected final PropagatorPriority priority
protected final boolean reactToFineEvt
protected Constraint constraint
protected final Solver solver
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 void defineIn(Constraint c)
c
- the constraint containing this propagatorprotected int getPropagationConditions(int vIdx)
Propagator
object can react.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 boolean advise(int idxVarInProp, int mask)
this
should be scheduled.
At least, this method SHOULD check the propagation condition of the event received.
In addition, this method can be used to update internal state of this
.
This method can returns true
even if the propagator is already scheduled.idxVarInProp
- index of the modified variablemask
- modification event masktrue
if this
should be scheduled, false
otherwise.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
public void setActive()
public void setReifiedTrue()
public void setReifiedSilent()
public void setPassive()
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 void incNbPendingEvt()
public void decNbPendingEvt()
public void flushPendingEvt()
public int arity()
public int dynPriority()
public void contradiction(Variable variable, String message) throws ContradictionException
variable
- involved variablemessage
- detailed messageContradictionException
- expected behaviorpublic int compareTo(Propagator o)
compareTo
in interface Comparable<Propagator>
public Solver getSolver()
public int getNbPendingEvt()
public final V getVar(int i)
V
objects.i
- index of the elementV
objectpublic final V[] getVars()
public int[] getVIndices()
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 duplicate(Solver solver, gnu.trove.map.hash.THashMap<Object,Object> identitymap)
solver
- the target solveridentitymap
- a map to ensure uniqueness of objectspublic boolean why(RuleStore ruleStore, IntVar var, IEventType evt, int value)
ICause
Copyright © 2015. All rights reserved.