choco.kernel.solver.variables
Class AbstractVar

java.lang.Object
  extended by choco.kernel.solver.variables.AbstractVar
All Implemented Interfaces:
IExtensionnable, IPretty, IIndex, Var
Direct Known Subclasses:
AbstractBijectiveVar, IntDomainVarImpl, RealVarImpl, SetVarImpl

public abstract class AbstractVar
extends Object
implements Var

An abstract class for all implementations of domain variables.


Field Summary
protected  APartiallyStoredCstrList<? extends SConstraint> constraints
          The list of constraints (listeners) observing the variable.
protected  VarEvent<? extends Var> event
          The variable var associated to this variable.
 Extension[] extensions
          The extensions of this constraint, in order to add some data linked to this constraint (for specific algorithms)
protected  String name
          A name may be associated to each variable.
protected  PropagationEngine propagationEngine
           
 
Fields inherited from interface choco.kernel.solver.variables.Var
LOGGER
 
Constructor Summary
AbstractVar(Solver solver, String name, APartiallyStoredCstrList<? extends SConstraint> constraints)
          Initializes a new variable.
 
Method Summary
 int addConstraint(SConstraint 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 addExtension(int extensionNumber)
          Adds a new extension.
 void eraseConstraint(SConstraint c)
          Removes (permanently) a constraint from the list of constraints connected to the variable.
static int getAbstractVarExtensionNumber(String name)
          Returns a new number of extension registration
 SConstraint getConstraint(int i)
          Retrieve the constraint i involving the variable.
 DisposableIterator<SConstraint> getConstraintsIterator()
          This methods should be used if one want to access the different constraints currently posted on this variable.
 PartiallyStoredVector<? extends SConstraint> getConstraintVector()
          Access the data structure storing constraints involving a given variable.
 VarEvent<? extends Var> getEvent()
          Returns the variable event.
 Extension getExtension(int extensionNumber)
          Returns the queried extension
 long getIndex()
          Unique index (Different from hashCode, can change from one execution to another one)
 PartiallyStoredIntVector getIndexVector()
          Access the data structure storing indices associated to constraints involving a given variable.
 String getName()
           
 int getNbConstraints()
          Returns the number of constraints involving the variable.
 int getPriority()
          Return the priority of this according to the related constraints (minimum over all constraints priority)
 int getVarIndex(int constraintIndex)
          Returns the index of the variable in its constraint i.
 int hashCode()
           
 String toString()
          Useful for debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface choco.kernel.solver.variables.Var
isInstantiated
 
Methods inherited from interface choco.IPretty
pretty
 

Field Detail

propagationEngine

protected PropagationEngine propagationEngine

name

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


event

protected VarEvent<? extends Var> event
The variable var associated to this variable.


constraints

protected APartiallyStoredCstrList<? extends SConstraint> constraints
The list of constraints (listeners) observing the variable.


extensions

public Extension[] extensions
The extensions of this constraint, in order to add some data linked to this constraint (for specific algorithms)

Constructor Detail

AbstractVar

public AbstractVar(Solver solver,
                   String name,
                   APartiallyStoredCstrList<? extends SConstraint> constraints)
Initializes a new variable.

Parameters:
solver - The model this variable belongs to
name - The name of the variable
constraints - constraints stored specific structure
Method Detail

getAbstractVarExtensionNumber

public static int getAbstractVarExtensionNumber(String name)
Returns a new number of extension registration

Parameters:
name - A name for the extension (should be an UID, like the absolute path for instance)
Returns:
a number that can be used for specifying an extension (setExtension method)

getName

public String getName()
Specified by:
getName in interface Var

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getIndex

public final long getIndex()
Unique index (Different from hashCode, can change from one execution to another one)

Specified by:
getIndex in interface IIndex
Returns:
the indice of the objet

getPriority

public final int getPriority()
Description copied from interface: Var
Return the priority of this according to the related constraints (minimum over all constraints priority)

Specified by:
getPriority in interface Var
Returns:

addExtension

public void addExtension(int extensionNumber)
Adds a new extension.

Specified by:
addExtension in interface IExtensionnable
Parameters:
extensionNumber - should use the number returned by getAbstractSConstraintExtensionNumber

getExtension

public Extension getExtension(int extensionNumber)
Returns the queried extension

Specified by:
getExtension in interface IExtensionnable
Parameters:
extensionNumber - should use the number returned by getAbstractSConstraintExtensionNumber
Returns:
the queried extension

toString

public String toString()
Useful for debugging.

Overrides:
toString in class Object
Returns:
the name of the variable

getEvent

public VarEvent<? extends Var> getEvent()
Returns the variable event.

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

getConstraint

public SConstraint 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<? extends SConstraint> 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(SConstraint 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(SConstraint 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 DisposableIterator<SConstraint> 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


Copyright © 2012. All Rights Reserved.