choco.cp.solver.variables.integer
Class IntDomainVarImpl<C extends AbstractSConstraint & IntPropagator>

java.lang.Object
  extended by choco.kernel.solver.variables.AbstractVar
      extended by choco.cp.solver.variables.integer.IntDomainVarImpl<C>
All Implemented Interfaces:
IExtensionnable, IPretty, IIndex, IntExp, IntDomainVar, IntVar, Var
Direct Known Subclasses:
BooleanVarImpl, ViewIntDomainVarImpl

public class IntDomainVarImpl<C extends AbstractSConstraint & IntPropagator>
extends AbstractVar
implements IntDomainVar

Implements search valued domain variables.


Field Summary
protected  AbstractIntDomain domain
          The backtrackable domain of the variable.
 
Fields inherited from class choco.kernel.solver.variables.AbstractVar
constraints, event, extensions, name, propagationEngine
 
Fields inherited from interface choco.kernel.solver.variables.integer.IntDomainVar
BINARYTREE, BIPARTITELIST, BITSET, BOOLEAN, BOUNDS, LINKEDLIST, ONE_VALUE
 
Fields inherited from interface choco.kernel.solver.variables.Var
LOGGER
 
Constructor Summary
protected IntDomainVarImpl(Solver solver, String name)
          Default constructor
  IntDomainVarImpl(Solver solver, String name, int domainType, int[] distinctSortedValues)
           
  IntDomainVarImpl(Solver solver, String name, int domainType, int a, int b)
          Constructs a new variable for the specified model 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.
 boolean fastCanBeInstantiatedTo(int x)
          Checks if a value is still in the domain assuming the value is in the initial bound of the domain
 int fastNextDomainValue(int i)
          retrieves the value immediately (but strictly) after i in the domain, assuming the value is greater or equal to the lower bound.
 int fastPrevDomainValue(int i)
          retrieves the value immediately (but strictly) before i in the domain, assuming the value is less or equal to the upper bound.
 DisposableIterator<Couple<C>> getActiveConstraints(int evtType, C cstrCause)
           
 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.
 PartiallyStoredIntVector[] getEventsVector()
           
 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 hasBooleanDomain()
          Public user API: Domains : whether the domain is a 0/1 domain
 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)
          Deprecated. 
 boolean instantiate(int x, SConstraint cause, boolean forceAwake)
          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.
 String pretty()
          pretty printing
 boolean removeInterval(int a, int b, int idx)
          Deprecated. 
 boolean removeInterval(int a, int b, SConstraint cause, boolean forceAwake)
          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)
          Deprecated. 
 boolean removeVal(int x, SConstraint cause, boolean forceAwake)
          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.
 String toString()
          pretty printing
 boolean updateInf(int x, int idx)
          Deprecated. 
 boolean updateInf(int x, SConstraint cause, boolean forceAwake)
          Internal var: update on the variable lower bound caused by its i-th constraint.
 boolean updateSup(int x, int idx)
          Deprecated. 
 boolean updateSup(int x, SConstraint cause, boolean forceAwake)
          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.kernel.solver.variables.AbstractVar
addConstraint, addExtension, eraseConstraint, getAbstractVarExtensionNumber, getConstraint, getConstraintsIterator, getConstraintVector, getEvent, getExtension, getIndex, getIndexVector, getName, getNbConstraints, getPriority, getVarIndex, hashCode
 
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
addConstraint, getConstraint, getConstraintsIterator, getConstraintVector, getEvent, getIndexVector, getName, getNbConstraints, getPriority, getVarIndex
 
Methods inherited from interface choco.kernel.common.IIndex
getIndex
 
Methods inherited from interface choco.IExtensionnable
addExtension, getExtension
 

Field Detail

domain

protected AbstractIntDomain domain
The backtrackable domain of the variable.

Constructor Detail

IntDomainVarImpl

protected IntDomainVarImpl(Solver solver,
                           String name)
Default constructor

Parameters:
solver - master solver
name - name of the variable

IntDomainVarImpl

public IntDomainVarImpl(Solver solver,
                        String name,
                        int domainType,
                        int a,
                        int b)
Constructs a new variable for the specified model and with the specified name and bounds.

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

IntDomainVarImpl

public IntDomainVarImpl(Solver solver,
                        String name,
                        int domainType,
                        int[] distinctSortedValues)
Method Detail

getActiveConstraints

public final DisposableIterator<Couple<C>> getActiveConstraints(int evtType,
                                                                C cstrCause)

getEventsVector

public final PartiallyStoredIntVector[] getEventsVector()

isInstantiatedTo

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

Specified by:
isInstantiatedTo in interface IntVar
Parameters:
x - the tested value
Returns:
wether the value of an instantiated variables is equal to a x.

isInstantiated

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

