Module org.chocosolver
Class PropMultiCostRegular
- java.lang.Object
-
- org.chocosolver.solver.constraints.Propagator<IntVar>
-
- org.chocosolver.solver.constraints.nary.automata.PropMultiCostRegular
-
- All Implemented Interfaces:
Comparable<Propagator>
,ICause
,Identity
public final class PropMultiCostRegular extends Propagator<IntVar>
Created by IntelliJ IDEA. User: julien S Date: Jul 16, 2008 Time: 5:56:50 PM Multi-Cost-Regular is a propagator for the constraint ensuring that, given : an automaton Pi; a sequence of domain variables X; a set of bound variables Z; a assignment cost matrix for each bound variable C; The word formed by the sequence of assigned variables is accepted by Pi; for each z^k in Z, sum_i(C_i(x_k)k) = z^k AC is NP hard for such a constraint. The propagation is based on a Lagrangian Relaxation approach of the underlying Resource constrained shortest/longest path problems
-
-
Field Summary
Fields Modifier and Type Field Description double
_MCR_DECIMAL_PREC
gnu.trove.map.hash.TObjectIntHashMap<IntVar>
map
Map to retrieve rapidly the index of a given variable.static int
MAXBOUNDITER
Maximum number of iteration during a bound computationstatic int
MAXNONIMPROVEITER
Maximum number of non improving iteration while computing a boundstatic double
RO
Lagrangian multiplier decreasing factorstatic double
U0
Constant coefficient of the lagrangian relaxation-
Fields inherited from class org.chocosolver.solver.constraints.Propagator
ACTIVE, constraint, DEFAULT_EXPL, model, operations, OUTPUT_DEFAULT_EXPL, priority, reactToFineEvt, state, vars
-
-
Constructor Summary
Constructors Constructor Description PropMultiCostRegular(IntVar[] variables, IntVar[] costvariables, ICostAutomaton cauto, double precision)
Constructs a multi-cost-regular propagator
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
check()
Necessary condition : checks whether the constraint is violted or notboolean
check(int[] word)
protected void
checkWorld()
void
computeSharpBounds()
Iteratively compute upper and lower bound for the underlying RCSPPprotected void
delayedGraphUpdate()
Updates the graphs w.r.t. the caught event during event-based propagationprotected void
filterDown(double realsp)
Filters w.r.t. a given lower bound.protected void
filterUp(double reallp)
Filters w.r.t. a given upper bound.void
forcePathRecomputation()
StoredDirectedMultiGraph
getGraph()
double[]
getInstantiatedLayerCosts(int layer)
int[]
getMinMaxPathCostForAssignment(int col, int val, int... resources)
int
getMinPathCost(int... resources)
int
getMinPathCostForAssignment(int col, int val, int... resources)
int
getPropagationConditions(int vIdx)
Returns the specific mask indicating the variable events on which thisPropagator
object can react.
A mask is a bitwise OR operations overIEventType
this can react on.int
getRegret(int layer, int value, int... resources)
protected void
initialize()
Build internal structure of the propagator, if necessaryESat
isEntailed()
Check wetherthis
is entailed according to the current state of its internal structure.boolean
isGraphConsistent()
boolean
isSatisfied()
boolean
needPropagation()
protected boolean
prefilter()
Performs cost based filtering w.r.t. each cost dimension.void
propagate(int evtmask)
Call the main filtering algorithm to apply to theDomain
of theVariable
objects.void
propagate(int varIdx, int mask)
Incremental filtering algorithm defined within thePropagator
, called whenever the variable of index idxVarInProp has changed.void
rebuildCostRegInfo()
protected void
updateLowerBound()
Performs a lagrangian relaxation to compute a new Lower bound of the underlying RCSPP problem Each built subproblem is a shortest path one can use to perform cost based filteringprotected void
updateUpperBound()
Performs a lagrangian relaxation to compute a new Upper bound of the underlying RCSPP problem Each built subproblem is a longest path one can use to perform cost based filtering-
Methods inherited from class org.chocosolver.solver.constraints.Propagator
addVariable, arity, compareTo, defaultExplain, doFinePropagation, doFlush, doSchedule, doScheduleEvent, dynPriority, equals, explain, fails, forcePropagate, forcePropagationOnBacktrack, forEachIntVar, getConstraint, getId, getModel, getNbVars, getPosition, getPriority, getVar, getVars, getVIndice, getVIndices, hashCode, isActive, isCompletelyInstantiated, isPassive, isReified, isReifiedAndSilent, isScheduled, isStateLess, linkVariables, reactToFineEvent, reifiedWith, setActive, setActive0, setPassive, setPosition, setReifiedSilent, setReifiedTrue, setVIndices, toString, unlinkVariables, unschedule
-
-
-
-
Field Detail
-
MAXBOUNDITER
public static final int MAXBOUNDITER
Maximum number of iteration during a bound computation- See Also:
- Constant Field Values
-
MAXNONIMPROVEITER
public static final int MAXNONIMPROVEITER
Maximum number of non improving iteration while computing a bound- See Also:
- Constant Field Values
-
U0
public static final double U0
Constant coefficient of the lagrangian relaxation- See Also:
- Constant Field Values
-
RO
public static final double RO
Lagrangian multiplier decreasing factor- See Also:
- Constant Field Values
-
map
public final gnu.trove.map.hash.TObjectIntHashMap<IntVar> map
Map to retrieve rapidly the index of a given variable.
-
_MCR_DECIMAL_PREC
public final double _MCR_DECIMAL_PREC
-
-
Constructor Detail
-
PropMultiCostRegular
public PropMultiCostRegular(IntVar[] variables, IntVar[] costvariables, ICostAutomaton cauto, double precision)
Constructs a multi-cost-regular propagator- Parameters:
variables
- decision variablescostvariables
- cost variablescauto
- finite automaton with costs
-
-
Method Detail
-
getPropagationConditions
public int getPropagationConditions(int vIdx)
Description copied from class:Propagator
Returns the specific mask indicating the variable events on which thisPropagator
object can react.
A mask is a bitwise OR operations overIEventType
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:- 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.VOID
which states that this propagator should not be aware of modifications applied to the variable in position vIdx.- Overrides:
getPropagationConditions
in classPropagator<IntVar>
- Parameters:
vIdx
- index of the variable within the propagator- Returns:
- an int composed of
REMOVE
and/orINSTANTIATE
and/orDECUPP
and/orINCLOW
-
initialize
protected void initialize() throws ContradictionException
Build internal structure of the propagator, if necessary- Throws:
ContradictionException
- if initialisation encounters a contradiction
-
propagate
public void propagate(int evtmask) throws ContradictionException
Description copied from class:Propagator
Call the main filtering algorithm to apply to theDomain
of theVariable
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:
- 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:
propagate
in classPropagator<IntVar>
- Parameters:
evtmask
- type of propagation eventthis
must consider.- Throws:
ContradictionException
- when a contradiction occurs, like domain wipe out or other incoherencies.
-
propagate
public void propagate(int varIdx, int mask) throws ContradictionException
Description copied from class:Propagator
Incremental 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
reactToFineEvt
is set totrue
in the constructor. Otherwise, it executespropagate(PropagatorEventType.CUSTOM_PROPAGATION.getStrengthenedMask());
- Overrides:
propagate
in classPropagator<IntVar>
- Parameters:
varIdx
- index of the variablevar
inthis
mask
- type of event- Throws:
ContradictionException
- if a contradiction occurs
-
updateUpperBound
protected void updateUpperBound() throws ContradictionException
Performs a lagrangian relaxation to compute a new Upper bound of the underlying RCSPP problem Each built subproblem is a longest path one can use to perform cost based filtering- Throws:
ContradictionException
- if a domain becomes empty
-
updateLowerBound
protected void updateLowerBound() throws ContradictionException
Performs a lagrangian relaxation to compute a new Lower bound of the underlying RCSPP problem Each built subproblem is a shortest path one can use to perform cost based filtering- Throws:
ContradictionException
- if a domain becomes empty
-
prefilter
protected boolean prefilter() throws ContradictionException
Performs cost based filtering w.r.t. each cost dimension.- Throws:
ContradictionException
- if a domain is emptied
-
filterDown
protected void filterDown(double realsp) throws ContradictionException
Filters w.r.t. a given lower bound.- Parameters:
realsp
- a given lower bound- Throws:
ContradictionException
- if the cost variable domain is emptied
-
filterUp
protected void filterUp(double reallp) throws ContradictionException
Filters w.r.t. a given upper bound.- Parameters:
reallp
- a given upper bound- Throws:
ContradictionException
- if the cost variable domain is emptied
-
checkWorld
protected void checkWorld() throws ContradictionException
- Throws:
ContradictionException
-
delayedGraphUpdate
protected void delayedGraphUpdate() throws ContradictionException
Updates the graphs w.r.t. the caught event during event-based propagation- Throws:
ContradictionException
- if removing an edge causes a domain to be emptied
-
computeSharpBounds
public void computeSharpBounds() throws ContradictionException
Iteratively compute upper and lower bound for the underlying RCSPP- Throws:
ContradictionException
- if a domain gets empty
-
rebuildCostRegInfo
public void rebuildCostRegInfo() throws ContradictionException
- Throws:
ContradictionException
-
needPropagation
public final boolean needPropagation()
-
isGraphConsistent
public boolean isGraphConsistent()
-
getGraph
public final StoredDirectedMultiGraph getGraph()
-
getRegret
public final int getRegret(int layer, int value, int... resources)
-
isEntailed
public ESat isEntailed()
Description copied from class:Propagator
Check wetherthis
is entailed according to the current state of its internal structure. At least, should check the satisfaction ofthis
(when all is instantiated).- Specified by:
isEntailed
in classPropagator<IntVar>
- Returns:
- ESat.TRUE if entailed, ESat.FALSE if not entailed, ESat.UNDEFINED if unknown
-
isSatisfied
public boolean isSatisfied()
-
check
public boolean check(int[] word)
-
check
public boolean check()
Necessary condition : checks whether the constraint is violted or not- Returns:
- true if the constraint is not violated
-
getMinPathCostForAssignment
public int getMinPathCostForAssignment(int col, int val, int... resources)
-
getMinMaxPathCostForAssignment
public int[] getMinMaxPathCostForAssignment(int col, int val, int... resources)
-
getMinPathCost
public int getMinPathCost(int... resources)
-
getInstantiatedLayerCosts
public double[] getInstantiatedLayerCosts(int layer)
-
forcePathRecomputation
public void forcePathRecomputation() throws ContradictionException
- Throws:
ContradictionException
-
-