choco
Class AbstractVar

java.lang.Object
  extended by choco.AbstractEntity
      extended by choco.AbstractVar
All Implemented Interfaces:
Entity, Var
Direct Known Subclasses:
IntDomainVarImpl, RealVarImpl, SetVarImpl

public abstract class AbstractVar
extends AbstractEntity
implements Var

An abstract class for all implementations of domain variables


Field Summary
protected  PartiallyStoredVector constraints
          The list of constraints (listeners) observing the variable.
protected  VarEvent event
          The variable var associated to this variable.
protected  PartiallyStoredIntVector indices
          List of indices encoding the constraint network: v.indices[i]=j means that v is the j-th variable of its i-th constraint.
protected  java.lang.String name
          A name may be associated to each variable
 
Fields inherited from class choco.AbstractEntity
hook, problem
 
Constructor Summary
AbstractVar(AbstractProblem pb, java.lang.String name)
          Initializes a new variable.
 
Method Summary
 int addConstraint(Constraint c, int varIdx, boolean dynamicAddition)
          Adds a new constraints on the stack of constraints the addition can be dynamic (undone upon backtracking) or not
 void eraseConstraint(Constraint c)
          removes (permanently) a constraint from the list of constraints connected to the variable
 Constraint getConstraint(int i)
          Retrieve the i-th constraint involving the variable.
 PartiallyStoredVector getConstraintVector()
          access the data structure storing constraints involving a given variable
 VarEvent getEvent()
          Returns the variable var.
 PartiallyStoredIntVector getIndexVector()
          access the data structure storing indices associated to constraints involving a given variable
 int getNbConstraints()
          Returns the number of constraints involving the variable.
 int getVarIndex(int constraintIndex)
          returns the index of the variable in it i-th constraint
 java.lang.String toString()
          useful for debugging
 
Methods inherited from class choco.AbstractEntity
getProblem, pretty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface choco.Var
fail, isInstantiated
 
Methods inherited from interface choco.Entity
getProblem, pretty
 

Field Detail

name

protected java.lang.String name
A name may be associated to each variable


event

protected VarEvent event
The variable var associated to this variable.


constraints

protected PartiallyStoredVector constraints
The list of constraints (listeners) observing the variable.


indices

protected PartiallyStoredIntVector indices
List of indices encoding the constraint network: v.indices[i]=j means that v is the j-th variable of its i-th constraint.

Constructor Detail

AbstractVar

public AbstractVar(AbstractProblem pb,
                   java.lang.String name)
Initializes a new variable.

Method Detail

toString

public java.lang.String toString()
useful for debugging

Overrides:
toString in class java.lang.Object

getEvent

public VarEvent getEvent()
Returns the variable var.

Specified by:
getEvent in interface Var
Returns:
the propagation event

getConstraint

public Constraint getConstraint(int i)
Retrieve the i-th constraint involving the variable.

Specified by:
getConstraint in interface Var

getNbConstraints

public int getNbConstraints()
Returns the number of constraints involving the variable.

Specified by:
getNbConstraints in interface Var

getConstraintVector

public PartiallyStoredVector getConstraintVector()
access the data structure storing constraints involving a given variable

Specified by:
getConstraintVector in interface Var
Returns:

getIndexVector

public PartiallyStoredIntVector getIndexVector()
access the data structure storing indices associated to constraints involving a given variable

Specified by:
getIndexVector in interface Var
Returns:

getVarIndex

public int getVarIndex(int constraintIndex)
returns the index of the variable in it i-th constraint

Specified by:
getVarIndex in interface Var
Parameters:
constraintIndex - the index of the constraint (among all constraints linked to the variable)
Returns:
the index of the variable (0 if this is the first variable of that constraint)

eraseConstraint

public void eraseConstraint(Constraint c)
removes (permanently) a constraint from the list of constraints connected to the variable


addConstraint

public int addConstraint(Constraint c,
                         int varIdx,
                         boolean dynamicAddition)
Adds a new constraints on the stack of constraints the addition can be dynamic (undone upon backtracking) or not

Specified by:
addConstraint in interface Var