choco.integer.constraints
Class IntLinComb

java.lang.Object
  extended by choco.AbstractEntity
      extended by choco.AbstractConstraint
          extended by choco.integer.constraints.AbstractIntConstraint
              extended by choco.integer.constraints.AbstractLargeIntConstraint
                  extended by choco.integer.constraints.IntLinComb
All Implemented Interfaces:
Constraint, Entity, IntConstraint, IntVarEventListener, VarEventListener, Propagator, java.lang.Cloneable, java.util.EventListener
Direct Known Subclasses:
PalmIntLinComb

public class IntLinComb
extends AbstractLargeIntConstraint

Implements a constraint Sigma (ai Xi) <=/>=/= C, with Xi variables, ai and C search constants.


Field Summary
protected  int[] coeffs
          Field representing the type of linear constraint (equality, inequality, disequality)
protected  int cste
          The search constant of the constraint
static int EQ
          Constant, to be assigned to op, representing linear equalities
static int GEQ
          Constant, to be assigned to op, representing linear inequalities
protected  int nbPosVars
          Field representing the number of variables with positive coeffficients in the linear combination (all positive coefficients are given before negative ones)
static int NEQ
          Constant, to be assigned to op, representing linear disequalities
protected  int op
          Field representing the type of linear constraint (equality, inequality, disequality)
 
Fields inherited from class choco.integer.constraints.AbstractLargeIntConstraint
cIndices, vars
 
Fields inherited from class choco.integer.constraints.AbstractIntConstraint
logger
 
Fields inherited from class choco.AbstractConstraint
active, constAwakeEvent, hook, priority
 
Fields inherited from class choco.AbstractEntity
problem
 
Constructor Summary
IntLinComb(IntDomainVar[] lvars, int[] lcoeffs, int nbPositive, int c, int linOperator)
          Constructs the constraint with the specified variables and constant.
 
Method Summary
 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 x)
          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 awakeOnVar(int idx)
          Default propagation on variable revision: full constraint re-propagation.
 java.lang.Object clone()
          returns a copy of the constraint.
protected  int computeLowerBound()
          computes a lower bound estimate of a linear combination of variables
protected  int computeUpperBound()
          computes an upper bound estimate of a linear combination of variables
protected  void filter(boolean startWithLB, int minNbRules)
          a strategy for chaotic iteration with two rules (LB and UB propagation) the fix point is reached individually for each rule in one function call but this call may break the stability condition for the other rule (in which case the second rule infers new information from the fresh inferences made by the first rule).
protected  boolean filterOnImprovedLowerBound()
           
protected  boolean filterOnImprovedUpperBound()
           
protected  boolean hasConsistentLowerBound()
          tests if the constraint is consistent with respect to the current state of domains
protected  boolean hasConsistentUpperBound()
           
 void init(int[] lcoeffs)
           
 boolean isConsistent()
          tests if the constraint is consistent with respect to the current state of domains
 java.lang.Boolean isEntailed()
          Checks whether the constraint is definitely satisfied, no matter what further restrictions occur to the domain of its variables.
 boolean isEquivalentTo(Constraint compareTo)
          tests the equivalence (logical equality of the conditions) between two constraints.
 boolean isSatisfied()
          Semantic: Testing if the constraint is satisfied.
 AbstractConstraint opposite()
          computes the constraint modelling the counter-opposite condition of this
 java.lang.String pretty()
          pretty printing of the object.
 void propagate()
          Propagates the constraint awake events.
protected  boolean propagateNewLowerBound(int mylb)
          propagates the constraint sigma(ai Xi) + c <= 0 where mylb = sigma(ai inf(Xi)) + c note: this does not reach saturation (fix point), but returns a boolean indicating whether it infered new information or not.
protected  boolean propagateNewUpperBound(int myub)
          propagates the constraint sigma(ai Xi) + c <= 0 where myub = sigma(ai sup(Xi)) + c note: this does not reach saturation (fix point), but returns a boolean indicating whether it infered new information or not.
 
