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.
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 constraint i involving the variable.
 java.util.Iterator getConstraintsIterator()
          This methods should be used if one want to access the different constraints currently posted on this variable.
 PartiallyStoredVector getConstraintVector()
          Access the data structure storing constraints involving a given variable.
 VarEvent getEvent()
          Returns the variable event.
 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 its constraint i.
 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.

Parameters:
pb - The problem this variable belongs to
name - The name of the variable
Method Detail

toString

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

Overrides:
toString in class java.lang.Object
Returns:
the name of the variable

getEvent

public VarEvent getEvent()
Returns the variable event.

Specified by:
getEvent in interface Var
Returns:
the event responsible for propagating variable modifications

getConstraint

public Constraint getConstraint(int i)
Retrieve the constraint i involving the variable. Be careful to use the correct constraint index (constraints are not numbered from 0 to number of constraints minus one, since an offset is used for some of the constraints).

Specified by:
getConstraint in interface Var
Parameters:
i - the number of the required constraint
Returns:
the constraint number i according to the variable

getNbConstraints

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

Specified by:
getNbConstraints in interface Var
Returns:
the number of constraints containing this variable

getConstraintVector

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

Specified by:
getConstraintVector in interface Var
Returns:
the backtrackable structure containing the constraints

getIndexVector

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

Specified by:
getIndexVector in interface Var
Returns:
the indices associated to this variable in each constraint

getVarIndex

public int getVarIndex(int constraintIndex)
Returns the index of the variable in its constraint i.

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

eraseConstraint

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

Parameters:
c - the constraint that should be removed from the list this variable maintains.

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
Parameters:
c - the constraint to add
varIdx - the variable index accrding to the added constraint
dynamicAddition - states if the addition is definitic (cut) or subject to backtracking (standard constraint)
Returns:
the index affected to the constraint according to this variable

getConstraintsIterator

public java.util.Iterator getConstraintsIterator()
This methods should be used if one want to access the different constraints currently posted on this variable. Indeed, since indices are not always consecutive, it is the only simple way to achieve this. Warning ! this iterator should not be used to remove elements. The remove method throws an UnsupportedOperationException.

Specified by:
getConstraintsIterator in interface Var
Returns:
an iterator over all constraints involving this variable