Specified by:
isInstantiated in interface Var
Returns:
a boolean giving if a variable is instanciated or not

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
Returns:
wether a value is in the domain

fastCanBeInstantiatedTo

public boolean fastCanBeInstantiatedTo(int x)
Checks if a value is still in the domain assuming the value is in the initial bound of the domain

Specified by:
fastCanBeInstantiatedTo in interface IntDomainVar

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 - contradiction exception

setMin

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

Specified by:
setMin in interface IntDomainVar
Parameters:
x - the new inf value
Throws:
ContradictionException - contradiction exception

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 - contradiction exception

setMax

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

Specified by:
setMax in interface IntDomainVar
Parameters:
x - the new max value
Throws:
ContradictionException - contradiction exception

setVal

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

Specified by:
setVal in interface IntVar
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 - contradiction exception

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
Returns:
wether an enumeration of values is stored

hasBooleanDomain

public boolean hasBooleanDomain()
Description copied from interface: IntDomainVar
Public user API: Domains : whether the domain is a 0/1 domain

Specified by:
hasBooleanDomain in interface IntDomainVar
Returns:
wether the domain is a 0/1 domain

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
Returns:
the objects responsible for storing the enumeration of values in the domain

getDomainSize

public int getDomainSize()
Gets the domain size.

Specified by:
getDomainSize in interface IntDomainVar
Returns:
the number of values in the domain

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
Returns:
wether two variables have intersecting domains

canBeInstantiatedIn

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

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
Returns:
a value drawn at random from the domain

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
Returns:
the value immediatly after the domain

fastNextDomainValue

public int fastNextDomainValue(int i)
Description copied from interface: IntDomainVar
retrieves the value immediately (but strictly) after i in the domain, assuming the value is greater or equal to the lower bound.

Specified by:
fastNextDomainValue in interface IntDomainVar

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
Returns:
the value immediatly before the domain

fastPrevDomainValue

public int fastPrevDomainValue(int i)
Description copied from interface: IntDomainVar
retrieves the value immediately (but strictly) before i in the domain, assuming the value is less or equal to the upper bound.

Specified by:
fastPrevDomainValue in interface IntDomainVar

updateInf

public boolean updateInf(int x,
                         SConstraint cause,
                         boolean forceAwake)
                  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.
cause -
forceAwake -
Returns:
a boolean indicating whether this method call added new information or not
Throws:
ContradictionException - contradiction exception

updateInf

@Deprecated
public boolean updateInf(int x,
                                    int idx)
                  throws ContradictionException
Deprecated. 

Specified by:
updateInf in interface IntDomainVar
Throws:
ContradictionException

updateSup

public boolean updateSup(int x,
                         SConstraint cause,
                         boolean forceAwake)
                  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
cause -
forceAwake -
Returns:
a boolean indicating whether this method call added new information or not
Throws:
ContradictionException - contradiction exception

updateSup

@Deprecated
public boolean updateSup(int x,
                                    int idx)
                  throws ContradictionException
Deprecated. 

Specified by:
updateSup in interface IntDomainVar
Throws:
ContradictionException

removeVal

public boolean removeVal(int x,
                         SConstraint cause,
                         boolean forceAwake)
                  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
cause -
forceAwake -
Returns:
a boolean indicating whether this method call added new information or not
Throws:
ContradictionException - contradiction exception

removeVal

@Deprecated
public boolean removeVal(int x,
                                    int idx)
                  throws ContradictionException
Deprecated. 

Specified by:
removeVal in interface IntDomainVar
Throws:
ContradictionException

removeInterval

public boolean removeInterval(int a,
                              int b,
                              SConstraint cause,
                              boolean forceAwake)
                       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
cause -
forceAwake -
Returns:
a boolean indicating whether this method call added new information or not
Throws:
ContradictionException - contradiction exception

removeInterval

@Deprecated
public boolean removeInterval(int a,
                                         int b,
                                         int idx)
                       throws ContradictionException
Deprecated. 

Specified by:
removeInterval in interface IntDomainVar
Throws:
ContradictionException

instantiate

public boolean instantiate(int x,
                           SConstraint cause,
                           boolean forceAwake)
                    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
cause -
forceAwake -
Returns:
a boolean indicating whether this method call added new information or not
Throws:
ContradictionException - contradiction exception

instantiate

@Deprecated
public boolean instantiate(int x,
                                      int idx)
                    throws ContradictionException
Deprecated. 

Specified by:
instantiate in interface IntDomainVar
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 IntVar
Returns:
the value of the variable

getValue

public int getValue()
Deprecated. replaced by getVal

Specified by:
getValue in interface IntDomainVar
Returns:
the value of the variable if known

toString

public String toString()
pretty printing

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

pretty

public String pretty()
pretty printing

Specified by:
pretty in interface IPretty
Returns:
a String representation of the variable


Copyright © 2012. All Rights Reserved.