choco.integer.var
Class IntDomainVarImpl

java.lang.Object
  extended by choco.AbstractEntity
      extended by choco.AbstractVar
          extended by choco.integer.var.IntDomainVarImpl
All Implemented Interfaces:
Entity, IntDomainVar, IntExp, IntVar, Var
Direct Known Subclasses:
JumpIntVar, PalmIntVar

public class IntDomainVarImpl
extends AbstractVar
implements IntDomainVar

Implements search valued domain variables.


Field Summary
protected  AbstractIntDomain domain
          The backtrackable domain of the variable.
protected static java.util.logging.Logger logger
          Reference to an object for logging trace statements related to IntDomainVar (using the java.util.logging package)
 StoredInt value
          The backtrackable value of the variable, if instantiated.
 
Fields inherited from class choco.AbstractVar
constraints, event, indices, name
 
Fields inherited from class choco.AbstractEntity
hook, problem
 
Fields inherited from interface choco.integer.IntDomainVar
BOUNDS, LIST
 
Constructor Summary
IntDomainVarImpl(AbstractProblem pb, java.lang.String name, int[] sortedValues)
           
IntDomainVarImpl(AbstractProblem pb, java.lang.String name, int domainType, int a, int b)
          Constructs a new variable for the specified problem and with the specified name and bounds.
 
Method Summary
 boolean canBeEqualTo(IntDomainVar x)
          Checks if it can be equals to another variable.
 boolean canBeInstantiatedIn(int[] sortedValList, int nVals)
          Checks if the variables can be instantiated to at least one value in the array.
 boolean canBeInstantiatedTo(int x)
          Checks if a value is still in the domain.
 void fail()
          a constraint may fail during propagation, raising a contradiction
 IntDomain getDomain()
          Public user API: Domains : returns the object responsible for storing the enumeration of values in the domain
 int getDomainSize()
          Gets the domain size.
 int getInf()
          Gets the minimal value of the variable.
 int getNextDomainValue(int currentv)
          Gets the next value in the domain.
 int getPrevDomainValue(int currentv)
          Gets the previous value in the domain.
 int getRandomDomainValue()
          Returns a randomly choosed value in the domain.
 int getSup()
          Gets the maximal value of the variable.
 int getVal()
          Gets the value of the variable if instantiated.
 int getValue()
          Deprecated. replaced by getVal
 boolean hasEnumeratedDomain()
          Public user API: Domains : whether an enumeration of values (in addition to the enclosing interval) is stored
 boolean instantiate(int x, int idx)
          Internal var: instantiation of the variable caused by its i-th constraint Returns a boolean indicating whether the call indeed added new information.
 boolean isInstantiated()
          Checks if the variables is instantiated to any value.
 boolean isInstantiatedTo(int x)
          Checks if the variable is instantiated to a specific value.
 java.lang.String pretty()
          pretty printing
 boolean removeInterval(int a, int b, int idx)
          Internal var: remove an interval (a sequence of consecutive values) from the domain of a variable caused by its i-th constraint.
 boolean removeVal(int x, int idx)
          Internal var: update (value removal) on the domain of a variable caused by its i-th constraint.
 void remVal(int x)
          Removes a value.
 void setInf(int x)
          Sets the minimum value.
 void setMax(int x)
          Deprecated. replaced by setSup
 void setMin(int x)
          Deprecated. replaced by setInf
 void setSup(int x)
          Sets the maximal value.
 void setVal(int x)
          Instantiates the variable.
 java.lang.String toString()
          pretty printing
 boolean updateInf(int x, int idx)
          Internal var: update on the variable lower bound caused by its i-th constraint.
 boolean updateSup(int x, int idx)
          Internal var: update on the variable upper bound caused by its i-th constraint.
 void wipeOut()
          Public user API: Propagation events wiping out the domain of the variable (removing all values) and throwing a contradiction
 
Methods inherited from class choco.AbstractVar
addConstraint, eraseConstraint, getConstraint, getConstraintsIterator, getConstraintVector, getEvent, getIndexVector, getNbConstraints, getVarIndex
 
Methods inherited from class choco.AbstractEntity
getProblem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface choco.integer.IntDomainVar
getProblem
 
