Package org.jacop.core
Class SmallDenseDomain
- java.lang.Object
-
- org.jacop.core.Domain
-
- org.jacop.core.IntDomain
-
- org.jacop.core.SmallDenseDomain
-
- All Implemented Interfaces:
java.lang.Cloneable
public class SmallDenseDomain extends IntDomain implements java.lang.Cloneable
Defines small dense domain based on bits within a long number.- Version:
- 4.8
-
-
Field Summary
Fields Modifier and Type Field Description longbitsIt stores information about presence of the elements in the domain.static SmallDenseDomainemptyDomainIt is an empty domain returned by default when empty domain becomes a result of any function.(package private) longfirst8private static java.util.Randomgeneratorprivate intmaxintminThe minimal value present in this domain encoding.private static long[]SEQ_ARRAYprivate booleansingletonprivate intsizeprivate static long[]TWO_N_ARRAY-
Fields inherited from class org.jacop.core.IntDomain
ANY, BOUND, BoundDomainID, emptyIntDomain, eventsInclusion, GROUND, IntervalDomainID, MaxInt, MinInt, previousDomain, SmallDenseDomainID
-
Fields inherited from class org.jacop.core.Domain
failException, modelConstraints, modelConstraintsToEvaluate, NOINFO, NONE, searchConstraints, searchConstraintsCloned, searchConstraintsToEvaluate, stamp
-
-
Constructor Summary
Constructors Constructor Description SmallDenseDomain()It creates an empty domain.SmallDenseDomain(int min, int max)It creates a domain with values between min and max inclusive.SmallDenseDomain(int min, long bits)It creates a domain of type small dense.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidadaptMin()voidaddDom(IntDomain domain)It adds values as specified by the parameter to the domain.java.lang.StringcheckInvariants()It checks if the domain has correct state.voidclear()It removes all elements.Domainclone()It clones the domain object.SmallDenseDomaincloneLight()It clones the domain object, only data responsible for encoding domain values is cloned.IntDomaincomplement()It creates a complement of a domain.booleancontains(int value)It checks if value belongs to the domain.booleancontains(int min, int max)It checks if an interval min..max belongs to the domain.booleancontains(IntDomain domain)It specifies if the current domain contains the domain given as a parameter.intdomainID()It returns an unique identifier of the domain.booleaneq(IntDomain domain)It specifies if the other int domain is equal to this one.intgetElementAt(int index)It access the element at the specified position.IntervalgetInterval(int position)It returns required interval.IntDomaingetPreviousDomain()It returns domain at earlier level at which the change has occurred.intgetRandomValue()It returns a random value from the domain.intgetSize()It returns the size of the domain.intgetSize(long input)It computes the number of 1's in the binary representation of the number given in the field input.voidin(int storeLevel, Var var, int min, int max)It updates the domain to have values only within the interval min..max.voidin(int storeLevel, Var var, long domain)voidin(int storeLevel, Var var, IntDomain domain)It updates the domain to have values only within the domain.voidinComplement(int storeLevel, Var var, int complement)It updates the domain to not contain the value complement.voidinComplement(int storeLevel, Var var, int minComplement, int maxComplement)It updates the domain so it does not contain the supplied interval.voidinMax(int storeLevel, Var var, int max)It updates the domain according to the maximum value and stamp value.voidinMin(int storeLevel, Var var, int min)It updates the domain according to the minimum value and stamp value.voidinShift(int storeLevel, Var var, IntDomain domain, int shift)It updates the domain to contain the elements as specifed by the domain, which is shifted.IntDomainintersect(int min, int max)In intersects current domain with the interval min..max.IntDomainintersect(IntDomain domain)It intersects current domain with the one given as a parameter.SmallDenseDomainintersect(IntervalDomain input, int shift)intintersectAdapt(int min, int max)It computes an intersection of this domain with an interval [min..max].intintersectAdapt(IntDomain domain)It computes an intersection with a given domain and stores it in this domain.IntervalEnumerationintervalEnumeration()It returns interval enumeration of the domain values.booleanisEmpty()It returns true if given domain is empty.booleanisIntersecting(int min, int max)It checks if interval min..max intersects with current domain.booleanisIntersecting(IntDomain domain)Checks if two domains intersect.booleanisNumeric()It specifies if domain is a finite domain of numeric values (integers).booleanisSparseRepresentation()It specifies if the domain type is more suited to representing sparse domain.intleftElement(int intervalNo)It returns the left most element of the given interval.intmax()It returns the maximum value in a domain.intmin()It returns the minimum value in a domain.intnextValue(int value)It gives next value in the domain from the given one (lexigraphical ordering).intnoIntervals()It returns number of intervals required to represent this domain.intpreviousValue(int value)It gives previous value in the domain from the given one (lexigraphical ordering).IntDomainrecentDomainPruning(int storeLevel)It returns the values which have been removed at current store level.voidremoveLevel(int level, Var var)It removes the specified level.intrightElement(int intervalNo)It returns the right most element of the given interval.voidsetDomain(int min, int max)It sets this domain to contain exactly all values between min and max.voidsetDomain(IntDomain domain)It sets the domain to the specified domain.voidshift(int shift)It shifts the domain.booleansingleton()It returns true if given domain has only one element.booleansingleton(int c)It returns true if given domain has only one element equal c.intsizeConstraintsOriginal()It returns all constraints which are associated with variable, even the ones which are already satisfied.intsizeOfIntersection(IntDomain domain)It computes the size of the intersection between this domain and the domain supplied as a parameter.IntDomainsubtract(int value)It intersects with the domain which is a complement of value.IntDomainsubtract(int min, int max)It subtracts interval min..max.IntDomainsubtract(IntDomain domain)It subtracts domain from current domain and returns the result.voidsubtractAdapt(int value)It removes value from the domain.voidsubtractAdapt(int min, int max)It removes all values between min and max to the domain.IntervalDomaintoIntervalDomain()java.lang.StringtoString()It returns string description of the domain (only values in the domain).java.lang.StringtoStringConstraints()It returns string description of the constraints attached to the domain.java.lang.StringtoStringFull()It returns complete string description containing all relevant information about the domain.IntDomainunion(int value)It computes union of this domain and value.IntDomainunion(int min, int max)It computes union of this domain and the interval.IntDomainunion(IntDomain domain)It computes union of the supplied domain with this domain.voidunionAdapt(int value)It adds a values to the domain.voidunionAdapt(int min, int max)It adds all values between min and max to the domain.voidunionAdapt(Interval i)It adds interval of values to the domain.ValueEnumerationvalueEnumeration()It returns value enumeration of the domain values.-
Methods inherited from class org.jacop.core.IntDomain
addInt, divBounds, divIntBounds, elementsSmallerThan, getEventsInclusion, in, inValue, lex, mulBounds, multiplyInt, noConstraints, putModelConstraint, putSearchConstraint, removeModelConstraint, removeSearchConstraint, removeSearchConstraint, singleton, squareBounds, subtractInt, toIntArray, unionAdapt, value
-
Methods inherited from class org.jacop.core.Domain
constraints, noSearchConstraints, searchConstraints, setStamp, sizeConstraints, stamp
-
-
-
-
Field Detail
-
emptyDomain
public static final SmallDenseDomain emptyDomain
It is an empty domain returned by default when empty domain becomes a result of any function.
-
min
public int min
The minimal value present in this domain encoding. The domain can only encode small domains within a range [min .. min + 63].
-
bits
public long bits
It stores information about presence of the elements in the domain. If the least significant bit is set then min + 63 is present. The most significant bit is always set as this domain maintains invariant that minimum value always belongs to the domain.
-
singleton
private boolean singleton
-
size
private int size
-
max
private int max
-
first8
long first8
-
TWO_N_ARRAY
private static final long[] TWO_N_ARRAY
-
SEQ_ARRAY
private static final long[] SEQ_ARRAY
-
generator
private static final java.util.Random generator
-
-
Constructor Detail
-
SmallDenseDomain
public SmallDenseDomain()
It creates an empty domain.
-
SmallDenseDomain
public SmallDenseDomain(int min, long bits)It creates a domain of type small dense.- Parameters:
min- the minimum value present in this domain.bits- the bits representing presence of any value from the range [ min .. min + 63].
-
SmallDenseDomain
public SmallDenseDomain(int min, int max)It creates a domain with values between min and max inclusive.- Parameters:
min- min element in the domainmax- max element in the domain
-
-
Method Detail
-
addDom
public void addDom(IntDomain domain)
Description copied from class:IntDomainIt adds values as specified by the parameter to the domain.
-
complement
public IntDomain complement()
Description copied from class:IntDomainIt creates a complement of a domain.- Specified by:
complementin classIntDomain- Returns:
- it returns the complement of this domain.
-
getPreviousDomain
public IntDomain getPreviousDomain()
Description copied from class:IntDomainIt returns domain at earlier level at which the change has occurred.- Specified by:
getPreviousDomainin classIntDomain- Returns:
- previous domain
-
contains
public boolean contains(IntDomain domain)
Description copied from class:IntDomainIt specifies if the current domain contains the domain given as a parameter.
-
contains
public boolean contains(int value)
Description copied from class:IntDomainIt checks if value belongs to the domain.
-
eq
public boolean eq(IntDomain domain)
Description copied from class:IntDomainIt specifies if the other int domain is equal to this one.
-
getElementAt
public int getElementAt(int index)
Description copied from class:IntDomainIt access the element at the specified position.- Specified by:
getElementAtin classIntDomain- Parameters:
index- the position of the element, indexing starts from 0.- Returns:
- the value at a given position in the domain.
-
getInterval
public Interval getInterval(int position)
Description copied from class:IntDomainIt returns required interval.- Specified by:
getIntervalin classIntDomain- Parameters:
position- the position of the interval.- Returns:
- the interval, or null if the required interval does not exist.
-
getSize
public int getSize()
Description copied from class:IntDomainIt returns the size of the domain.
-
getSize
public int getSize(long input)
It computes the number of 1's in the binary representation of the number given in the field input.- Parameters:
input- the 64bits for which calculation of number of 1's takes place.- Returns:
- the number of 1's.
-
in
public void in(int storeLevel, Var var, int min, int max)It updates the domain to have values only within the interval min..max. The type of update is decided by the value of stamp. It informs the variable of a change if it occurred.
-
adaptMin
private void adaptMin()
-
in
public void in(int storeLevel, Var var, long domain)
-
in
public void in(int storeLevel, Var var, IntDomain domain)Description copied from class:IntDomainIt updates the domain to have values only within the domain. The type of update is decided by the value of stamp. It informs the variable of a change if it occurred.
-
inComplement
public void inComplement(int storeLevel, Var var, int complement)Description copied from class:IntDomainIt updates the domain to not contain the value complement. It informs the variable of a change if it occurred.- Overrides:
inComplementin classIntDomain- Parameters:
storeLevel- level of the store at which the update occurs.var- variable for which this domain is used.complement- value which is removed from the domain if it belonged to the domain.
-
inComplement
public void inComplement(int storeLevel, Var var, int minComplement, int maxComplement)Description copied from class:IntDomainIt updates the domain so it does not contain the supplied interval. It informs the variable of a change if it occurred.- Specified by:
inComplementin classIntDomain- Parameters:
storeLevel- level of the store at which the update occurs.var- variable for which this domain is used.minComplement- the left bound of the interval (inclusive).maxComplement- the right bound of the interval (inclusive).
-
inMax
public void inMax(int storeLevel, Var var, int max)Description copied from class:IntDomainIt updates the domain according to the maximum value and stamp value. It informs the variable of a change if it occurred.
-
inMin
public void inMin(int storeLevel, Var var, int min)Description copied from class:IntDomainIt updates the domain according to the minimum value and stamp value. It informs the variable of a change if it occurred.
-
inShift
public void inShift(int storeLevel, Var var, IntDomain domain, int shift)Description copied from class:IntDomainIt updates the domain to contain the elements as specifed by the domain, which is shifted. E.g. {1..4} + 3 = 4..7
-
intersect
public SmallDenseDomain intersect(IntervalDomain input, int shift)
-
intersect
public IntDomain intersect(IntDomain domain)
Description copied from class:IntDomainIt intersects current domain with the one given as a parameter.
-
intersect
public IntDomain intersect(int min, int max)
Description copied from class:IntDomainIn intersects current domain with the interval min..max.
-
intersectAdapt
public int intersectAdapt(IntDomain domain)
Description copied from class:IntDomainIt computes an intersection with a given domain and stores it in this domain.- Specified by:
intersectAdaptin classIntDomain- Parameters:
domain- domain with which the intersection is being computed.- Returns:
- type of event which has occurred due to the operation.
-
intersectAdapt
public int intersectAdapt(int min, int max)Description copied from class:IntDomainIt computes an intersection of this domain with an interval [min..max]. It adapts this domain to the result of the intersection.- Specified by:
intersectAdaptin classIntDomain- Parameters:
min- the minimum value of the interval used in the intersection computation.max- the maximum value of the interval used in the intersection computation.- Returns:
- it returns information about the pruning event which has occurred due to this operation.
-
intervalEnumeration
public IntervalEnumeration intervalEnumeration()
Description copied from class:IntDomainIt returns interval enumeration of the domain values.- Specified by:
intervalEnumerationin classIntDomain- Returns:
- intervalEnumeration which can be used to enumerate intervals in this domain.
-
isIntersecting
public boolean isIntersecting(IntDomain domain)
Description copied from class:IntDomainChecks if two domains intersect.- Overrides:
isIntersectingin classIntDomain- Parameters:
domain- the domain for which intersection is checked.- Returns:
- true if domains are intersecting.
-
isIntersecting
public boolean isIntersecting(int min, int max)Description copied from class:IntDomainIt checks if interval min..max intersects with current domain.- Specified by:
isIntersectingin classIntDomain- Parameters:
min- the left bound of the interval.max- the right bound of the interval.- Returns:
- true if domain intersects with the specified interval.
-
leftElement
public int leftElement(int intervalNo)
Description copied from class:IntDomainIt returns the left most element of the given interval.- Overrides:
leftElementin classIntDomain- Parameters:
intervalNo- the interval number.- Returns:
- the left bound of the specified interval.
-
max
public int max()
Description copied from class:IntDomainIt returns the maximum value in a domain.
-
min
public int min()
Description copied from class:IntDomainIt returns the minimum value in a domain.
-
nextValue
public int nextValue(int value)
Description copied from class:IntDomainIt gives next value in the domain from the given one (lexigraphical ordering). If no value can be found then returns the same value.
-
noIntervals
public int noIntervals()
Description copied from class:IntDomainIt returns number of intervals required to represent this domain.- Specified by:
noIntervalsin classIntDomain- Returns:
- the number of intervals in the domain.
-
previousValue
public int previousValue(int value)
Description copied from class:IntDomainIt gives previous value in the domain from the given one (lexigraphical ordering). If no value can be found then returns the same value.- Specified by:
previousValuein classIntDomain- Parameters:
value- before which a value is seeked for.- Returns:
- it returns the value before the one specified as a parameter.
-
recentDomainPruning
public IntDomain recentDomainPruning(int storeLevel)
Description copied from class:IntDomainIt returns the values which have been removed at current store level.- Specified by:
recentDomainPruningin classIntDomain- Parameters:
storeLevel- the current store level.- Returns:
- emptyDomain if domain did not change at current level, or the set of values which have been removed at current level.
-
rightElement
public int rightElement(int intervalNo)
Description copied from class:IntDomainIt returns the right most element of the given interval.- Overrides:
rightElementin classIntDomain- Parameters:
intervalNo- the interval number.- Returns:
- the right bound of the specified interval.
-
setDomain
public void setDomain(IntDomain domain)
Description copied from class:IntDomainIt sets the domain to the specified domain.
-
setDomain
public void setDomain(int min, int max)Description copied from class:IntDomainIt sets this domain to contain exactly all values between min and max.
-
singleton
public boolean singleton(int c)
Description copied from class:IntDomainIt returns true if given domain has only one element equal c.
-
sizeOfIntersection
public int sizeOfIntersection(IntDomain domain)
Description copied from class:IntDomainIt computes the size of the intersection between this domain and the domain supplied as a parameter.- Overrides:
sizeOfIntersectionin classIntDomain- Parameters:
domain- the domain with which the intersection is computed.- Returns:
- the size of the intersection.
-
subtract
public IntDomain subtract(int value)
Description copied from class:IntDomainIt intersects with the domain which is a complement of value.
-
subtract
public IntDomain subtract(IntDomain domain)
Description copied from class:IntDomainIt subtracts domain from current domain and returns the result.
-
subtractAdapt
public void subtractAdapt(int min, int max)Description copied from class:IntDomainIt removes all values between min and max to the domain.- Specified by:
subtractAdaptin classIntDomain- Parameters:
min- the left bound of the interval being removed.max- the right bound of the interval being removed.
-
subtract
public IntDomain subtract(int min, int max)
Description copied from class:IntDomainIt subtracts interval min..max.
-
subtractAdapt
public void subtractAdapt(int value)
Description copied from class:IntDomainIt removes value from the domain. It adapts current (this) domain.- Specified by:
subtractAdaptin classIntDomain- Parameters:
value- the value for which the complement is computed
-
union
public IntDomain union(IntDomain domain)
Description copied from class:IntDomainIt computes union of the supplied domain with this domain.
-
union
public IntDomain union(int min, int max)
Description copied from class:IntDomainIt computes union of this domain and the interval.
-
union
public IntDomain union(int value)
Description copied from class:IntDomainIt computes union of this domain and value.
-
unionAdapt
public void unionAdapt(Interval i)
Description copied from class:IntDomainIt adds interval of values to the domain.- Overrides:
unionAdaptin classIntDomain- Parameters:
i- Interval which needs to be added to the domain.
-
unionAdapt
public void unionAdapt(int min, int max)Description copied from class:IntDomainIt adds all values between min and max to the domain.- Specified by:
unionAdaptin classIntDomain- Parameters:
min- the left bound of the interval being added.max- the right bound of the interval being added.
-
unionAdapt
public void unionAdapt(int value)
Description copied from class:IntDomainIt adds a values to the domain.- Overrides:
unionAdaptin classIntDomain- Parameters:
value- value being added to the domain.
-
valueEnumeration
public ValueEnumeration valueEnumeration()
Description copied from class:IntDomainIt returns value enumeration of the domain values.- Specified by:
valueEnumerationin classIntDomain- Returns:
- valueEnumeration which can be used to enumerate one by one value from this domain.
-
checkInvariants
public java.lang.String checkInvariants()
Description copied from class:DomainIt checks if the domain has correct state.- Specified by:
checkInvariantsin classDomain- Returns:
- null if everything is ok, otherwise a string describing the problem.
-
clear
public void clear()
Description copied from class:DomainIt removes all elements.
-
domainID
public int domainID()
Description copied from class:DomainIt returns an unique identifier of the domain.
-
isEmpty
public boolean isEmpty()
Description copied from class:DomainIt returns true if given domain is empty.
-
isNumeric
public boolean isNumeric()
Description copied from class:DomainIt specifies if domain is a finite domain of numeric values (integers).
-
isSparseRepresentation
public boolean isSparseRepresentation()
Description copied from class:DomainIt specifies if the domain type is more suited to representing sparse domain.- Specified by:
isSparseRepresentationin classDomain- Returns:
- true if sparse, false otherwise.
-
cloneLight
public SmallDenseDomain cloneLight()
It clones the domain object, only data responsible for encoding domain values is cloned. All other fields must be set separately.- Specified by:
cloneLightin classIntDomain- Returns:
- It returns a clone of this domain.
-
removeLevel
public void removeLevel(int level, Var var)Description copied from class:DomainIt removes the specified level. This function may re-instantiate the old copy of the domain (previous value) or recover from changes done at stamp level to get the previous value at level lower at provided level.- Specified by:
removeLevelin classDomain- Parameters:
level- the level which is being removed.var- the variable to which this domain belonged to.
-
singleton
public boolean singleton()
Description copied from class:DomainIt returns true if given domain has only one element.
-
sizeConstraintsOriginal
public int sizeConstraintsOriginal()
Description copied from class:DomainIt returns all constraints which are associated with variable, even the ones which are already satisfied.- Specified by:
sizeConstraintsOriginalin classDomain- Returns:
- the number of constraints attached to the original domain of the variable associated with this domain.
-
toString
public java.lang.String toString()
Description copied from class:DomainIt returns string description of the domain (only values in the domain).
-
toStringConstraints
public java.lang.String toStringConstraints()
Description copied from class:DomainIt returns string description of the constraints attached to the domain.- Specified by:
toStringConstraintsin classDomain- Returns:
- the string description.
-
toStringFull
public java.lang.String toStringFull()
Description copied from class:DomainIt returns complete string description containing all relevant information about the domain.- Specified by:
toStringFullin classDomain- Returns:
- complete description of the domain.
-
getRandomValue
public int getRandomValue()
Description copied from class:IntDomainIt returns a random value from the domain.- Overrides:
getRandomValuein classIntDomain- Returns:
- random value.
-
contains
public boolean contains(int min, int max)Description copied from class:IntDomainIt checks if an interval min..max belongs to the domain.
-
shift
public void shift(int shift)
It shifts the domain.- Parameters:
shift- how much should the domain be shifted.
-
toIntervalDomain
public IntervalDomain toIntervalDomain()
-
-