Package org.jacop.core
Class IntervalDomain
java.lang.Object
org.jacop.core.Domain
org.jacop.core.IntDomain
org.jacop.core.IntervalDomain
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
GCC.XDomain
Defines interval of numbers which is part of FDV definition which consist of
one or several intervals.
- Version:
- 4.8
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IntervalDomain
An empty domain, so no constant creation of empty domains is required.private static final Random
Interval[]
The values of the domain are encoded as a list of intervals.int
It specifies number of intervals needed to encode 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
ConstructorsConstructorDescriptionEmpty constructor, does not initialize anything.IntervalDomain
(int size) It creates an empty domain, with at least specified number of places in an array list for intervals.IntervalDomain
(int min, int max) It creates domain with all values between min and max. -
Method Summary
Modifier and TypeMethodDescriptionvoid
It adds values as specified by the parameter to the domain.void
addLastElement
(int i) It adds a value to the domain.It is a function to check if the object is in consistent state.void
clear()
It removes all elements.clone()
It clones the domain object.It clones the domain object, only data responsible for encoding domain values is cloned.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
It specifies if the current domain contains the domain given as a parameter.private int
div
(int A, int B) int
domainID()
It returns an unique identifier of the domain.boolean
It checks if the domain is equal to the supplied domain.int
getElementAt
(int index) It access the element at the specified position.getInterval
(int position) It returns required interval.It returns domain at earlier level at which the change has occurred.int
It returns a random value from the domain.int
getSize()
It returns the size of the domain.void
It updates the domain to have values only within the interval min..max.void
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
It updates the domain according to the maximum value and stamp value.void
It updates the domain according to the minimum value and stamp value.void
It updates the domain to contain the elements as specifed by the domain, which is shifted.intersect
(int min, int max) In intersects current domain with the domain min..max.It interesects current domain with the one given as a parameter.int
intersectAdapt
(int min, int max) It computes an intersection of this domain with an interval [min..max].int
intersectAdapt
(IntDomain domain) It computes an intersection with a given domain and stores it in this domain.It returns interval enumeration of the domain values.int
intervalNo
(int value) It specifies the position of the interval which contains specified value.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
It specifies if domain is a finite domain of numeric values (integers).boolean
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.multiply
(int mul) {1..4} * 6 = {6, 12, 18, 24}int
nextValue
(int value) It gives next value in the domain from the given value (lexigraphical ordering).int
It returns the number intervals into which this domain is split.int
previousValue
(int value) It gives previous value in the domain from the given one (lexigraphical ordering).recentDomainPruning
(int storeLevel) It removes a constraint from a domain, it should only be called by removeConstraint function of Variable object.void
removeInterval
(int position) It removes the counter-th interval from the domain.void
removeLevel
(int level, Var var) It removes a level of a domain.int
rightElement
(int intervalNo) It returns the left most element of the given interval.void
setDomain
(int min, int max) It sets the domain to all values between min and max.void
It sets the domain to the specified domain.boolean
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
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.subtract
(int value) It intersects with the domain which is a complement of value.subtract
(int min, int max) It subtracts min..max from current domain and returns the result.It subtracts domain from current domain and returns the result.void
subtractAdapt
(int value) It removes value from the domain.void
subtractAdapt
(int minValue, int maxValue) It removes all values between min and max to the domain.toString()
It returns string description of the domain (only values in the domain).It returns string description of the constraints attached to the domain.It returns complete string description containing all relevant information.union
(int value) It computes union of dom1 and value and returns the result.union
(int min, int max) It computes union of current domain and an interval min..max;It computes union of dom1 from dom2 and returns the result.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.int
unionAdapt
(IntDomain union) It computes a union between this domain and the domain provided as a parameter.void
It adds interval of values to the domain.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, value
Methods inherited from class org.jacop.core.Domain
constraints, noSearchConstraints, searchConstraints, setStamp, sizeConstraints, stamp
-
Field Details
-
intervals
The values of the domain are encoded as a list of intervals. -
size
public int sizeIt specifies number of intervals needed to encode the domain. -
emptyDomain
An empty domain, so no constant creation of empty domains is required. -
generator
-
-
Constructor Details
-
IntervalDomain
public IntervalDomain()Empty constructor, does not initialize anything. -
IntervalDomain
public IntervalDomain(int size) It creates an empty domain, with at least specified number of places in an array list for intervals.- Parameters:
size
- defines the initial size of an array storing the intervals.
-
IntervalDomain
public IntervalDomain(int min, int max) It creates domain with all values between min and max.- Parameters:
min
- defines the left bound of a domain.max
- defines the right bound of a domain.
-
-
Method Details
-
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
-
unionAdapt
It adds interval of values to the domain. It adds at the end without checks for the correctness of domain representation.- Overrides:
unionAdapt
in classIntDomain
- Parameters:
i
- Interval which needs to be added to the domain.
-
addLastElement
public void addLastElement(int i) It adds a value to the domain. It adds at the end without checks for the correctness of domain representation.- Parameters:
i
- the element to be added as the lase element of the domain
-
addDom
It adds values as specified by the parameter to the domain. The input parameter can not be an empty set. -
unionAdapt
public void unionAdapt(int min, int max) 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.
-
isIntersecting
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.
-
clear
public void clear()It removes all elements. -
cloneLight
It clones the domain object, only data responsible for encoding domain values is cloned. All other fields must be set separately.- Specified by:
cloneLight
in classIntDomain
- Returns:
- It returns a clone of this domain.
-
clone
It clones the domain object. -
contains
It specifies if the current domain contains the domain given as a parameter. It assumes that input parameter does not represent an empty domain. -
complement
It creates a complement of a domain.- Specified by:
complement
in classIntDomain
- Returns:
- it returns the complement of this domain.
-
contains
public boolean contains(int value) It checks if value belongs to the domain. -
nextValue
public int nextValue(int value) It gives next value in the domain from the given value (lexigraphical ordering). The provided value does not have to belong to the domain. If no value can be found then returns the same value. -
div
private int div(int A, int B) -
valueEnumeration
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.
-
intervalEnumeration
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.
-
eq
It checks if the domain is equal to the supplied domain. -
getSize
public int getSize()It returns the size of the domain. -
intersect
It interesects current domain with the one given as a parameter. -
intersect
In intersects current domain with the domain min..max. -
subtract
Description copied from class:IntDomain
It intersects with the domain which is a complement of value. -
isEmpty
public boolean isEmpty()It returns true if given domain is empty. -
max
public int max()It returns the maximum value in a domain. -
min
public int min()It returns the minimum value in a domain. -
multiply
{1..4} * 6 = {6, 12, 18, 24}- Parameters:
mul
- the multiplier constant.- Returns:
- the domain after multiplication.
-
removeInterval
public void removeInterval(int position) It removes the counter-th interval from the domain.- Parameters:
position
- it specifies the position of the removed interval.
-
setDomain
It sets the domain to the specified domain. -
setDomain
public void setDomain(int min, int max) It sets the domain to all values between min and max. -
singleton
public boolean singleton()It returns true if given domain has only one element. -
singleton
public boolean singleton(int c) It returns true if given domain has only one element equal c. -
subtract
It subtracts domain from current domain and returns the result. -
subtract
It subtracts min..max from current domain and returns the result. -
union
It computes union of dom1 from dom2 and returns the result. -
union
It computes union of current domain and an interval min..max; -
union
It computes union of dom1 and value and returns the result. -
toString
It returns string description of the domain (only values in the domain). -
toStringConstraints
It returns string description of the constraints attached to the domain.- Specified by:
toStringConstraints
in classDomain
- Returns:
- the string description.
-
toStringFull
It returns complete string description containing all relevant information.- Specified by:
toStringFull
in classDomain
- Returns:
- complete description of the domain.
-
inMin
It updates the domain according to the minimum value and stamp value. It informs the variable of a change if it occurred. -
inMax
It updates the domain according to the maximum value and stamp value. It informs the variable of a change if it occurred. -
in
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
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. -
noIntervals
public int noIntervals()It returns the number intervals into which this domain is split.- Specified by:
noIntervals
in classIntDomain
- Returns:
- the number of intervals in the domain.
-
intervalNo
public int intervalNo(int value) It specifies the position of the interval which contains specified value.- Parameters:
value
- value for which an interval containing it is searched.- Returns:
- the position of the interval containing the specified value.
-
getInterval
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.
-
inComplement
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
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).
-
inShift
It updates the domain to contain the elements as specifed by the domain, which is shifted. E.g. {1..4} + 3 = 4..7 -
domainID
public int domainID()It returns an unique identifier of the domain. -
isSparseRepresentation
public boolean isSparseRepresentation()It specifies if the domain type is more suited to representing sparse domain.- Specified by:
isSparseRepresentation
in classDomain
- Returns:
- true if sparse, false otherwise.
-
isNumeric
public boolean isNumeric()It specifies if domain is a finite domain of numeric values (integers). -
leftElement
public int leftElement(int intervalNo) 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.
-
rightElement
public int rightElement(int intervalNo) It returns the left most element of the given interval.- Overrides:
rightElement
in classIntDomain
- Parameters:
intervalNo
- the interval number.- Returns:
- the right bound of the specified interval.
-
removeLevel
It removes a level of a domain. If domain is represented as a list of domains, the domain pointer within variable will be updated.- Specified by:
removeLevel
in classDomain
- Parameters:
level
- the level which is being removed.var
- the variable to which this domain belonged to.
-
recentDomainPruning
It removes a constraint from a domain, it should only be called by removeConstraint function of Variable object.- 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.
-
sizeConstraintsOriginal
public int sizeConstraintsOriginal()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.
-
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
It is a function to check if the object is in consistent state.- Specified by:
checkInvariants
in classDomain
- Returns:
- String describing the violated invariant, null if no invariant is violated.
-
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 value) Description copied from class:IntDomain
It removes value from the domain. It adapts current (this) domain.- Specified by:
subtractAdapt
in classIntDomain
- Parameters:
value
- the value for which the complement is computed
-
subtractAdapt
public void subtractAdapt(int minValue, int maxValue) Description copied from class:IntDomain
It removes all values between min and max to the domain.- Specified by:
subtractAdapt
in classIntDomain
- Parameters:
minValue
- the left bound of the interval being removed.maxValue
- the right bound of the interval being removed.
-
intersectAdapt
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:
domain
- domain with which the intersection is being computed.- Returns:
- type of event which has occurred due to the operation.
-
unionAdapt
Description copied from class:IntDomain
It computes a union between this domain and the domain provided as a parameter. This domain is changed to reflect the result.- Overrides:
unionAdapt
in classIntDomain
- Parameters:
union
- the domain with is used for the union operation with this domain.- Returns:
- it returns information about the pruning event which has occurred due to this operation.
-
intersectAdapt
public int intersectAdapt(int min, int max) 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:
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.
-
sizeOfIntersection
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.
-
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.
-
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.
-