Methods inherited from interface choco.Var
addConstraint, getConstraint, getConstraintsIterator, getConstraintVector, getEvent, getIndexVector, getNbConstraints, getVarIndex
 

Field Detail

value

public final StoredInt value
The backtrackable value of the variable, if instantiated.


domain

protected AbstractIntDomain domain
The backtrackable domain of the variable.


logger

protected static java.util.logging.Logger logger
Reference to an object for logging trace statements related to IntDomainVar (using the java.util.logging package)

Constructor Detail

IntDomainVarImpl

public IntDomainVarImpl(AbstractProblem pb,
                        java.lang.String name,
                        int domainType,
                        int a,
                        int b)
Constructs a new variable for the specified problem and with the specified name and bounds.

Parameters:
pb - The problem of the variable.
name - Its name.
domainType - the type of encoding for the domain (BOUNDS, LIST, ...)
a - Its minimal value.
b - Its maximal value.

IntDomainVarImpl

public IntDomainVarImpl(AbstractProblem pb,
                        java.lang.String name,
                        int[] sortedValues)
Method Detail

isInstantiatedTo

public boolean isInstantiatedTo(int x)
Checks if the variable is instantiated to a specific value.

Specified by:
isInstantiatedTo in interface IntDomainVar

isInstantiated

public boolean isInstantiated()
Checks if the variables is instantiated to any value.

Specified by:
isInstantiated in interface Var

canBeInstantiatedTo

public boolean canBeInstantiatedTo(int x)
Checks if a value is still in the domain.

Specified by:
canBeInstantiatedTo in interface IntDomainVar
Parameters:
x - the tested value

setInf

public void setInf(int x)
            throws ContradictionException
Sets the minimum value.

Specified by:
setInf in interface IntDomainVar
Parameters:
x - the new lower bound
Throws:
ContradictionException

setMin

public void setMin(int x)
            throws ContradictionException
Deprecated. replaced by setInf

Specified by:
setMin in interface IntDomainVar
Throws:
ContradictionException

setSup

public void setSup(int x)
            throws ContradictionException
Sets the maximal value.

Specified by:
setSup in interface IntDomainVar
Parameters:
x - the new upper bound
Throws:
ContradictionException

setMax

public void setMax(int x)
            throws ContradictionException
Deprecated. replaced by setSup

Specified by:
setMax in interface IntDomainVar
Throws:
ContradictionException

setVal

public void setVal(int x)
            throws ContradictionException
Instantiates the variable.

Specified by:
setVal in interface IntDomainVar
Parameters:
x - the value that is assigned to the variable
Throws:
ContradictionException

remVal

public void remVal(int x)
            throws ContradictionException
Removes a value.

Specified by:
remVal in interface IntDomainVar
Parameters:
x - the removed value
Throws:
ContradictionException

wipeOut

public void wipeOut()
             throws ContradictionException
Description copied from interface: IntDomainVar
Public user API: Propagation events wiping out the domain of the variable (removing all values) and throwing a contradiction

Specified by:
wipeOut in interface IntDomainVar
Throws:
ContradictionException

hasEnumeratedDomain

public boolean hasEnumeratedDomain()
Description copied from interface: IntDomainVar
Public user API: Domains : whether an enumeration of values (in addition to the enclosing interval) is stored

Specified by:
hasEnumeratedDomain in interface IntDomainVar

getDomain

public IntDomain getDomain()
Description copied from interface: IntDomainVar
Public user API: Domains : returns the object responsible for storing the enumeration of values in the domain

Specified by:
getDomain in interface IntDomainVar

getDomainSize

public int getDomainSize()
Gets the domain size.

Specified by:
getDomainSize in interface IntDomainVar

canBeEqualTo

public boolean canBeEqualTo(IntDomainVar x)
Checks if it can be equals to another variable.

Specified by:
canBeEqualTo in interface IntDomainVar
Parameters:
x - the other variable

canBeInstantiatedIn

public boolean canBeInstantiatedIn(int[] sortedValList,
                                   int nVals)
Checks if the variables can be instantiated to at least one value in the array.

Specified by:
canBeInstantiatedIn in interface IntDomainVar
Parameters:
sortedValList - The value array.
nVals - The number of interesting value in this array.

getRandomDomainValue

public int getRandomDomainValue()
Returns a randomly choosed value in the domain.

