java.lang.Object
org.maxicp.cp.engine.core.CPIntVarImpl
- All Implemented Interfaces:
Serializable,CPIntVar,CPVar,Expression,IntExpression,ConcreteIntVar,ConcreteVar,IntVar,Var
- Direct Known Subclasses:
CPBoolVarIsEqual
Implementation of a variable
with a
SparseSetDomain.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCPIntVarImpl(CPSolver cp, int n) Creates a variable with the elements{0,...,n-1}as initial domain.CPIntVarImpl(CPSolver cp, int min, int max) Creates a variable with the elements{min,...,max}as initial domain.CPIntVarImpl(CPSolver cp, Set<Integer> values) Creates a variable with a given set of values as initial domain. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(int v) Returns true if the domain contains the specified value.Returns a delta object allowing to retrieve the changes in the domain of the variable (removed values) since the previous call to theConstraint.propagateof the constraint.intfillArray(int[] dest) Copies the values of the domain into an array.intfillDeltaArray(int oldMin, int oldMax, int oldSize, int[] arr) Copies the values of the domain that have been removed (delta set) wrt to a previous state of the domain described by oldMin, oldMax and oldSize.voidfix(int v) Fixes the specified value.Returns the ModelDispatcher linked to this ExpressionReturns the solver in which this variable was created.booleanisFixed()Returns true if the domain of the variable has a single value.intmax()Returns the maximum of the domain of the variableintmin()Returns the minimum of the domain of the variablevoidAsks thatCPConstraint.propagate()is called whenever the bound (maximum or minimum values) of the domain of this variable is changes.voidAsks thatCPConstraint.propagate()is called whenever the domain of this variable changes.voidAsks thatCPConstraint.propagate()is called whenever the domain of this variable is reduced to a singleton.voidremove(int v) Removes the specified value.voidremoveAbove(int v) Removes all the values above a given value.voidremoveBelow(int v) Removes all the values less than a given value.protected voidscheduleAll(StateStack<CPConstraint> constraints) intsize()Returns the size of the domain of the variabletoString()voidAsks that the closure is called whenever the max or min setValue of the domain of this variable changesvoidAsks that the closure is called whenever the domain change of this variable changesvoidAsks that the consumer is called whenever the domain change of this variable changes.voidAsks that the closure is called whenever the domain of this variable is reduced to a single setValue.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.maxicp.cp.engine.core.CPIntVar
abs, after, before, evaluate, minus, minus, plus, plusMethods inherited from interface org.maxicp.modeling.algebra.Expression
subexpressionsMethods inherited from interface org.maxicp.modeling.algebra.integer.IntExpression
showMethods inherited from interface org.maxicp.modeling.IntVar
computeSubexpressions, mapSubexpressions
-
Constructor Details
-
CPIntVarImpl
Creates a variable with the elements{0,...,n-1}as initial domain.- Parameters:
cp- the solver in which the variable is createdn- the number of values withn > 0
-
CPIntVarImpl
Creates a variable with the elements{min,...,max}as initial domain.- Parameters:
cp- the solver in which the variable is createdmin- the minimum value of the domainmax- the maximum value of the domain withmax >= min
-
CPIntVarImpl
Creates a variable with a given set of values as initial domain.- Parameters:
cp- the solver in which the variable is createdvalues- the initial values in the domain, it must be nonempty
-
-
Method Details
-
getSolver
Description copied from interface:CPIntVarReturns the solver in which this variable was created. -
isFixed
public boolean isFixed()Description copied from interface:CPIntVarReturns true if the domain of the variable has a single value. -
toString
-
whenFixed
Description copied from interface:CPIntVarAsks that the closure is called whenever the domain of this variable is reduced to a single setValue. -
whenBoundChange
Description copied from interface:CPIntVarAsks that the closure is called whenever the max or min setValue of the domain of this variable changes- Specified by:
whenBoundChangein interfaceCPIntVar- Parameters:
f- the closure
-
whenDomainChange
Description copied from interface:CPIntVarAsks that the closure is called whenever the domain change of this variable changes- Specified by:
whenDomainChangein interfaceCPIntVar- Parameters:
f- the closure
-
whenDomainChange
Description copied from interface:CPIntVarAsks that the consumer is called whenever the domain change of this variable changes. The consumer is called with a delta object that allows to retrieve the changes in the domain of the variable (removed values) since the previous call.- Specified by:
whenDomainChangein interfaceCPIntVar- Parameters:
f- the consumer with the delta of the domain since last call
-
propagateOnDomainChange
Description copied from interface:CPIntVarAsks thatCPConstraint.propagate()is called whenever the domain of this variable changes. We say that a change event occurs.- Specified by:
propagateOnDomainChangein interfaceCPIntVar- Parameters:
c- the constraint for which theCPConstraint.propagate()method should be called on change events of this variable.
-
propagateOnFix
Description copied from interface:CPIntVarAsks thatCPConstraint.propagate()is called whenever the domain of this variable is reduced to a singleton. In such a state the variable is bind and we say that a bind event occurs.- Specified by:
propagateOnFixin interfaceCPIntVar- Parameters:
c- the constraint for which theCPConstraint.propagate()method should be called on bind events of this variable.
-
propagateOnBoundChange
Description copied from interface:CPIntVarAsks thatCPConstraint.propagate()is called whenever the bound (maximum or minimum values) of the domain of this variable is changes. We say that a bound change event occurs in this case.- Specified by:
propagateOnBoundChangein interfaceCPIntVar- Parameters:
c- the constraint for which theCPConstraint.propagate()method should be called on bound change events of this variable.
-
scheduleAll
-
min
public int min()Description copied from interface:CPIntVarReturns the minimum of the domain of the variable- Specified by:
minin interfaceCPIntVar- Specified by:
minin interfaceIntExpression- Returns:
- the minimum of the domain of the variable
-
max
public int max()Description copied from interface:CPIntVarReturns the maximum of the domain of the variable- Specified by:
maxin interfaceCPIntVar- Specified by:
maxin interfaceIntExpression- Returns:
- the maximum of the domain of the variable
-
size
public int size()Description copied from interface:CPIntVarReturns the size of the domain of the variable- Specified by:
sizein interfaceCPIntVar- Specified by:
sizein interfaceIntExpression- Returns:
- the size of the domain of the variable
-
fillArray
public int fillArray(int[] dest) Description copied from interface:CPIntVarCopies the values of the domain into an array.- Specified by:
fillArrayin interfaceCPIntVar- Specified by:
fillArrayin interfaceIntExpression- Parameters:
dest- an array large enoughdest.length >= size()- Returns:
- the size of the domain and
dest[0,...,size-1]contains the values in the domain in an arbitrary order
-
contains
public boolean contains(int v) Description copied from interface:CPIntVarReturns true if the domain contains the specified value.- Specified by:
containsin interfaceCPIntVar- Specified by:
containsin interfaceIntExpression- Parameters:
v- the value whose presence in the domain is to be tested- Returns:
- true if the domain contains the specified value
-
remove
public void remove(int v) Description copied from interface:CPIntVarRemoves the specified value. -
fix
public void fix(int v) Description copied from interface:CPIntVarFixes the specified value. -
removeBelow
public void removeBelow(int v) Description copied from interface:CPIntVarRemoves all the values less than a given value.- Specified by:
removeBelowin interfaceCPIntVar- Parameters:
v- the value such that all the values less than v are removed
-
removeAbove
public void removeAbove(int v) Description copied from interface:CPIntVarRemoves all the values above a given value.- Specified by:
removeAbovein interfaceCPIntVar- Parameters:
v- the value such that all the values larger than v are removed
-
fillDeltaArray
public int fillDeltaArray(int oldMin, int oldMax, int oldSize, int[] arr) Description copied from interface:CPIntVarCopies the values of the domain that have been removed (delta set) wrt to a previous state of the domain described by oldMin, oldMax and oldSize.- Specified by:
fillDeltaArrayin interfaceCPIntVar- Parameters:
arr- an array large enoughdest.length >= oldSize-size()- Returns:
- the size of delta set stored in prefix of dest
-
delta
Description copied from interface:CPIntVarReturns a delta object allowing to retrieve the changes in the domain of the variable (removed values) since the previous call to theConstraint.propagateof the constraint. This can be useful to implement some constraint with incremental reasoning. -
getModelProxy
Description copied from interface:ExpressionReturns the ModelDispatcher linked to this Expression- Specified by:
getModelProxyin interfaceExpression- Specified by:
getModelProxyin interfaceVar
-