choco.cp.solver.variables.integer
Class LinkedIntDomain

java.lang.Object
  extended by choco.cp.solver.variables.integer.AbstractIntDomain
      extended by choco.cp.solver.variables.integer.LinkedIntDomain
All Implemented Interfaces:
IPretty, Domain, IntDomain

public class LinkedIntDomain
extends AbstractIntDomain

Integer domain implementation using linked list of indices. This implementation is more costful in terms of memory than bit set implementation but should be more efficient in terms of CPU (mainly for interating the domain).

This implementation should be extendable to deal with large sparse domains, since we mainly deal with indices of values (which is managed implicitely here: offset + index).

Author: Guillaume Rochart Creation date: January, 20th 2007


Field Summary
protected  IntDomainIterator _iterator
           
 
Fields inherited from class choco.cp.solver.variables.integer.AbstractIntDomain
currentInfPropagated, currentSupPropagated
 
Fields inherited from interface choco.kernel.solver.variables.integer.IntDomain
LOGGER
 
Constructor Summary
LinkedIntDomain(IntDomainVarImpl v, int[] sortedValues, IEnvironment environment, PropagationEngine propagationEngine)
           
LinkedIntDomain(IntDomainVarImpl v, int a, int b, IEnvironment environment, PropagationEngine propagationEngine)
          Constructs a new domain for the specified variable and bounds.
 
Method Summary
 boolean contains(int x)
          Checks if the value x is in the current domain.
 int getInf()
          Returns the lower bound of the domain in O(1).
 DisposableIntIterator getIterator()
          Retrieve an getIterator for traversing the sequence of values contained in the domain
 int getNextValue(int x)
          Looks for the value after x in the domain.
 int getPrevValue(int x)
          Looks for the value before x in the domain.
 int getRandomValue()
          Returns a value randomly choosed in the domain.
 int getSize()
          Retuens the dynamic size of the domain, that is the number of possible values in the domain when the method is called.
 int getSup()
          Returns the upper bound of the domain in O(1).
 boolean hasNextValue(int x)
          Checks if there is a value after x in the domain.
 boolean hasPrevValue(int x)
          Checks if there is a value before x in the domain.
 boolean isBoolean()
          Checks if this is a boolean domain, that is the values are 0 or 1.
 boolean isEnumerated()
          Interface method to know if this domain is enumerated.
 String pretty()
          pretty printing of the object.
 boolean remove(int x)
          Removes a precise value from the domain.
 void restrict(int x)
          Restricts the domain to the given value.
 String toString()
           
 int updateInf(int x)
          Updates the lower bound of the domain to the next value contained in the domain which is more or equal to x.
 int updateSup(int x)
          Updates the upper bound of the domain to the next value contained in the domain which is less or equal to x.
 
Methods inherited from class choco.cp.solver.variables.integer.AbstractIntDomain
clearDeltaDomain, copyDelta, fastNextValue, fastPrevValue, freezeDeltaDomain, getDeltaIterator, getReleasedDeltaDomain, instantiate, releaseDeltaDomain, removeInterval, removeVal, updateInf, updateSup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_iterator

protected IntDomainIterator _iterator
Constructor Detail

LinkedIntDomain

public LinkedIntDomain(IntDomainVarImpl v,
                       int a,
                       int b,
                       IEnvironment environment,
                       PropagationEngine propagationEngine)
Constructs a new domain for the specified variable and bounds.

Parameters:
v - The involved variable.
a - Minimal value.
b - Maximal value.
environment -
propagationEngine -

LinkedIntDomain

public LinkedIntDomain(IntDomainVarImpl v,
                       int[] sortedValues,
                       IEnvironment environment,
                       PropagationEngine propagationEngine)
Method Detail

getInf

public int getInf()
Returns the lower bound of the domain in O(1).

Returns:
the lower bound of the domain.

getSup

public int getSup()
Returns the upper bound of the domain in O(1).

Returns:
the upper bound of the domain.

contains

public boolean contains(int x)
Checks if the value x is in the current domain. It is done in O(1).

Parameters:
x - the value to check wetehr it is in the domain. It can be completely outside of the original domain in this implementation.
Returns:
true if the value x is in the domain.

updateInf

public int updateInf(int x)
Updates the lower bound of the domain to the next value contained in the domain which is more or equal to x.

This is done in O(n) with n the size of the domain.

Parameters:
x - a value the lower bound should be more than. x should be less than the upper bound!
Returns:
the new lower bound of the domain.

updateSup

public int updateSup(int x)
Updates the upper bound of the domain to the next value contained in the domain which is less or equal to x.

This is done in O(n) with n the size of the domain.

Parameters:
x - a value the upper bound should be less than. x should be more than lower bound!
Returns:
the new upper bound of the domain.

restrict

public void restrict(int x)
Restricts the domain to the given value.

This is done in O(n) with n the size of the domain.

Parameters:
x - the value to which this domain should be restricted to.

remove

public boolean remove(int x)
Removes a precise value from the domain.

This is done in O(1).

Parameters:
x - the value in the domain.
Returns:
true if a value was actually removed.

getSize

public int getSize()
Retuens the dynamic size of the domain, that is the number of possible values in the domain when the method is called.

Returns:
the size of the domain.

getIterator

public DisposableIntIterator getIterator()
Description copied from interface: IntDomain
Retrieve an getIterator for traversing the sequence of values contained in the domain


getNextValue

public int getNextValue(int x)
Looks for the value after x in the domain. It is safe with value out of the domain.

It is done in O(1) if x is a value of the domain, O(n) else.

Parameters:
x - A value (in or out of the domain).
Returns:
The value in the domain after x, Integer.MAX_VALUE if none.

getPrevValue

public int getPrevValue(int x)
Looks for the value before x in the domain. It is safe with value out of the domain.

It is done in O(1) if x is a value of the domain, O(n) else.

Parameters:
x - A value (in or out of the domain).
Returns:
The value in the domain before x, Integer.MIN_VALUE if none.

hasNextValue

public boolean hasNextValue(int x)
Checks if there is a value after x in the domain. Basically checks that x if less than the upper bound (in O(1)).

Parameters:
x - value in or out of the domain.
Returns:
true if there is value in the domain greater than x

hasPrevValue

public boolean hasPrevValue(int x)
Checks if there is a value before x in the domain. Basically checks that x if more than the lower bound (in O(1)).

Parameters:
x - value in or out of the domain.
Returns:
true if there is value in the domain smaller than x

getRandomValue

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

It is done in O(n).

Returns:
a random value from the domain.

isEnumerated

public boolean isEnumerated()
Interface method to know if this domain is enumerated. Always true here.

Returns:
true

isBoolean

public boolean isBoolean()
Checks if this is a boolean domain, that is the values are 0 or 1.

Returns:
tue if this is a boolean domain.

toString

public String toString()
Overrides:
toString in class AbstractIntDomain

pretty

public String pretty()
Description copied from interface: IPretty
pretty printing of the object. This String is not constant and may depend on the context.

Returns:
a readable string representation of the object


Copyright © 2012. All Rights Reserved.