Not implemented yet.

Specified by:
getRandomDomainValue in interface IntDomainVar

getNextDomainValue

public int getNextDomainValue(int currentv)
Gets the next value in the domain.

Specified by:
getNextDomainValue in interface IntDomainVar
Parameters:
currentv - the pivot value. May or may not be in the domain

getPrevDomainValue

public int getPrevDomainValue(int currentv)
Gets the previous value in the domain.

Specified by:
getPrevDomainValue in interface IntDomainVar
Parameters:
currentv - the pivot value. May or may not be in the domain

updateInf

public boolean updateInf(int x,
                         int idx)
                  throws ContradictionException
Internal var: update on the variable lower bound caused by its i-th constraint. Returns a boolean indicating whether the call indeed added new information

Specified by:
updateInf in interface IntDomainVar
Parameters:
x - The new lower bound.
idx - The index of the constraint (among all constraints linked to the variable) responsible for the update.
Returns:
a boolean indicating whether this method call added new information or not
Throws:
ContradictionException

updateSup

public boolean updateSup(int x,
                         int idx)
                  throws ContradictionException
Internal var: update on the variable upper bound caused by its i-th constraint. Returns a boolean indicating whether the call indeed added new information.

Specified by:
updateSup in interface IntDomainVar
Parameters:
x - The new upper bound
idx - The index of the constraint (among all constraints linked to the variable) responsible for the update
Returns:
a boolean indicating whether this method call added new information or not
Throws:
ContradictionException

removeVal

public boolean removeVal(int x,
                         int idx)
                  throws ContradictionException
Internal var: update (value removal) on the domain of a variable caused by its i-th constraint. Note: Whenever the hole results in a stronger var (such as a bound update or an instantiation, then we forget about the index of the var generating constraint. Indeed the propagated var is stronger than the initial one that was generated; thus the generating constraint should be informed about such a new var. Returns a boolean indicating whether the call indeed added new information.

Specified by:
removeVal in interface IntDomainVar
Parameters:
x - The removed value
idx - The index of the constraint (among all constraints linked to the variable) responsible for the update
Returns:
a boolean indicating whether this method call added new information or not
Throws:
ContradictionException

removeInterval

public boolean removeInterval(int a,
                              int b,
                              int idx)
                       throws ContradictionException
Internal var: remove an interval (a sequence of consecutive values) from the domain of a variable caused by its i-th constraint. Returns a boolean indicating whether the call indeed added new information.

Specified by:
removeInterval in interface IntDomainVar
Parameters:
a - the first removed value
b - the last removed value
idx - the index of the constraint (among all constraints linked to the variable) responsible for the update
Returns:
a boolean indicating whether this method call added new information or not
Throws:
ContradictionException

instantiate

public boolean instantiate(int x,
                           int idx)
                    throws ContradictionException
Internal var: instantiation of the variable caused by its i-th constraint Returns a boolean indicating whether the call indeed added new information.

Specified by:
instantiate in interface IntDomainVar
Parameters:
x - the new upper bound
idx - the index of the constraint (among all constraints linked to the variable) responsible for the update
Returns:
a boolean indicating whether this method call added new information or not
Throws:
ContradictionException

fail

public void fail()
          throws ContradictionException
Description copied from interface: Var
a constraint may fail during propagation, raising a contradiction

Specified by:
fail in interface Var
Throws:
ContradictionException

getInf

public int getInf()
Gets the minimal value of the variable.

Specified by:
getInf in interface IntDomainVar
Returns:
the domain lower bound

getSup

public int getSup()
Gets the maximal value of the variable.

Specified by:
getSup in interface IntDomainVar
Returns:
the domain upper bound

getVal

public int getVal()
Gets the value of the variable if instantiated.

Specified by:
getVal in interface IntDomainVar
Returns:
the value of the variable

getValue

public int getValue()
Deprecated. replaced by getVal

Specified by:
getValue in interface IntDomainVar

toString

public java.lang.String toString()
pretty printing

Overrides:
toString in class AbstractVar
Returns:
a String representation of the variable

pretty

public java.lang.String pretty()
pretty printing

Specified by:
pretty in interface Entity
Overrides:
pretty in class AbstractEntity
Returns:
a String representation of the variable