Package org.chocosolver.solver.variables
Interface IntVar
-
- All Superinterfaces:
ArExpression,Comparable<Variable>,ICause,Identity,Iterable<Integer>,Variable
- All Known Subinterfaces:
BoolVar
- All Known Implementing Classes:
BitsetArrayIntVarImpl,BitsetIntVarImpl,BoolNotView,BoolVarImpl,FixedBoolVarImpl,FixedIntVarImpl,IntervalIntVarImpl,IntView,MinusView,OffsetView,ScaleView
public interface IntVar extends ICause, Variable, Iterable<Integer>, ArExpression
Interface for integer variables. Provides every required services. The domain is explicitly represented but is not (and should not be) accessible from outside.
CPRU r544: remove default implementation
- Since:
- 18 nov. 2010
- Author:
- Charles Prud'homme
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.chocosolver.solver.expression.discrete.arithmetic.ArExpression
ArExpression.Operator
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_INT_BOUNDProvide a minimum value for integer variable lower bound.static intMIN_INT_BOUNDProvide a minimum value for integer variable lower bound.-
Fields inherited from interface org.chocosolver.solver.expression.discrete.arithmetic.ArExpression
NO_CHILD
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleancontains(int value)Checks if a valuevbelongs to the domain ofthisintgetDomainSize()Returns the size of this domain, that is the number of elements in this domain.intgetLB()Retrieves the lower bound of the variabledefault intgetNoChild()intgetRange()Returns the range of this domain, that is, the difference between the upper bound and the lower bound.DisposableRangeIteratorgetRangeIterator(boolean bottomUp)Retrieves an iterator over ranges (or intervals) ofthis.intgetUB()Retrieves the upper bound of the variableintgetValue()Retrieves the current value of the variable if instantiated, otherwier the lower bound.DisposableValueIteratorgetValueIterator(boolean bottomUp)Retrieves an iterator over values ofthis.booleanhasEnumeratedDomain()Indicates wether (or not)thishas an enumerated domain (represented in extension) or not (only bounds)booleaninstantiateTo(int value, ICause cause)Instantiates the domain ofthistovalue.default IntVarintVar()booleanisBool()default booleanisExpressionLeaf()booleanisInstantiatedTo(int value)Checks wetherthisis instantiated tovalIIntDeltaMonitormonitorDelta(ICause propagator)Allow to monitor removed values ofthis.intnextValue(int v)Returns the first value just after v inthiswhich is in the domain.intnextValueOut(int v)Returns the first value just after v inthiswhich is out of the domain.intpreviousValue(int v)Returns the previous value just before v inthis.intpreviousValueOut(int v)Returns the first value just before v inthiswhich is out of the domain.booleanremoveAllValuesBut(IntIterableSet values, ICause cause)Removes all values from the domain ofthisexcept those invalues.booleanremoveInterval(int from, int to, ICause cause)Removes values between [from, to] from the domain ofthis.booleanremoveValue(int value, ICause cause)Removesvaluefrom the domain ofthis.booleanremoveValues(IntIterableSet values, ICause cause)Removes the value invaluesfrom the domain ofthis.default intreverseValue(int value)default IEventTypetransformEvent(IEventType evt)default inttransformValue(int value)booleanupdateBounds(int lb, int ub, ICause cause)Updates the lower bound and the upper bound of the domain ofthisto, resp.booleanupdateLowerBound(int value, ICause cause)Updates the lower bound of the domain ofthistovalue.booleanupdateUpperBound(int value, ICause cause)Updates the upper bound of the domain ofthistovalue.default booleanwhy(RuleStore ruleStore, IntVar modifiedVar, IEventType evt, int value)Add new rules to the rule store-
Methods inherited from interface org.chocosolver.solver.expression.discrete.arithmetic.ArExpression
abs, add, add, add, dist, dist, div, div, eq, eq, eq, extractVar, ge, ge, getExpressionChild, getModel, gt, gt, ieval, le, le, lt, lt, max, max, max, min, min, min, mod, mod, mul, mul, mul, ne, ne, neg, pow, pow, sqr, sub, sub
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Methods inherited from interface org.chocosolver.solver.variables.Variable
addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, contradiction, createDelta, getCause, getDelta, getDindex, getEnvironment, getEvtScheduler, getIndexInPropagator, getMask, getModel, getName, getNbProps, getPIndices, getPropagator, getPropagators, getTypeAndKind, getViews, isAConstant, isInstantiated, link, notifyMonitors, notifyPropagators, notifyViews, removeMonitor, setPIndice, storeEvents, subscribeView, swapOnActivate, swapOnPassivate, unlink
-
-
-
-
Field Detail
-
MIN_INT_BOUND
static final int MIN_INT_BOUND
Provide a minimum value for integer variable lower bound. Do not prevent from underflow, but may avoid it, somehow.- See Also:
- Constant Field Values
-
MAX_INT_BOUND
static final int MAX_INT_BOUND
Provide a minimum value for integer variable lower bound. Do not prevent from overflow, but may avoid it, somehow.- See Also:
- Constant Field Values
-
-
Method Detail
-
removeValue
boolean removeValue(int value, ICause cause) throws ContradictionExceptionRemovesvaluefrom the domain ofthis. The instruction comes frompropagator.- If
valueis out of the domain, nothing is done and the return value isfalse, - if removing
valueleads to a dead-end (domain wipe-out), aContradictionExceptionis thrown, - otherwise, if removing
valuefrom the domain can be done safely, the event type is created (the original event can be promoted) and observers are notified and the return value istrue
- Parameters:
value- value to remove from the domain (int)cause- removal releaser- Returns:
- true if the value has been removed, false otherwise
- Throws:
ContradictionException- if the domain become empty due to this action
- If
-
removeValues
boolean removeValues(IntIterableSet values, ICause cause) throws ContradictionException
Removes the value invaluesfrom the domain ofthis. The instruction comes frompropagator.- If all values are out of the domain, nothing is done and the return value is
false, - if removing a value leads to a dead-end (domain wipe-out),
a
ContradictionExceptionis thrown, - otherwise, if removing the
valuesfrom the domain can be done safely, the event type is created (the original event can be promoted) and observers are notified and the return value istrue
- Parameters:
values- set of ordered values to removecause- removal release- Returns:
- true if at least a value has been removed, false otherwise
- Throws:
ContradictionException- if the domain become empty due to this action
- If all values are out of the domain, nothing is done and the return value is
-
removeAllValuesBut
boolean removeAllValuesBut(IntIterableSet values, ICause cause) throws ContradictionException
Removes all values from the domain ofthisexcept those invalues. The instruction comes frompropagator.- If all values are out of the domain,
a
ContradictionExceptionis thrown, - if the domain is a subset of values,
nothing is done and the return value is
false, - otherwise, if removing all values but
valuesfrom the domain can be done safely, the event type is created (the original event can be promoted) and observers are notified and the return value istrue
- Parameters:
values- set of ordered values to keep in the domaincause- removal release- Returns:
- true if a at least a value has been removed, false otherwise
- Throws:
ContradictionException- if the domain become empty due to this action
- If all values are out of the domain,
a
-
removeInterval
boolean removeInterval(int from, int to, ICause cause) throws ContradictionExceptionRemoves values between [from, to] from the domain ofthis. The instruction comes frompropagator.- If union between values and the current domain is empty, nothing is done and the return value is
false, - if removing a
valueleads to a dead-end (domain wipe-out), aContradictionExceptionis thrown, - otherwise, if removing at least a
valuefrom the domain can be done safely, the event type is created (the original event can be promoted) and observers are notified and the return value istrue
- Parameters:
from- lower bound of the interval to remove (int)to- upper bound of the interval to remove(int)cause- removal releaser- Returns:
- true if the value has been removed, false otherwise
- Throws:
ContradictionException- if the domain become empty due to this action
- If union between values and the current domain is empty, nothing is done and the return value is
-
instantiateTo
boolean instantiateTo(int value, ICause cause) throws ContradictionExceptionInstantiates the domain ofthistovalue. The instruction comes frompropagator.- If the domain of
thisis already instantiated tovalue, nothing is done and the return value isfalse, - If the domain of
thisis already instantiated to another value, then aContradictionExceptionis thrown, - Otherwise, the domain of
thisis restricted tovalueand the observers are notified and the return value istrue.
- Parameters:
value- instantiation value (int)cause- instantiation releaser- Returns:
- true if the instantiation is done, false otherwise
- Throws:
ContradictionException- if the domain become empty due to this action
- If the domain of
-
updateLowerBound
boolean updateLowerBound(int value, ICause cause) throws ContradictionExceptionUpdates the lower bound of the domain ofthistovalue. The instruction comes frompropagator.- If
valueis smaller than the lower bound of the domain, nothing is done and the return value isfalse, - if updating the lower bound to
valueleads to a dead-end (domain wipe-out), aContradictionExceptionis thrown, - otherwise, if updating the lower bound to
valuecan be done safely, the event type is created (the original event can be promoted) and observers are notified and the return value istrue
- Parameters:
value- new lower bound (included)cause- updating releaser- Returns:
- true if the lower bound has been updated, false otherwise
- Throws:
ContradictionException- if the domain become empty due to this action
- If
-
updateUpperBound
boolean updateUpperBound(int value, ICause cause) throws ContradictionExceptionUpdates the upper bound of the domain ofthistovalue. The instruction comes frompropagator.- If
valueis greater than the upper bound of the domain, nothing is done and the return value isfalse, - if updating the upper bound to
valueleads to a dead-end (domain wipe-out), aContradictionExceptionis thrown, - otherwise, if updating the upper bound to
valuecan be done safely, the event type is created (the original event can be promoted) and observers are notified and the return value istrue
- Parameters:
value- new upper bound (included)cause- update releaser- Returns:
- true if the upper bound has been updated, false otherwise
- Throws:
ContradictionException- if the domain become empty due to this action
- If
-
updateBounds
boolean updateBounds(int lb, int ub, ICause cause) throws ContradictionExceptionUpdates the lower bound and the upper bound of the domain ofthisto, resp.lbandub. The instruction comes frompropagator.- If
lbis smaller than the lower bound of the domain andubis greater than the upper bound of the domain,nothing is done and the return value is
false, - if updating the lower bound to
lb, or updating the upper bound toubleads to a dead-end (domain wipe-out), or iflbis strictly greater thanub, aContradictionExceptionis thrown, - otherwise, if updating the lower bound to
lband/or the upper bound toubcan be done safely can be done safely, the event type is created (the original event can be promoted) and observers are notified and the return value istrue
- Parameters:
lb- new lower bound (included)ub- new upper bound (included)cause- update releaser- Returns:
- true if the upper bound has been updated, false otherwise
- Throws:
ContradictionException- if the domain become empty due to this action
- If
-
contains
boolean contains(int value)
Checks if a valuevbelongs to the domain ofthis- Parameters:
value- int- Returns:
trueif the value belongs to the domain ofthis,falseotherwise.
-
isInstantiatedTo
boolean isInstantiatedTo(int value)
Checks wetherthisis instantiated toval- Parameters:
value- int- Returns:
- true if
thisis instantiated toval, false otherwise
-
getValue
int getValue()
Retrieves the current value of the variable if instantiated, otherwier the lower bound.- Returns:
- the current value (or lower bound if not yet instantiated).
-
getLB
int getLB()
Retrieves the lower bound of the variable- Returns:
- the lower bound
-
getUB
int getUB()
Retrieves the upper bound of the variable- Returns:
- the upper bound
-
getDomainSize
int getDomainSize()
Returns the size of this domain, that is the number of elements in this domain.- Returns:
- size of the domain
-
getRange
int getRange()
Returns the range of this domain, that is, the difference between the upper bound and the lower bound.- Returns:
- the range of this domain
-
nextValue
int nextValue(int v)
Returns the first value just after v inthiswhich is in the domain. If no such value exists, returns Integer.MAX_VALUE;To iterate over the values in a
IntVar, use the following loop:int ub = iv.getUB(); for (int i = iv.getLB(); i <= ub; i = iv.nextValue(i)) { // operate on value i here }- Parameters:
v- the value to start checking (exclusive)- Returns:
- the next value in the domain
-
nextValueOut
int nextValueOut(int v)
Returns the first value just after v inthiswhich is out of the domain. If v is less than or equal togetLB()-2, returns v + 1, if v is greater than or equal togetUB(), returns v + 1.- Parameters:
v- the value to start checking (exclusive)- Returns:
- the next value out of the domain
-
previousValue
int previousValue(int v)
Returns the previous value just before v inthis. If no such value exists, returns Integer.MIN_VALUE;To iterate over the values in a
IntVar, use the following loop:int lb = iv.getLB(); for (int i = iv.getUB(); i >= lb; i = iv.previousValue(i)) { // operate on value i here }- Parameters:
v- the value to start checking (exclusive)- Returns:
- the previous value in the domain
-
previousValueOut
int previousValueOut(int v)
Returns the first value just before v inthiswhich is out of the domain. If v is greater than or equal togetUB()+2, returns v - 1, if v is less than or equal togetLB(), returns v - 1.- Parameters:
v- the value to start checking (exclusive)- Returns:
- the previous value out of the domain
-
getValueIterator
DisposableValueIterator getValueIterator(boolean bottomUp)
Retrieves an iterator over values ofthis.The values can be iterated in a bottom-up way or top-down way.
To bottom-up iterate over the values in a
IntVar, use the following loop:DisposableValueIterator vit = var.getValueIterator(true); while(vit.hasNext()){ int v = vit.next(); // operate on value v here } vit.dispose();To top-down iterate over the values in aIntVar, use the following loop:DisposableValueIterator vit = var.getValueIterator(false); while(vit.hasPrevious()){ int v = vit.previous(); // operate on value v here } vit.dispose();Using both previous and next can lead to unexpected behaviour.- Parameters:
bottomUp- way to iterate over values.truemeans from lower bound to upper bound,falsemeans from upper bound to lower bound.- Returns:
- a disposable iterator over values of
this.
-
getRangeIterator
DisposableRangeIterator getRangeIterator(boolean bottomUp)
Retrieves an iterator over ranges (or intervals) ofthis.The ranges can be iterated in a bottom-up way or top-down way.
To bottom-up iterate over the values in a
IntVar, use the following loop:DisposableRangeIterator rit = var.getRangeIterator(true); while (rit.hasNext()) { int from = rit.min(); int to = rit.max(); // operate on range [from,to] here rit.next(); } rit.dispose();To top-down iterate over the values in aIntVar, use the following loop:DisposableRangeIterator rit = var.getRangeIterator(false); while (rit.hasPrevious()) { int from = rit.min(); int to = rit.max(); // operate on range [from,to] here rit.previous(); } rit.dispose();Using both previous and next can lead to unexpected behaviour.- Parameters:
bottomUp- way to iterate over ranges.truemeans from lower bound to upper bound,falsemeans from upper bound to lower bound.- Returns:
- a disposable iterator over ranges of
this.
-
hasEnumeratedDomain
boolean hasEnumeratedDomain()
Indicates wether (or not)thishas an enumerated domain (represented in extension) or not (only bounds)- Returns:
trueif the domain is enumerated,falseotherwise.
-
monitorDelta
IIntDeltaMonitor monitorDelta(ICause propagator)
Allow to monitor removed values ofthis.- Parameters:
propagator- the cause that requires to monitor delta- Returns:
- a delta monitor
-
isBool
boolean isBool()
- Returns:
- true iff the variable has a binary domain
-
why
default boolean why(RuleStore ruleStore, IntVar modifiedVar, IEventType evt, int value)
Description copied from interface:ICauseAdd new rules to the rule store
-
transformEvent
default IEventType transformEvent(IEventType evt)
- Parameters:
evt- original event- Returns:
- transforms the original event wrt this IntVar
-
transformValue
default int transformValue(int value)
- Parameters:
value- original value- Returns:
- transforms the original value wrt this IntVar
-
reverseValue
default int reverseValue(int value)
- Parameters:
value- original value- Returns:
- reverses the original value wrt this IntVar
-
intVar
default IntVar intVar()
- Specified by:
intVarin interfaceArExpression- Returns:
- the arithmetic expression as an
IntVar. If necessary, it creates intermediary variable and posts intermediary constraints
-
getNoChild
default int getNoChild()
- Specified by:
getNoChildin interfaceArExpression- Returns:
- the child of this expression, or null if thid
-
isExpressionLeaf
default boolean isExpressionLeaf()
- Specified by:
isExpressionLeafin interfaceArExpression- Returns:
- true if this expression is a leaf, ie a variable, false otherwise
-
-