Methods inherited from class choco.integer.constraints.AbstractLargeIntConstraint
assignIndices, getConstraintIdx, getIntVar, getNbVars, getVar, isCompletelyInstantiated, setConstraintIndex, setVar
 
Methods inherited from class choco.integer.constraints.AbstractIntConstraint
awakeOnBounds, awakeOnRemovals, getSelfIndex
 
Methods inherited from class choco.AbstractConstraint
addListener, awake, connectVar, constAwake, delete, fail, getEvent, getPlugIn, getPriority, getProblem, getVarIdxInOpposite, isActive, setActive, setEntailed, setPassive, setPlugIn, substituteVar
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface choco.Propagator
awake, constAwake, delete, getEvent, getPlugIn, getPriority
 
Methods inherited from interface choco.prop.VarEventListener
addListener, isActive, setActive, setPassive
 
Methods inherited from interface choco.prop.VarEventListener
addListener, isActive, setActive, setPassive
 

Field Detail

EQ

public static final int EQ
Constant, to be assigned to op, representing linear equalities

See Also:
Constant Field Values

GEQ

public static final int GEQ
Constant, to be assigned to op, representing linear inequalities

See Also:
Constant Field Values

NEQ

public static final int NEQ
Constant, to be assigned to op, representing linear disequalities

See Also:
Constant Field Values

op

protected final int op
Field representing the type of linear constraint (equality, inequality, disequality)


coeffs

protected int[] coeffs
Field representing the type of linear constraint (equality, inequality, disequality)


nbPosVars

protected final int nbPosVars
Field representing the number of variables with positive coeffficients in the linear combination (all positive coefficients are given before negative ones)


cste

protected final int cste
The search constant of the constraint

Constructor Detail

IntLinComb

public IntLinComb(IntDomainVar[] lvars,
                  int[] lcoeffs,
                  int nbPositive,
                  int c,
                  int linOperator)
Constructs the constraint with the specified variables and constant. Use the Problem.createIntLinComb API instead of this constructor. This constructor assumes that there are no null coefficient and that the positive coefficients come before the negative ones.

Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Description copied from interface: Constraint
returns a copy of the constraint. This copy is a new object, may be a recursive copy in case of composite constraints. The original and the copy share the same variables & plugins

Specified by:
clone in interface Constraint
Overrides:
clone in class AbstractLargeIntConstraint
Returns:
Throws:
java.lang.CloneNotSupportedException

init

public void init(int[] lcoeffs)

propagate

public void propagate()
               throws ContradictionException
Description copied from class: AbstractLargeIntConstraint
Propagates the constraint awake events.

Specified by:
propagate in interface Propagator
Overrides:
propagate in class AbstractLargeIntConstraint
Throws:
ContradictionException

awakeOnVar

public void awakeOnVar(int idx)
                throws ContradictionException
Description copied from class: AbstractConstraint
Default propagation on variable revision: full constraint re-propagation.

Specified by:
awakeOnVar in interface VarEventListener
Specified by:
awakeOnVar in interface Propagator
Overrides:
awakeOnVar in class AbstractConstraint
Throws:
ContradictionException

awakeOnInf

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

Specified by:
awakeOnInf in interface IntVarEventListener
Overrides:
awakeOnInf in class AbstractIntConstraint
Throws:
ContradictionException

awakeOnSup

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

Specified by:
awakeOnSup in interface IntVarEventListener
Overrides:
awakeOnSup in class AbstractIntConstraint
Throws:
ContradictionException

awakeOnInst

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

Specified by:
awakeOnInst in interface IntVarEventListener
Overrides:
awakeOnInst in class AbstractIntConstraint
Throws:
ContradictionException

awakeOnRem

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

