Package org.jacop.core
Class BoundDomain
- java.lang.Object
-
- org.jacop.core.Domain
-
- org.jacop.core.IntDomain
-
- org.jacop.core.BoundDomain
-
- All Implemented Interfaces:
java.lang.Cloneable
class BoundDomain extends IntDomain implements java.lang.Cloneable
Defines interval of numbers which is part of FDV definition which consist of one or several intervals.- Version:
- 4.8
-
-
Field Summary
Fields Modifier and Type Field Description static BoundDomain
emptyDomain
It predefines empty domain so there is no need to constantly create it when needed.private static java.util.Random
generator
int
max
The maximal value of the domain.int
min
The minimal value of the domain.-
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 BoundDomain()
It is a constructor which will create an empty Bound domain.BoundDomain(int min, int max)
Creates a new instance of BoundDomain.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDom(IntDomain domain)
It adds values as specified by the parameter to the domain.java.lang.String
checkInvariants()
It checks if the domain has correct state.void
clear()
It removes all elements.BoundDomain
clone()
It clones the domain object.BoundDomain
cloneLight()
It clones this domain.IntDomain
complement()
It creates a complement of a domain.boolean
contains(int value)
It checks if value belongs to the domain.boolean
contains(int min, int max)
It checks if an interval min..max belongs to the domain.boolean
contains(IntDomain domain)
It specifies if the current domain contains the domain given as a parameter.private int
div(int A, int B)
IntDomain
divide(int div)
It divides the domain by a given constant.int
domainID()
It returns an unique identifier of the domain.boolean
eq(IntDomain domain)
It specifies if the other int domain is equal to this one.int
getElementAt(int index)
It access the element at the specified position.Interval
getInterval(int position)
It returns required interval.IntDomain
getPreviousDomain()
It returns domain at earlier level at which the change has occurred.int
getRandomValue()
It returns a random value from the domain.int
getSize()
It returns the size of the domain.void
in(int storeLevel, Var var, int min, int max)
It updates the domain to have values only within the interval min..max.void
in(int storeLevel, Var var, IntDomain domain)
It updates the domain to have values only within the domain.void
inComplement(int storeLevel, Var var, int complement)
It updates the domain to not contain the value complement.void
inComplement(int storeLevel, Var var, int min, int max)
It updates the domain so it does not contain the supplied interval.void
inMax(int storeLevel, Var var, int max)
It updates the domain according to the maximum value and stamp value.void
inMin(int storeLevel, Var var, int min)
It updates the domain according to the minimum value and stamp value.void
inShift(int storeLevel, Var var, IntDomain domain, int shift)
It updates the domain to contain the elements as specifed by the domain, which is shifted.IntDomain
intersect(int min, int max)
In intersects current domain with the interval min..max.IntDomain
intersect(IntDomain dom)
It intersects current domain with the one given as a parameter.int
intersectAdapt(int minIntersect, int maxIntersect)
It computes an intersection of this domain with an interval [min..max].int
intersectAdapt(IntDomain intersect)
It computes an intersection with a given domain and stores it in this domain.IntervalEnumeration
intervalEnumeration()
It returns interval enumeration of the domain values.boolean
isEmpty()
It returns true if given domain is empty.boolean
isIntersecting(int min, int max)
It checks if interval min..max intersects with current domain.boolean
isIntersecting(IntDomain domain)
Checks if two domains intersect.boolean
isNumeric()
It specifies if domain is a finite domain of numeric values (integers).boolean
isSparseRepresentation()
It specifies if the domain type is more suited to representing sparse domain.int
leftElement(int intervalNo)
It returns the left most element of the given interval.int
max()
It returns the maximum value in a domain.int
min()
It returns the minimum value in a domain.IntDomain
multiply(int mul)
It multiplies the domain by a given constant.int
nextValue(int value)
It gives next value in the domain from the given one (lexigraphical ordering).int
noIntervals()
It returns number of intervals required to represent this domain.int
previousValue(int value)
It gives previous value in the domain from the given one (lexigraphical ordering).IntDomain
recentDomainPruning(int storeLevel)
It returns the values which have been removed at current store level.void
removeLevel(int level, Var var)
It removes the specified level.int
rightElement(int intervalNo)
It returns the right most element of the given interval.void
setDomain(int min, int max)
It sets this domain to contain exactly all values between min and max.void
setDomain(IntDomain domain)
It sets the domain to the specified domain.boolean
singleton()
It returns true if given domain has only one element.boolean
singleton(int c)
It returns true if given domain has only one element equal c.int
sizeConstraintsOriginal()
It returns all constraints which are associated with variable, even the ones which are already satisfied.int
sizeOfIntersection(IntDomain domain)
It computes the size of the intersection between this domain and the domain supplied as a parameter.IntDomain
subtract(int value)
It intersects with the domain which is a complement of value.BoundDomain
subtract(int min, int max)
It subtracts interval min..max.IntDomain
subtract(IntDomain domain)
It subtracts domain from current domain and returns the result.void
subtractAdapt(int complement)
It removes value from the domain.void
subtractAdapt(int min, int max)
It removes all values between min and max to the domain.java.lang.String
toString()
It returns string description of the domain (only values in the domain).java.lang.String
toStringConstraints()
It returns string description of the constraints attached to the domain.java.lang.String
toStringFull()
It returns complete string description containing all relevant information about the domain.IntDomain
union(int value)
It computes union of this domain and value.IntDomain
union(int min, int max)
It computes union of this domain and the interval.IntDomain
union(IntDomain domain)
It computes union of the supplied domain with this domain.void
unionAdapt(int value)
It adds a values to the domain.void
unionAdapt(int min, int max)
It adds all values between min and max to the domain.void
unionAdapt(Interval i)
It adds interval of values to the domain.ValueEnumeration
valueEnumeration()
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
-
min
public int min
The minimal value of the domain.
-
max
public int max
The maximal value of the domain.
-
emptyDomain
public static final BoundDomain emptyDomain
It predefines empty domain so there is no need to constantly create it when needed.
-
generator
private static final java.util.Random generator
-
-
Constructor Detail
-
BoundDomain
public BoundDomain()
It is a constructor which will create an empty Bound domain. An empty domain has minimum larger than maximum.
-
BoundDomain
public BoundDomain(int min, int max)
Creates a new instance of BoundDomain. It requires min to be smaller or equal to max.- Parameters:
min
- it specifies the left bound of the BoundDomain (inclusive).max
- it specifies the right bound of the BoundDomain (inclusive).
-
-
Method Detail
-
unionAdapt
public void unionAdapt(Interval i)
Description copied from class:IntDomain
It adds interval of values to the domain.- Overrides:
unionAdapt
in classIntDomain
- Parameters:
i
- interval for union operation
-
addDom
public void addDom(IntDomain domain)
Description copied from class:IntDomain
It adds values as specified by the parameter to the domain.
-
unionAdapt
public void unionAdapt(int min, int max)
Description copied from class:IntDomain
It adds all values between min and max to the domain.- Specified by:
unionAdapt
in classIntDomain
- Parameters:
min
- the left bound of the interval being added.max
- the right bound of the interval being added.
-
clear
public void clear()
Description copied from class:Domain
It removes all elements.
-
getPreviousDomain
public IntDomain getPreviousDomain()
Description copied from class:IntDomain
It returns domain at earlier level at which the change has occurred.- Specified by:
getPreviousDomain
in classIntDomain
- Returns:
- previous domain
-
clone
public BoundDomain clone()
Description copied from class:Domain
It clones the domain object.
-
cloneLight
public BoundDomain cloneLight()
It clones this domain.- Specified by:
cloneLight
in classIntDomain
- Returns:
- clone of this domain.
-
complement
public IntDomain complement()
Description copied from class:IntDomain
It creates a complement of a domain.- Specified by:
complement
in classIntDomain
- Returns:
- it returns the complement of this domain.
-
contains
public boolean contains(IntDomain domain)
Description copied from class:IntDomain
It specifies if the current domain contains the domain given as a parameter.
-
contains
public boolean contains(int value)
Description copied from class:IntDomain
It checks if value belongs to the domain.
-
divide
public IntDomain divide(int div)
It divides the domain by a given constant.- Parameters:
div
- the constant by which the domain should be divided.- Returns:
- the domain obtained by dividing this domain by a given constant.
-
div
private int div(int A, int B)
-
domainID
public int domainID()
Description copied from class:Domain
It returns an unique identifier of the domain.
-
eq
public boolean eq(IntDomain domain)
Description copied from class:IntDomain
It specifies if the other int domain is equal to this one.
-
getInterval
public Interval getInterval(int position)
Description copied from class:IntDomain
It returns required interval.- Specified by:
getInterval
in 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:IntDomain
It returns the size of the domain.
-
in
public void in(int storeLevel, Var var, int min, int max)
Description copied from class:IntDomain
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.
-
in
public void in(int storeLevel, Var var, IntDomain domain)
Description copied from class:IntDomain
It 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:IntDomain
It updates the domain to not contain the value complement. It informs the variable of a change if it occurred.- Overrides:
inComplement
in 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 min, int max)
Description copied from class:IntDomain
It updates the domain so it does not contain the supplied interval. It informs the variable of a change if it occurred.- Specified by:
inComplement
in classIntDomain
- Parameters:
storeLevel
- level of the store at which the update occurs.var
- variable for which this domain is used.min
- the left bound of the interval (inclusive).max
- the right bound of the interval (inclusive).
-
inMax
public void inMax(int storeLevel, Var var, int max)
Description copied from class:IntDomain
It 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:IntDomain
It 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:IntDomain
It updates the domain to contain the elements as specifed by the domain, which is shifted. E.g. {1..4} + 3 = 4..7
-
intersect
public IntDomain intersect(IntDomain dom)
Description copied from class:IntDomain
It intersects current domain with the one given as a parameter.
-
intersect
public IntDomain intersect(int min, int max)
Description copied from class:IntDomain
In intersects current domain with the interval min..max.
-
subtract
public IntDomain subtract(int value)
Description copied from class:IntDomain
It intersects with the domain which is a complement of value.
-
intervalEnumeration
public IntervalEnumeration intervalEnumeration()
Description copied from class:IntDomain
It returns interval enumeration of the domain values.- Specified by:
intervalEnumeration
in classIntDomain
- Returns:
- intervalEnumeration which can be used to enumerate intervals in this domain.
-
isEmpty
public boolean isEmpty()
Description copied from class:Domain
It returns true if given domain is empty.
-
isIntersecting
public boolean isIntersecting(IntDomain domain)
Description copied from class:IntDomain
Checks if two domains intersect.- Overrides:
isIntersecting
in 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:IntDomain
It checks if interval min..max intersects with current domain.- Specified by:
isIntersecting
in 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.
-
isNumeric
public boolean isNumeric()
Description copied from class:Domain
It specifies if domain is a finite domain of numeric values (integers).
-
isSparseRepresentation
public boolean isSparseRepresentation()
Description copied from class:Domain
It specifies if the domain type is more suited to representing sparse domain.- Specified by:
isSparseRepresentation
in classDomain
- Returns:
- true if sparse, false otherwise.
-
leftElement
public int leftElement(int intervalNo)
Description copied from class:IntDomain
It returns the left most element of the given interval.- Overrides:
leftElement
in classIntDomain
- Parameters:
intervalNo
- the interval number.- Returns:
- the left bound of the specified interval.
-
max
public int max()
Description copied from class:IntDomain
It returns the maximum value in a domain.
-
min
public int min()
Description copied from class:IntDomain
It returns the minimum value in a domain.
-
multiply
public IntDomain multiply(int mul)
It multiplies the domain by a given constant.- Parameters:
mul
- a factor by which the domain is being multiplied.- Returns:
- Domain created by multiplication of this domain.
-
nextValue
public int nextValue(int value)
Description copied from class:IntDomain
It 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:IntDomain
It returns number of intervals required to represent this domain.- Specified by:
noIntervals
in classIntDomain
- Returns:
- the number of intervals in the domain.
-
recentDomainPruning
public IntDomain recentDomainPruning(int storeLevel)
Description copied from class:IntDomain
It returns the values which have been removed at current store level.- Specified by:
recentDomainPruning
in 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.
-
removeLevel
public void removeLevel(int level, Var var)
Description copied from class:Domain
It 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:
removeLevel
in classDomain
- Parameters:
level
- the level which is being removed.var
- the variable to which this domain belonged to.
-
rightElement
public int rightElement(int intervalNo)
Description copied from class:IntDomain
It returns the right most element of the given interval.- Overrides:
rightElement
in classIntDomain
- Parameters:
intervalNo
- the interval number.- Returns:
- the right bound of the specified interval.
-
setDomain
public void setDomain(IntDomain domain)
Description copied from class:IntDomain
It sets the domain to the specified domain.
-
setDomain
public void setDomain(int min, int max)
Description copied from class:IntDomain
It sets this domain to contain exactly all values between min and max.
-
singleton
public boolean singleton()
Description copied from class:Domain
It returns true if given domain has only one element.
-
singleton
public boolean singleton(int c)
Description copied from class:IntDomain
It returns true if given domain has only one element equal c.
-
sizeConstraintsOriginal
public int sizeConstraintsOriginal()
Description copied from class:Domain
It returns all constraints which are associated with variable, even the ones which are already satisfied.- Specified by:
sizeConstraintsOriginal
in classDomain
- Returns:
- the number of constraints attached to the original domain of the variable associated with this domain.
-
subtract
public IntDomain subtract(IntDomain domain)
Description copied from class:IntDomain
It subtracts domain from current domain and returns the result.
-
subtract
public BoundDomain subtract(int min, int max)
Description copied from class:IntDomain
It subtracts interval min..max.
-
toString
public java.lang.String toString()
Description copied from class:Domain
It returns string description of the domain (only values in the domain).
-
toStringConstraints
public java.lang.String toStringConstraints()
Description copied from class:Domain
It returns string description of the constraints attached to the domain.- Specified by:
toStringConstraints
in classDomain
- Returns:
- the string description.
-
toStringFull
public java.lang.String toStringFull()
Description copied from class:Domain
It returns complete string description containing all relevant information about the domain.- Specified by:
toStringFull
in classDomain
- Returns:
- complete description of the domain.
-
union
public IntDomain union(IntDomain domain)
Description copied from class:IntDomain
It computes union of the supplied domain with this domain.
-
union
public IntDomain union(int min, int max)
Description copied from class:IntDomain
It computes union of this domain and the interval.
-
union
public IntDomain union(int value)
Description copied from class:IntDomain
It computes union of this domain and value.
-
valueEnumeration
public ValueEnumeration valueEnumeration()
Description copied from class:IntDomain
It returns value enumeration of the domain values.- Specified by:
valueEnumeration
in classIntDomain
- Returns:
- valueEnumeration which can be used to enumerate one by one value from this domain.
-
previousValue
public int previousValue(int value)
Description copied from class:IntDomain
It 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:
previousValue
in classIntDomain
- Parameters:
value
- before which a value is seeked for.- Returns:
- it returns the value before the one specified as a parameter.
-
checkInvariants
public java.lang.String checkInvariants()
Description copied from class:Domain
It checks if the domain has correct state.- Specified by:
checkInvariants
in classDomain
- Returns:
- It returns the information about the first invariant which does not hold or null otherwise.
-
unionAdapt
public void unionAdapt(int value)
Description copied from class:IntDomain
It adds a values to the domain.- Overrides:
unionAdapt
in classIntDomain
- Parameters:
value
- value being added to the domain.
-
subtractAdapt
public void subtractAdapt(int complement)
Description copied from class:IntDomain
It removes value from the domain. It adapts current (this) domain.- Specified by:
subtractAdapt
in classIntDomain
- Parameters:
complement
- the value for which the complement is computed
-
subtractAdapt
public void subtractAdapt(int min, int max)
Description copied from class:IntDomain
It removes all values between min and max to the domain.- Specified by:
subtractAdapt
in classIntDomain
- Parameters:
min
- the left bound of the interval being removed.max
- the right bound of the interval being removed.
-
intersectAdapt
public int intersectAdapt(IntDomain intersect)
Description copied from class:IntDomain
It computes an intersection with a given domain and stores it in this domain.- Specified by:
intersectAdapt
in classIntDomain
- Parameters:
intersect
- domain with which the intersection is being computed.- Returns:
- type of event which has occurred due to the operation.
-
intersectAdapt
public int intersectAdapt(int minIntersect, int maxIntersect)
Description copied from class:IntDomain
It computes an intersection of this domain with an interval [min..max]. It adapts this domain to the result of the intersection.- Specified by:
intersectAdapt
in classIntDomain
- Parameters:
minIntersect
- the minimum value of the interval used in the intersection computation.maxIntersect
- 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.
-
getElementAt
public int getElementAt(int index)
Description copied from class:IntDomain
It access the element at the specified position.- Specified by:
getElementAt
in classIntDomain
- Parameters:
index
- the position of the element, indexing starts from 0.- Returns:
- the value at a given position in the domain.
-
sizeOfIntersection
public int sizeOfIntersection(IntDomain domain)
Description copied from class:IntDomain
It computes the size of the intersection between this domain and the domain supplied as a parameter.- Overrides:
sizeOfIntersection
in classIntDomain
- Parameters:
domain
- the domain with which the intersection is computed.- Returns:
- the size of the intersection.
-
getRandomValue
public int getRandomValue()
Description copied from class:IntDomain
It returns a random value from the domain.- Overrides:
getRandomValue
in classIntDomain
- Returns:
- random value.
-
contains
public boolean contains(int min, int max)
Description copied from class:IntDomain
It checks if an interval min..max belongs to the domain.
-
-