choco.bool
Class AbstractBinCompositeConstraint

java.lang.Object
  extended by choco.AbstractEntity
      extended by choco.AbstractConstraint
          extended by choco.bool.AbstractCompositeConstraint
              extended by choco.bool.AbstractBinCompositeConstraint
All Implemented Interfaces:
CompositeConstraint, Constraint, Entity, IntVarEventListener, VarEventListener, Propagator, java.lang.Cloneable, java.util.EventListener
Direct Known Subclasses:
AbstractBinBoolConstraint

public abstract class AbstractBinCompositeConstraint
extends AbstractCompositeConstraint

Abstract implementation of a composite constraint (like boolean ones) involving two sub-constraints.


Field Summary
protected  AbstractConstraint const0
          The first sub-constraint of the composition.
protected  AbstractConstraint const1
          The second sub-constraint of the composition.
protected  int offset
          The number of variables in the first sub-constraint.
 
Fields inherited from class choco.AbstractConstraint
active, constAwakeEvent, hook, priority
 
Fields inherited from class choco.AbstractEntity
problem
 
Constructor Summary
AbstractBinCompositeConstraint(AbstractConstraint c1, AbstractConstraint c2)
          Builds a new binary composite constraint with the two specified sub-constraints.
 
Method Summary
 int assignIndices(AbstractCompositeConstraint root, int i, boolean dynamicAddition)
          Assigns indices to variables for the global constraint involving this one.
 java.lang.Object clone()
          Builds a copy of this constraint.
 int getConstraintIdx(int i)
          Returns the constraint index according to the variable i.
 IntDomainVar getIntVar(int varIdx)
          Network management: Accessing the i-th search variable of a constraint.
 int getNbSubConstraints()
          Returns the number of direct sub-constraints (2 here since this is a binary composite constraint).
 int getNbVars()
          Determines the number of variables, that is the sum of all variables in sub-constraints.
 Constraint getSubConstraint(int constIdx)
          Accesses the sub-constraints.
 int getSubConstraintIdx(int varIdx)
          Returns the index of the sub-constraint involving the variable varIdx.
 Var getVar(int i)
          Accesses the variable i.
 int getVarIdxInOpposite(int i)
          Returns the variable indx in the opposite constraint.
 boolean isCompletelyInstantiated()
          Checks if all variables are instantiated, that if sub-constraints variables are instantiated.
 void setConstraintIndex(int i, int idx)
          Sets the constraint index according to the variable i.
 void setVar(int i, Var v)
          Sets the variable i.
 
Methods inherited from class choco.bool.AbstractCompositeConstraint
addListener, awakeOnBounds, awakeOnRemovals, getGlobalVarIndex
 
Methods inherited from class choco.AbstractConstraint
awake, awakeOnVar, connectVar, constAwake, delete, fail, getEvent, getPlugIn, getPriority, getProblem, isActive, isEntailed, isEquivalentTo, opposite, setActive, setEntailed, setPassive, setPlugIn, substituteVar
 
Methods inherited from class choco.AbstractEntity
pretty
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface choco.Constraint
isEquivalentTo, isSatisfied, opposite
 
Methods inherited from interface choco.Entity
getProblem, pretty
 
Methods inherited from interface choco.integer.var.IntVarEventListener
awakeOnInf, awakeOnInst, awakeOnRem, awakeOnSup
 
Methods inherited from interface choco.prop.VarEventListener
awakeOnVar, isActive, setActive, setPassive
 
Methods inherited from interface choco.Propagator
isConsistent, propagate
 

Field Detail

const0

protected AbstractConstraint const0
The first sub-constraint of the composition.


const1

protected AbstractConstraint const1
The second sub-constraint of the composition.


offset

protected int offset
The number of variables in the first sub-constraint. Therefore the offset in the numbering of the variables from the second sub-constraint.

Constructor Detail

AbstractBinCompositeConstraint

public AbstractBinCompositeConstraint(AbstractConstraint c1,
                                      AbstractConstraint c2)
Builds a new binary composite constraint with the two specified sub-constraints.

Parameters:
c1 - the first sub-constraint
c2 - the second sub-constraint
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Builds a copy of this constraint.

Specified by:
clone in interface Constraint
Overrides:
clone in class AbstractConstraint
Returns:
a copy of this constraint
Throws:
java.lang.CloneNotSupportedException - if an problem occurs when cloning elements pf this constraint

assignIndices

public int assignIndices(AbstractCompositeConstraint root,
                         int i,
                         boolean dynamicAddition)
Assigns indices to variables for the global constraint involving this one.

Parameters:
root - the global constraint including this one
i - the first available index
dynamicAddition - states if the constraint is added definitively
Returns:
the next available index for the global constraint

getIntVar

public IntDomainVar getIntVar(int varIdx)
Network management: Accessing the i-th search variable of a constraint.

Parameters:
varIdx - index of the variable among all search variables in the constraint. Numbering start from 0 on.
Returns:
the variable, or null when no such variable is found

getSubConstraintIdx

public int getSubConstraintIdx(int varIdx)
Returns the index of the sub-constraint involving the variable varIdx.

Parameters:
varIdx - the variable index
Returns:
0 if this is the first sub-constraint, 1 else

getVarIdxInOpposite

public int getVarIdxInOpposite(int i)
Returns the variable indx in the opposite constraint.

Specified by:
getVarIdxInOpposite in interface Constraint
Overrides:
getVarIdxInOpposite in class AbstractConstraint
Parameters:
i - the variable index
Returns:
the index in the opposite constraint

getNbVars

public int getNbVars()
Determines the number of variables, that is the sum of all variables in sub-constraints.

Returns:
the number of variables

getVar

public Var getVar(int i)
Accesses the variable i.

Parameters:
i - the index of the variable
Returns:
the requested variable

setVar

public void setVar(int i,
                   Var v)
Sets the variable i.

Parameters:
i - the variable index
v - the variable

isCompletelyInstantiated

public boolean isCompletelyInstantiated()
Checks if all variables are instantiated, that if sub-constraints variables are instantiated.

Returns:
true if all variables are instantiated

getConstraintIdx

public int getConstraintIdx(int i)
Returns the constraint index according to the variable i.

Parameters:
i - the variable index
Returns:
this constraint index according to the variable

setConstraintIndex

public void setConstraintIndex(int i,
                               int idx)
Sets the constraint index according to the variable i.

Parameters:
i - the variable index
idx - the requested constraint index

getSubConstraint

public Constraint getSubConstraint(int constIdx)
Accesses the sub-constraints.

Parameters:
constIdx - the constraint index (0 or 1 here)
Returns:
the requested constraint

getNbSubConstraints

public int getNbSubConstraints()
Returns the number of direct sub-constraints (2 here since this is a binary composite constraint).

Returns:
the number of direct sub-constraints