Specified by:
awakeOnRem in interface IntVarEventListener
Overrides:
awakeOnRem in class AbstractIntConstraint
Throws:
ContradictionException

isEntailed

public java.lang.Boolean isEntailed()
Description copied from interface: Propagator
Checks whether the constraint is definitely satisfied, no matter what further restrictions occur to the domain of its variables.

Specified by:
isEntailed in interface Propagator
Overrides:
isEntailed in class AbstractConstraint

isSatisfied

public boolean isSatisfied()
Description copied from interface: Constraint
Semantic: Testing if the constraint is satisfied. Note that all variables involved in the constraint must be instantiated when this method is called.


computeUpperBound

protected int computeUpperBound()
computes an upper bound estimate of a linear combination of variables


computeLowerBound

protected int computeLowerBound()
computes a lower bound estimate of a linear combination of variables


filter

protected void filter(boolean startWithLB,
                      int minNbRules)
               throws ContradictionException
a strategy for chaotic iteration with two rules (LB and UB propagation) the fix point is reached individually for each rule in one function call but this call may break the stability condition for the other rule (in which case the second rule infers new information from the fresh inferences made by the first rule). The algorithm oscilates between both rules until a global fix point is reached.

Parameters:
startWithLB - whether LB must be the first rule applied
minNbRules - minimum number of rules required to reach fiux point.
Throws:
ContradictionException

filterOnImprovedLowerBound

protected boolean filterOnImprovedLowerBound()
                                      throws ContradictionException
Throws:
ContradictionException

filterOnImprovedUpperBound

protected boolean filterOnImprovedUpperBound()
                                      throws ContradictionException
Throws:
ContradictionException

propagateNewLowerBound

protected boolean propagateNewLowerBound(int mylb)
                                  throws ContradictionException
propagates the constraint sigma(ai Xi) + c <= 0 where mylb = sigma(ai inf(Xi)) + c note: this does not reach saturation (fix point), but returns a boolean indicating whether it infered new information or not.

Throws:
ContradictionException

propagateNewUpperBound

protected boolean propagateNewUpperBound(int myub)
                                  throws ContradictionException
propagates the constraint sigma(ai Xi) + c <= 0 where myub = sigma(ai sup(Xi)) + c note: this does not reach saturation (fix point), but returns a boolean indicating whether it infered new information or not.

Throws:
ContradictionException

isConsistent

public boolean isConsistent()
tests if the constraint is consistent with respect to the current state of domains

Specified by:
isConsistent in interface Propagator
Overrides:
isConsistent in class AbstractIntConstraint
Returns:
true iff the constraint is bound consistent (weaker than arc consistent)

hasConsistentLowerBound

protected boolean hasConsistentLowerBound()
tests if the constraint is consistent with respect to the current state of domains

Returns:
true iff the constraint is bound consistent (weaker than arc consistent)

hasConsistentUpperBound

protected boolean hasConsistentUpperBound()

opposite

public AbstractConstraint opposite()
Description copied from interface: Constraint
computes the constraint modelling the counter-opposite condition of this

Specified by:
opposite in interface Constraint
Overrides:
opposite in class AbstractConstraint
Returns:
a new constraint (modelling the opposite condition)

isEquivalentTo

public boolean isEquivalentTo(Constraint compareTo)
Description copied from interface: Constraint
tests the equivalence (logical equality of the conditions) between two constraints. In particular whenever c1.equals(c2), then c1.isEquivalent(c2).

Specified by:
isEquivalentTo in interface Constraint
Overrides:
isEquivalentTo in class AbstractConstraint
Parameters:
compareTo - the constraint to be compared to
Returns:
true if and only if the constraints model the same logical condition.

pretty

public java.lang.String pretty()
Description copied from interface: Entity
pretty printing of the object. This String is not constant and may depend on the context.

Specified by:
pretty in interface Entity
Overrides:
pretty in class AbstractEntity
Returns:
a readable string representation of the object