Package org.jacop.set.core
Class SetDomain
- java.lang.Object
-
- org.jacop.core.Domain
-
- org.jacop.set.core.SetDomain
-
- Direct Known Subclasses:
BoundSetDomain
public abstract class SetDomain extends Domain
Defines a set interval determined by a least upper bound(lub) and a greatest lower bound(glb). The domain consist of zero, one or several sets.- Version:
- 4.7
-
-
Field Summary
Fields Modifier and Type Field Description static int
ANY
Any event.static int
BOUND
Bound event.static int
CARDINALITY
It specifies event that has changed the cardinality of the set.static SetDomain
emptyDomain
It predefines empty domain so there is no need to constantly create it when needed.(package private) static int[][]
eventsInclusion
It specifies for each event what other events are subsumed by this event.static int
GLB
It specifies event that GLB has grown.static int
GROUND
It specifies event that Set variable became singleton.static int
LUB
It specifies event that LUB has shrank.static int
MaxElement
It specifies the maximum element in the set domain.static int
MinElement
It specifies the minimum element in the set domain.SetDomain
previousDomain
It specifies the previous domain which was used by this domain.static int
SetDomainID
It specifies an unique ID for the domain.-
Fields inherited from class org.jacop.core.Domain
failException, modelConstraints, modelConstraintsToEvaluate, NOINFO, NONE, searchConstraints, searchConstraintsCloned, searchConstraintsToEvaluate, stamp
-
-
Constructor Summary
Constructors Constructor Description SetDomain()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addDom(int min, int max)
Adds an interval [min..max] to the domain.abstract void
addDom(IntDomain set)
Adds a set of values to the set of possible values used within this set domain.abstract void
addDom(Interval i)
Adds an interval to the lub.abstract void
addDom(SetDomain domain)
Adds a set domain to this set domain.abstract IntDomain
card()
Returns the cardinality of the setDomain as [glb.card(), lub.card()]abstract java.lang.String
checkInvariants()
It checks if the domain has correct state.abstract void
clear()
Sets the domain to an empty SetDomain.abstract SetDomain
cloneLight()
It clones the domain object, only data responsible for encoding domain values is cloned.abstract boolean
contains(int value)
It checks if value belongs to the domain of the set.abstract boolean
contains(IntDomain set)
It checks if the supplied set or setDomain is still potentially a subset of this domain.abstract boolean
contains(SetDomain domain)
It checks if the supplied set domain is a subset of this domain.abstract int
domainID()
It returns an unique identifier of the domain.abstract boolean
eq(SetDomain domain)
It checks if the domain is equal to the supplied domain.int[]
getEventsInclusion(int pruningEvent)
It helps to specify what events should be executed if a given event occurs.abstract IntDomain
glb()
It returns the least upper bound of the domain.void
in(int level, Var var, Domain domain)
It enforces that this domain is included within the specified domain.abstract void
in(int storeLevel, SetVar var, IntDomain glb, IntDomain lub)
This function is equivalent to in(int storeLevel, Variable var, int min, int max).abstract void
in(int storeLevel, SetVar var, SetDomain domain)
It updates the domain to have values only within the domain.abstract void
inCardinality(int level, SetVar a, int i, int j)
It restricts the possible cardinality of the set domain.abstract void
inGLB(int level, SetVar var, int element)
It adds if necessary an element to glb.abstract void
inGLB(int level, SetVar var, IntDomain domain)
It specifies what elements must be in GLB.abstract void
inLUB(int level, SetVar var, IntDomain domain)
It specifies what elements can be in LUB.abstract void
inLUBComplement(int level, SetVar var, int element)
It specifies the element which can *NOT* be used as an element within a set assign to a set variable.abstract SetDomain
intersect(IntDomain set)
It intersects current domain with the set of allowed values to be taken by the set domain.abstract SetDomain
intersect(SetDomain domain)
It intersects current domain with the one given as a parameter.abstract void
inValue(int level, SetVar var, IntDomain set)
It assigns a set variable to the specified value.abstract boolean
isEmpty()
It returns true if given domain is empty.abstract boolean
isIntersecting(int min, int max)
In intersects current domain with the interval min..max.abstract boolean
isIntersecting(SetDomain domain)
It returns true if this domain intersects with the supplied domain.abstract boolean
isNumeric()
A set is never numericabstract boolean
isSparseRepresentation()
A set is not sparseabstract IntDomain
lub()
It returns the least upper bound of the domain.int
noConstraints()
It returns the number of constraintsvoid
putModelConstraint(int storeLevel, Var var, Constraint C, int pruningEvent)
It adds a constraint to a domain, it should only be called by putConstraint function of Variable object.void
putSearchConstraint(int storeLevel, Var var, Constraint C)
It adds a constraint to a domain, it should only be called by putConstraint function of Variable object.SetDomain
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.void
removeModelConstraint(int storeLevel, Var var, Constraint C)
It removes a constraint from a domain, it should only be called by removeConstraint function of Variable object.void
removeSearchConstraint(int storeLevel, Var var, int position, Constraint C)
It removes a constraint from a domain, it should only be called by removeConstraint function of Variable object.abstract void
setDomain(int min, int max)
It sets the domain to contain any values in between min and max.abstract void
setDomain(SetDomain domain)
It sets the domain to the specified domain.abstract boolean
singleton()
It returns true if given domain has only one set-element.abstract boolean
singleton(IntDomain set)
It check whether the set domain is singleton and its value is equal to the specified set.int
sizeConstraintsOriginal()
It returns all constraints which are associated with variable, even the ones which are already satisfied.abstract SetDomain
subtract(int value)
It removes the value from any set allowed to be taken by this set domain.abstract SetDomain
subtract(int min, int max)
It subtracts the set {min..max}.abstract SetDomain
subtract(SetDomain domain)
It subtracts domain from current domain and returns the result.java.lang.String
toStringConstraints()
It returns string description of the constraints attached to the domain.java.lang.String
toStringFull()
not implemented.abstract SetDomain
union(int value)
It computes union of this domain and value.abstract SetDomain
union(int min, int max)
It computes union of this domain and the interval.abstract SetDomain
union(SetDomain domain)
It computes union of the supplied domain with this domain.abstract ValueEnumeration
valueEnumeration()
It returns value enumeration of the domain values.-
Methods inherited from class org.jacop.core.Domain
clone, constraints, getSize, noSearchConstraints, searchConstraints, setStamp, singleton, sizeConstraints, stamp, toString
-
-
-
-
Field Detail
-
MinElement
public static final int MinElement
It specifies the minimum element in the set domain.
-
MaxElement
public static final int MaxElement
It specifies the maximum element in the set domain.
-
SetDomainID
public static final int SetDomainID
It specifies an unique ID for the domain.- See Also:
- Constant Field Values
-
GROUND
public static final int GROUND
It specifies event that Set variable became singleton.- See Also:
- Constant Field Values
-
GLB
public static final int GLB
It specifies event that GLB has grown.- See Also:
- Constant Field Values
-
LUB
public static final int LUB
It specifies event that LUB has shrank.- See Also:
- Constant Field Values
-
BOUND
public static final int BOUND
Bound event. Both bounds have changed.- See Also:
- Constant Field Values
-
ANY
public static final int ANY
Any event.- See Also:
- Constant Field Values
-
CARDINALITY
public static final int CARDINALITY
It specifies event that has changed the cardinality of the set.- See Also:
- Constant Field Values
-
eventsInclusion
static final int[][] eventsInclusion
It specifies for each event what other events are subsumed by this event. Possibly implement this by bit flags in int.
-
previousDomain
public SetDomain previousDomain
It specifies the previous domain which was used by this domain. The old domain is stored here and can be easily restored if necessary.
-
emptyDomain
public static final SetDomain emptyDomain
It predefines empty domain so there is no need to constantly create it when needed.
-
-
Method Detail
-
getEventsInclusion
public int[] getEventsInclusion(int pruningEvent)
It helps to specify what events should be executed if a given event occurs.- Specified by:
getEventsInclusion
in classDomain
- Parameters:
pruningEvent
- the pruning event for which we want to know what events it encompasses.- Returns:
- an array specifying what events should be included given this event.
-
addDom
public abstract void addDom(Interval i)
Adds an interval to the lub.- Parameters:
i
- The interval to be added to the lub.
-
addDom
public abstract void addDom(IntDomain set)
Adds a set of values to the set of possible values used within this set domain. It changes the cardinality too to avoid cardinality constraining the domain.- Parameters:
set
- a set of values which can be taken by a set domain.
-
addDom
public abstract void addDom(SetDomain domain)
Adds a set domain to this set domain. This operation may add more sets than intended if for example used in the context of BoundSetDomain which can not represent arbitrary union of two sets.- Parameters:
domain
- a set domain containing information what sets are being added.
-
addDom
public abstract void addDom(int min, int max)
Adds an interval [min..max] to the domain.- Parameters:
min
- min value in the setmax
- max value in the set
-
card
public abstract IntDomain card()
Returns the cardinality of the setDomain as [glb.card(), lub.card()]- Returns:
- The cardinality of the setDomain given as a boundDomain.
-
clear
public abstract void clear()
Sets the domain to an empty SetDomain.
-
contains
public abstract boolean contains(IntDomain set)
It checks if the supplied set or setDomain is still potentially a subset of this domain.- Parameters:
set
- the set for which we check the inclusion relation.- Returns:
- true, if this domain contains provided set, false otherwise.
-
contains
public abstract boolean contains(SetDomain domain)
It checks if the supplied set domain is a subset of this domain.- Parameters:
domain
- the domain for which we check the inclusion relation.- Returns:
- true, if this domain contains provided domain, false otherwise.
-
contains
public abstract boolean contains(int value)
It checks if value belongs to the domain of the set.- Parameters:
value
- value which is checked.- Returns:
- true if the value being checked can still be included in the set, false otherwise.
-
domainID
public abstract int domainID()
It returns an unique identifier of the domain.
-
eq
public abstract boolean eq(SetDomain domain)
It checks if the domain is equal to the supplied domain.- Parameters:
domain
- against which the equivalence test is performed.- Returns:
- true if suppled domain has the same elements as this domain.
-
in
public abstract void in(int storeLevel, SetVar var, IntDomain glb, IntDomain lub)
This function is equivalent to in(int storeLevel, Variable var, int min, int max).- Parameters:
storeLevel
- the level of the store at which the change occurrs.var
- the set variable for which the domain may change.glb
- the greatest lower bound of the domain.lub
- the least upper bound of the domain.
-
in
public abstract void in(int storeLevel, SetVar var, SetDomain domain)
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.- Parameters:
storeLevel
- level of the store at which the update occurs.var
- variable for which this domain is used.domain
- the domain according to which the domain is updated.
-
intersect
public abstract SetDomain intersect(SetDomain domain)
It intersects current domain with the one given as a parameter.- Parameters:
domain
- domain with which the intersection needs to be computed.- Returns:
- the intersection between supplied domain and this domain.
-
intersect
public abstract SetDomain intersect(IntDomain set)
It intersects current domain with the set of allowed values to be taken by the set domain.- Parameters:
set
- set of values which are allowed to be used within a set.- Returns:
- the intersection of this domain with the set of allowed values.
-
isEmpty
public abstract boolean isEmpty()
It returns true if given domain is empty.
-
isIntersecting
public abstract boolean isIntersecting(SetDomain domain)
It returns true if this domain intersects with the supplied domain.- Parameters:
domain
- the domain against which the intersection is being checked.- Returns:
- true if the given domain intersects this domain.
-
isIntersecting
public abstract boolean isIntersecting(int min, int max)
In intersects current domain with the interval min..max.- Parameters:
min
- the left bound of the interval (inclusive)max
- the right bound of the interval (inclusive)- Returns:
- the intersection between the specified interval and this domain.
-
isNumeric
public abstract boolean isNumeric()
A set is never numeric
-
isSparseRepresentation
public abstract boolean isSparseRepresentation()
A set is not sparse- Specified by:
isSparseRepresentation
in classDomain
- Returns:
- false
-
lub
public abstract IntDomain lub()
It returns the least upper bound of the domain.- Returns:
- the least upper bound of the domain.
-
glb
public abstract IntDomain glb()
It returns the least upper bound of the domain.- Returns:
- the least upper bound of the domain.
-
cloneLight
public abstract SetDomain 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 classDomain
- Returns:
- return a clone of the domain. It aims at getting domain of the proper class type.
-
putModelConstraint
public void putModelConstraint(int storeLevel, Var var, Constraint C, int pruningEvent)
It adds a constraint to a domain, it should only be called by putConstraint function of Variable object. putConstraint function from Variable must make a copy of a vector of constraints if vector was not cloned.- Specified by:
putModelConstraint
in classDomain
- Parameters:
storeLevel
- the level at which the model constraint is to be added.var
- variable to which the constraint is attached to.C
- the constraint which is being attached to a variable.pruningEvent
- the type of the prunning event required to check the consistency of the attached constraint.
-
putSearchConstraint
public void putSearchConstraint(int storeLevel, Var var, Constraint C)
It adds a constraint to a domain, it should only be called by putConstraint function of Variable object. putConstraint function from Variable must make a copy of a vector of constraints if vector was not cloned.- Specified by:
putSearchConstraint
in classDomain
- Parameters:
storeLevel
- the level at which the search constraint is to be added.var
- variable to which the constraint is attached to.C
- the constraint which is being attached to a variable.
-
recentDomainPruning
public SetDomain recentDomainPruning(int storeLevel)
It returns the values which have been removed at current store level.- 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)
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.
-
removeSearchConstraint
public void removeSearchConstraint(int storeLevel, Var var, int position, Constraint C)
It removes a constraint from a domain, it should only be called by removeConstraint function of Variable object.- Specified by:
removeSearchConstraint
in classDomain
- Parameters:
storeLevel
- specifies the current level of the store, from which it should be removed.var
- specifies variable for which the constraint is being removed.position
- specifies the position of the removed constraint.C
- the constraint which is being removed.
-
removeModelConstraint
public void removeModelConstraint(int storeLevel, Var var, Constraint C)
It removes a constraint from a domain, it should only be called by removeConstraint function of Variable object.- Specified by:
removeModelConstraint
in classDomain
- Parameters:
storeLevel
- specifies the current level of the store, from which it should be removed.var
- specifies variable for which the constraint is being removed.C
- the constraint which is being removed.
-
setDomain
public abstract void setDomain(SetDomain domain)
It sets the domain to the specified domain.- Parameters:
domain
- the domain from which this domain takes all elements.
-
setDomain
public abstract void setDomain(int min, int max)
It sets the domain to contain any values in between min and max.- Parameters:
min
- the minimum value allowed to be taken within the set.max
- the maximal value allowed to be taken within the set.
-
singleton
public abstract boolean singleton()
It returns true if given domain has only one set-element.
-
singleton
public abstract boolean singleton(IntDomain set)
It check whether the set domain is singleton and its value is equal to the specified set.- Parameters:
set
- the set for which we check if it is equal to a value taken by this set domain.- Returns:
- true, if this set domain is equal to supplied set, false otherwise.
-
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.
-
subtract
public abstract SetDomain subtract(SetDomain domain)
It subtracts domain from current domain and returns the result.- Parameters:
domain
- the domain which is subtracted from this domain.- Returns:
- the result of the subtraction.
-
subtract
public abstract SetDomain subtract(int min, int max)
It subtracts the set {min..max}.- Parameters:
min
- the left bound of the set.max
- the right bound of the set.- Returns:
- the result of the subtraction.
-
subtract
public abstract SetDomain subtract(int value)
It removes the value from any set allowed to be taken by this set domain.- Parameters:
value
- value which can not be used within any set value assigned to this set domain.- Returns:
- the domain which does not allow specified value to be used.
-
toStringConstraints
public java.lang.String toStringConstraints()
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()
not implemented.- Specified by:
toStringFull
in classDomain
- Returns:
- complete description of the domain.
-
union
public abstract SetDomain union(SetDomain domain)
It computes union of the supplied domain with this domain.- Parameters:
domain
- the domain for which the union is computed.- Returns:
- the union of this domain with the supplied one.
-
union
public abstract SetDomain union(int min, int max)
It computes union of this domain and the interval.- Parameters:
min
- the left bound of the interval (inclusive).max
- the right bound of the interval (inclusive).- Returns:
- the union of this domain and the interval.
-
union
public abstract SetDomain union(int value)
It computes union of this domain and value.- Parameters:
value
- it specifies the value which is being added.- Returns:
- domain which is a union of this one and the value.
-
valueEnumeration
public abstract ValueEnumeration valueEnumeration()
It returns value enumeration of the domain values.- Specified by:
valueEnumeration
in classDomain
- Returns:
- valueEnumeration which can be used to enumerate the sets of this domain one by one.
-
checkInvariants
public abstract 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.
-
in
public void in(int level, Var var, Domain domain)
Description copied from class:Domain
It enforces that this domain is included within the specified domain.
-
inLUB
public abstract void inLUB(int level, SetVar var, IntDomain domain)
It specifies what elements can be in LUB. It will not add any new elements only removed the elements currently in LUB but not permitted by the argument domain.- Parameters:
level
- level of the store at which this restriction takes place.var
- variable which domain is being restricted.domain
- the domain specifying the allowed values the domain of the set variable.
-
inLUBComplement
public abstract void inLUBComplement(int level, SetVar var, int element)
It specifies the element which can *NOT* be used as an element within a set assign to a set variable.- Parameters:
level
- level of the store at which this restriction takes place.var
- variable which domain is being restricted.element
- the value being removed from the domain of the set variable.
-
inGLB
public abstract void inGLB(int level, SetVar var, IntDomain domain)
It specifies what elements must be in GLB. It will add new elements if they are not already in GLB.- Parameters:
level
- level of the store at which this addition takes place.var
- variable which domain is being restricted.domain
- the domain specifying the required values of the set variable.
-
inGLB
public abstract void inGLB(int level, SetVar var, int element)
It adds if necessary an element to glb.- Parameters:
level
- level at which the change is recorded.var
- set variable to which the change applies to.element
- the element which must be in glb.
-
inValue
public abstract void inValue(int level, SetVar var, IntDomain set)
It assigns a set variable to the specified value.- Parameters:
level
- level at which the change is recorded.var
- set variable to which the change applies to.set
- the value assigned to a set variable.
-
noConstraints
public int noConstraints()
It returns the number of constraints- Specified by:
noConstraints
in classDomain
- Returns:
- the number of constraints attached to this domain.
-
inCardinality
public abstract void inCardinality(int level, SetVar a, int i, int j)
It restricts the possible cardinality of the set domain.- Parameters:
level
- level of the store at which the restriction takes place.a
- the variable which domain is being restricted.i
- the minimal allowed cardinalityj
- the maximal allowed cardinality
-
-