choco.cp.solver.constraints.global
Class LexChain

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.LexChain
All Implemented Interfaces:
IExtensionnable, IPretty, SConstraint<IntDomainVar>, IntPropagator, Cloneable, EventListener

public final class LexChain
extends AbstractLargeIntSConstraint

Created by IntelliJ IDEA. User: Ashish Date: Jun 23, 2008 Time: 9:12:41 AM Solver constraint of the LexChain constraint. Allows to sort lexical chain with strict lexicographic ordering or not.


Field Summary
 int[][] lowerBoundVector
          array for holding lexicographically smallest feasible lower bound of each vector
 int n
          the number of variables in each vector of the chain - v1 <= lexChainEq/lexChain <= v2 .....
 int numOfVectors
          total number of vector in the lex chain constraint
 boolean strict
          If strict's value is true then lexChain is implemented , if false lexChainEq
 int[][] upperBoundVector
          array for holding lexicographically largest feasible upper bound of each vector
 IntDomainVar[][] x
          array of vectors in the lex chain constraint
 
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
LexChain(IntDomainVar[] vars, int n, boolean strict)
          Constructor for the lex_chain constraint
 
Method Summary
 void awake()
          Propagation: Propagating the constraint for the very first time until local consistency is reached.
 void awakeOnInst(int idx)
          Default propagation on instantiation: full constraint re-propagation.
 void boundsLex(int[] a, IntDomainVar[] x, int[] b, int j)
          Filtering algorithm for between(a,x,b) Ensures that x is lexicographically greater than a and less than b if strict is false otherwise x is lexicographically greater than or equal to a and less than or equal to b
 int computeAlpha(IntDomainVar[] x, int[] b)
          computes alpha for use in computing lexicographically largest feasible upper bound of x in computUB
 int computeBeta(IntDomainVar[] x, int[] a)
          computes beta for use in computing lexicographically smallest feasible lower bound of x in computeLB
 void computeLB(IntDomainVar[] x, int[] a, int[] lower)
          Computes the lexicographically smallest feasible lower bound vector of integers of x .
 void computeUB(IntDomainVar[] x, int[] b, int[] u)
          Computes the lexicographically largest feasible upper bound vector of integers of x .
 void filter()
          Implements the main filtering algorithm by calling boundsLex for each vector in the chain.
 int getFilteredEventMask(int idx)
           
 Boolean isEntailed()
          Indicates if the constraint is entailed, from now on will be always satisfied
 boolean isSatisfied(int[] tuple)
          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 !
 String pretty()
          Method for printing the constraint in a readable form
 void propagate()
          Propagation: Propagating the constraint until local consistency is reached.
 
Methods inherited from class choco.kernel.solver.constraints.integer.AbstractIntSConstraint
awakeOnBounds, awakeOnInf, awakeOnRem, awakeOnRemovals, awakeOnSup, getConstraintType, isConsistent, isSatisfied
 
Methods inherited from class choco.kernel.solver.constraints.AbstractSConstraint
addExtension, addListener, clone, getAbstractSConstraintExtensionNumber, getConstraintIdx, getExtension, getFineDegree, getNbVarNotInst, getNbVars, getVar, getVarQuick, isCompletelyInstantiated, opposite, 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

n

public int n
the number of variables in each vector of the chain - v1 <= lexChainEq/lexChain <= v2 .....


x

public IntDomainVar[][] x
array of vectors in the lex chain constraint


upperBoundVector

public int[][] upperBoundVector
array for holding lexicographically largest feasible upper bound of each vector


lowerBoundVector

public int[][] lowerBoundVector
array for holding lexicographically smallest feasible lower bound of each vector


strict

public boolean strict
If strict's value is true then lexChain is implemented , if false lexChainEq


numOfVectors

public int numOfVectors
total number of vector in the lex chain constraint

Constructor Detail

LexChain

public LexChain(IntDomainVar[] vars,
                int n,
                boolean strict)
