choco.cp.solver.constraints.global.automata.fast_multicostregular
Class MultiCostRegular

java.lang.Object
  extended by choco.kernel.solver.propagation.Propagator
      extended by choco.kernel.solver.constraints.AbstractSConstraint<IntDomainVar>
          extended by choco.kernel.solver.constraints.integer.AbstractIntSConstraint
              extended by choco.kernel.solver.constraints.integer.AbstractLargeIntSConstraint
                  extended by choco.cp.solver.constraints.global.automata.fast_multicostregular.MultiCostRegular
All Implemented Interfaces:
IExtensionnable, IPretty, SConstraint<IntDomainVar>, IntPropagator, Cloneable, EventListener

public final class MultiCostRegular
extends AbstractLargeIntSConstraint

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
protected  StoredDirectedMultiGraph graph
          Layered graph of the unfolded automaton
 int[] lastLp
          The last computed Longest Path
 double lastLpValue
           
 int lastNbOfBacktracks
           
 int lastNbOfRestarts
           
 int[] lastSp
          The last computed Shortest Path
 double lastSpValue
           
 int lastWorld
           
 gnu.trove.TObjectIntHashMap<IntDomainVar> map
          Map to retrieve rapidly the index of a given variable.
static int MAXBOUNDITER
          Maximum number of iteration during a bound computation
static int MAXNONIMPROVEITER
          Maximum number of non improving iteration while computing a bound
protected  boolean[] modifiedBound
          Boolean array which record whether a bound has been modified by the propagator
protected  int nbR
          Store the number of resources = z.length
protected  ICostAutomaton pi
          The finite automaton which defines the regular language the variable sequence must belong
protected  gnu.trove.TIntHashSet removed
          Buffer to check whether an arc needs to be removed.
static double RO
          Lagrangian multiplier decreasing factor
protected  FastPathFinder slp
          Instance of the class containing all path finding algorithms Also contains graph filtering algorithms
protected  gnu.trove.TIntStack toRemove
          Stack to store removed edges index, for delayed update
protected  gnu.trove.TIntStack[] toUpdateLeft
           
protected  gnu.trove.TIntStack[] toUpdateRight
           
static double U0
          Constant coefficient of the lagrangian relaxation
protected  double[] uLb
          Lagrangian multiplier container to compute a LB
protected  double[] uUb
          Lagrangian multiplier container to compute an UB
protected  IntDomainVar[] vs
          Decision variables
 IntDomainVar[] z
          Cost variables
 
Fields inherited from class choco.kernel.solver.constraints.AbstractSConstraint
cIndices, constraintType, extensions, vars
 
Fields inherited from class choco.kernel.solver.propagation.Propagator
active, constAwakeEvent, priority, propagationEngine
 
Fields inherited from interface choco.kernel.solver.constraints.SConstraint
LOGGER
 
Constructor Summary
MultiCostRegular(IntDomainVar[] vars, IntDomainVar[] CR, IAutomaton auto, int[][][][] costs, Solver solver)
          Constructs a multi-cost-regular constraint propagator
MultiCostRegular(IntDomainVar[] vars, IntDomainVar[] CR, IAutomaton auto, int[][][] costs, Solver solver)
          Constructs a multi-cost-regular constraint propagator
MultiCostRegular(IntDomainVar[] vars, IntDomainVar[] CR, ICostAutomaton pi, Solver solver)
           
 
Method Summary
 void awake()
          Propagation: Propagating the constraint for the very first time until local consistency is reached.
 void awakeOnInf(int idx)
          Default propagation on improved lower bound: propagation on domain revision.
 void awakeOnInst(int idx)
          Default propagation on instantiation: full constraint re-propagation.
 void awakeOnRem(int idx, int val)
          Default propagation on one value removal: propagation on domain revision.
 void awakeOnSup(int idx)
          Default propagation on improved upper bound: propagation on domain revision.
 void boundChange(int idx)
           
 boolean check()
          Necessary condition : checks whether the constraint is violted or not
 boolean check(int[] word)
           
protected  void checkWorld()
           
 void computeSharpBounds()
          Iteratively compute upper and lower bound for the underlying RCSPP
protected  void delayedGraphUpdate()
          Updates the graphs w.r.t. the caught event during event-based propagation
protected  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()
           
 int getFilteredEventMask(int idx)
           
 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 getRegret(int layer, int value, int... resources)
           
 void initGraph()
           
 boolean isGraphConsistent()
           
 boolean isSatisfied()
          Default implementation of the isSatisfied by delegating to the isSatisfied(int[] tuple)
 boolean isSatisfied(int[] word)
          TEMPORARY: if not overriden by the constraint, throws an error to avoid bug using reified constraints in constraints that have not been changed to fulfill this api yet !
 boolean needPropagation()
           
protected  boolean prefilter()
          Performs cost based filtering w.r.t. each cost dimension.
 void propagate()
          Propagation: Propagating the constraint until local consistency is reached.
 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 filtering
protected  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 choco.kernel.solver.constraints.integer.AbstractIntSConstraint
awakeOnBounds, awakeOnRemovals, getConstraintType, isConsistent
 
Methods inherited from class choco.kernel.solver.constraints.AbstractSConstraint
addExtension, addListener, clone, getAbstractSConstraintExtensionNumber, getConstraintIdx, getExtension, getFineDegree, getNbVarNotInst, getNbVars, getVar, getVarQuick, isCompletelyInstantiated, isEntailed, opposite, pretty, setConstraintIndex, setExtension, setVar, toString
 
Methods inherited from class choco.kernel.solver.propagation.Propagator
activate, constAwake, fail, getEvent, getPriority, isActive, setActive, setActiveSilently, setEntailed, setPassive, setPropagationEngine
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAXBOUNDITER

public static int MAXBOUNDITER
Maximum number of iteration during a bound computation


MAXNONIMPROVEITER

public static int MAXNONIMPROVEITER
Maximum number of non improving iteration while computing a bound


U0

public static double U0
Constant coefficient of the lagrangian relaxation


RO

public static double RO
Lagrangian multiplier decreasing factor


map

public final gnu.trove.TObjectIntHashMap<IntDomainVar> map
Map to retrieve rapidly the index of a given variable.


lastSp

public int[] lastSp
The last computed Shortest Path


lastSpValue

public double lastSpValue

lastLp

public int[] lastLp
The last computed Longest Path


lastLpValue

public double lastLpValue

vs

protected final IntDomainVar[] vs
Decision variables


z

public final IntDomainVar[] z
Cost variables


pi

protected ICostAutomaton pi
The finite automaton which defines the regular language the variable sequence must belong


graph

protected StoredDirectedMultiGraph graph
Layered graph of the unfolded automaton


modifiedBound

protected final boolean[] modifiedBound
Boolean array which record whether a bound has been modified by the propagator


uUb

protected final double[] uUb
Lagrangian multiplier container to compute an UB


uLb

protected final double[] uLb
Lagrangian multiplier container to compute a LB


slp

protected FastPathFinder slp
Instance of the class containing all path finding algorithms Also contains graph filtering algorithms


nbR

protected final int nbR
Store the number of resources = z.length


toRemove

protected final gnu.trove.TIntStack toRemove
Stack to store removed edges index, for delayed update


toUpdateLeft

protected final gnu.trove.TIntStack[] toUpdateLeft

toUpdateRight

protected final gnu.trove.TIntStack[] toUpdateRight

removed

protected final gnu.trove.TIntHashSet removed
Buffer to check whether an arc needs to be removed.


lastWorld

public int lastWorld

lastNbOfBacktracks

public int lastNbOfBacktracks

lastNbOfRestarts

public int lastNbOfRestarts
Constructor Detail

MultiCostRegular

public MultiCostRegular(IntDomainVar[] vars,
                        IntDomainVar[] CR,
                        IAutomaton auto,
                        int[][][] costs,
                        Solver solver)
Constructs a multi-cost-regular constraint propagator

Parameters:
vars - decision variables
CR - cost variables
auto - finite automaton
costs - assignment cost arrays
solver - solver

MultiCostRegular

public MultiCostRegular(IntDomainVar[] vars,
                        IntDomainVar[] CR,
                        IAutomaton auto,
                        int[][][][] costs,
                        Solver solver)
Constructs a multi-cost-regular constraint propagator

Parameters:
vars - decision variables
CR - cost variables
auto - finite automaton
costs - assignment cost arrays
solver - solver

MultiCostRegular

public MultiCostRegular(IntDomainVar[] vars,
                        IntDomainVar[] CR,
                        ICostAutomaton pi,
                        Solver solver)
Method Detail

initGraph

public void initGraph()

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

awakeOnRem

public void awakeOnRem(int idx,
                       int val)
                throws ContradictionException
Description copied from class: AbstractIntSConstraint
Default propagation on one value removal: propagation on domain revision.

Specified by:
awakeOnRem in interface IntPropagator
Overrides:
awakeOnRem in class AbstractIntSConstraint
Throws:
ContradictionException

awakeOnInst

public final void awakeOnInst(int idx)
Description copied from class: AbstractIntSConstraint
Default propagation on instantiation: full constraint re-propagation.

Specified by:
awakeOnInst in interface IntPropagator
Overrides:
awakeOnInst in class AbstractIntSConstraint

awakeOnSup

public final void awakeOnSup(int idx)
Description copied from class: AbstractIntSConstraint
Default propagation on improved upper bound: propagation on domain revision.

Specified by:
awakeOnSup in interface IntPropagator
Overrides:
awakeOnSup in class AbstractIntSConstraint

awakeOnInf

public final void awakeOnInf(int idx)
Description copied from class: AbstractIntSConstraint
Default propagation on improved lower bound: propagation on domain revision.

Specified by:
awakeOnInf in interface IntPropagator
Overrides:
awakeOnInf in class AbstractIntSConstraint

boundChange

public void boundChange(int idx)

awake

public void awake()
           throws ContradictionException
Description copied from class: Propagator
Propagation: Propagating the constraint for the very first time until local consistency is reached.

Overrides:
awake in class Propagator
Throws:
ContradictionException - contradiction exception

propagate

public void propagate()
               throws ContradictionException
Description copied from class: Propagator
Propagation: Propagating the constraint until local consistency is reached.

Specified by:
propagate in class Propagator
Throws:
ContradictionException - contradiction exception

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)

isSatisfied

public boolean isSatisfied()
Description copied from class: AbstractIntSConstraint
Default implementation of the isSatisfied by delegating to the isSatisfied(int[] tuple)

Specified by:
isSatisfied in interface SConstraint<IntDomainVar>
Overrides:
isSatisfied in class AbstractIntSConstraint
Returns:
true if the constraint is satisfied

isSatisfied

public boolean isSatisfied(int[] word)
Description copied from class: AbstractIntSConstraint
TEMPORARY: if not overriden by the constraint, throws an error to avoid bug using reified constraints in constraints that have not been changed to fulfill this api yet !

Specified by:
isSatisfied in interface IntPropagator
Overrides:
isSatisfied in class AbstractIntSConstraint

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

getFilteredEventMask

public int getFilteredEventMask(int idx)
Overrides:
getFilteredEventMask in class Propagator

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


Copyright © 2012. All Rights Reserved.