Constructor for the lex_chain constraint

Parameters:
vars - an array containing all the variables in all the vectors of variables in the chain of vectors
n - the number of variables in each vector of the chain - v1 <= lexChainEq/lexChain <= v2 .....
strict - whether strict lexicographic ordering or not .True value means lexChain { < } else lexChainEq { <= }
Method Detail

getFilteredEventMask

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

boundsLex

public void boundsLex(int[] a,
                      IntDomainVar[] x,
                      int[] b,
                      int j)
               throws ContradictionException
Filtering algorithm for between(a,x,b) Ensures that x is lexicographically greater than a and less than b if strict is false otherwise x is lexicographically greater than or equal to a and less than or equal to b

Parameters:
a - lexicographically smallest feasible lower bound
x - the vector of variables among other vectors in the chain of vectors
b - lexicographically largest feasible upper bound
j - index of the vector x in the chain
Throws:
ContradictionException

computeAlpha

public int computeAlpha(IntDomainVar[] x,
                        int[] b)
                 throws ContradictionException
computes alpha for use in computing lexicographically largest feasible upper bound of x in computUB

Parameters:
x - the vector of variables whose lexicographically largest feasible upper bound is to be computed
b - the vector of integers claimed to be the feasible upper bound
Returns:
an integer greater than or equal to -1 which is used in the computation of lexicographically smallest feasible upper bound vector of integers of x
Throws:
ContradictionException

computeBeta

public int computeBeta(IntDomainVar[] x,
                       int[] a)
                throws ContradictionException
computes beta for use in computing lexicographically smallest feasible lower bound of x in computeLB

Parameters:
x - the vector of variables whose lexicographically smallest feasible lower bound is to be computed
a - the vector of integers claimed to be the feasible lower bound
Returns:
an integer greater than or equal to -1 which is used in the computation of lexicographically smallest feasible upper bound vector of integers of x
Throws:
ContradictionException

computeUB

public void computeUB(IntDomainVar[] x,
                      int[] b,
                      int[] u)
               throws ContradictionException
Computes the lexicographically largest feasible upper bound vector of integers of x . if aplha computed in computeAlpha is -1 then the current domain values can't satisfy the constraint .So the current intantiations if any are dropped and fresh search is continued.

Parameters:
x - the vector of variables whose lexicographically largest feasible upper bound is to be computed
b - the vector of integers claimed to be the feasible upper bound
u - lexicographically largest feasible upper bound of x
Throws:
ContradictionException

computeLB

public void computeLB(IntDomainVar[] x,
                      int[] a,
                      int[] lower)
               throws ContradictionException
Computes the lexicographically smallest feasible lower bound vector of integers of x . if beta computed in computeBeta is -1 then the current domain values can't satisfy the constraint .So the current intantiations if any are dropped and fresh search is continued.

Parameters:
x - the vector of variables whose lexicographically smallest feasible lower bound is to be computed
a - the vector of integers claimed to be the feasible lower bound
lower - lexicographically smallest feasible lower bound of x
Throws:
ContradictionException

filter

public void filter()
            throws ContradictionException
Implements the main filtering algorithm by calling boundsLex for each vector in the chain. If there is no variable aliasing then the fixed-point is reached in one run.

Throws:
ContradictionException

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

isEntailed

public Boolean isEntailed()
Description copied from class: AbstractSConstraint
Indicates if the constraint is entailed, from now on will be always satisfied

Overrides:
isEntailed in class AbstractSConstraint<IntDomainVar>
Returns:
wether the constraint is entailed

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

awakeOnInst

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

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

isSatisfied

public boolean isSatisfied(int[] tuple)
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

pretty

public String pretty()
Method for printing the constraint in a readable form

Specified by:
pretty in interface IPretty
Overrides:
pretty in class AbstractSConstraint<IntDomainVar>
Returns:
a readable representation of the constraint as a String


Copyright © 2012. All Rights Reserved.