-
- All Superinterfaces:
ArExpression
,java.lang.Comparable<Variable>
,ICause
,Identity
,java.lang.Iterable<java.lang.Integer>
,Variable
- All Known Subinterfaces:
BoolVar
- All Known Implementing Classes:
BitsetArrayIntVarImpl
,BitsetIntVarImpl
,BoolEqView
,BoolIntView
,BoolLeqView
,BoolNotView
,BoolSetView
,BoolVarImpl
,FixedBoolVarImpl
,FixedIntVarImpl
,IntervalIntVarImpl
,IntMinusView
,IntOffsetView
,IntScaleView
,IntView
public interface IntVar extends ICause, Variable, java.lang.Iterable<java.lang.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.IntPrimitive, ArExpression.Operator
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_INT_BOUND
Provide a minimum value for integer variable lower bound.static int
MIN_INT_BOUND
Provide 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 boolean
contains(int value)
Checks if a valuev
belongs to the domain ofthis
void
createLit(IntIterableRangeSet rootDomain)
Create the signed literal.default void
flushLit()
Flush the current signed literaldefault void
forEachIntVar(java.util.function.Consumer<IntVar> action)
Apply an action on each variable declared on the scope of this cause, if any.int
getLB()
Retrieves the lower bound of the variableSignedLiteral
getLit()
default int
getNoChild()
int
getRange()
Returns the range of this domain, that is, the difference between the upper bound and the lower bound.DisposableRangeIterator
getRangeIterator(boolean bottomUp)
Retrieves an iterator over ranges (or intervals) ofthis
.int
getUB()
Retrieves the upper bound of the variableint
getValue()
Retrieves the current value of the variable if instantiatedDisposableValueIterator
getValueIterator(boolean bottomUp)
Retrieves an iterator over values ofthis
.boolean
hasEnumeratedDomain()
Indicates wether (or not)this
has an enumerated domain (represented in extension) or not (only bounds)boolean
instantiateTo(int value, ICause cause)
Instantiates the domain ofthis
tovalue
.default boolean
instantiateTo(long value, ICause cause)
Instantiates the domain ofthis
tovalue
.default void
intersectLit(int l, int u, ExplanationForSignedClause explanation)
Perform the intersection of this internal signed literal and the range [l
,u
]:default void
intersectLit(int v, ExplanationForSignedClause explanation)
Perform the intersection of this internal signed literal and {v
}:default void
intersectLit(IntIterableRangeSet set, ExplanationForSignedClause explanation)
Perform the intersection of this internal signed literal andset
:default IntVar
intVar()
boolean
isBool()
default boolean
isExpressionLeaf()
boolean
isInstantiatedTo(int value)
Checks wetherthis
is instantiated toval
IIntDeltaMonitor
monitorDelta(ICause propagator)
Allow to monitor removed values ofthis
.int
nextValue(int v)
Returns the first value just after v inthis
which is in the domain.int
nextValueOut(int v)
Returns the first value just after v inthis
which is out of the domain.int
previousValue(int v)
Returns the previous value just before v inthis
.int
previousValueOut(int v)
Returns the first value just before v inthis
which is out of the domain.boolean
removeAllValuesBut(IntIterableSet values, ICause cause)
Removes all values from the domain ofthis
except those invalues
.boolean
removeInterval(int from, int to, ICause cause)
Removes values between [from, to
] from the domain ofthis
.boolean
removeValue(int value, ICause cause)
Removesvalue
from the domain ofthis
.default boolean
removeValue(long value, ICause cause)
Removesvalue
from the domain ofthis
.boolean
removeValues(IntIterableSet values, ICause cause)
Removes the value invalues
from the domain ofthis
.default java.util.stream.IntStream
stream()
default IEventType
transformEvent(IEventType evt)
default void
unionLit(int l, int u, ExplanationForSignedClause explanation)
Perform the union of this internal signed literal and the range [l
,u
]:default void
unionLit(int v, ExplanationForSignedClause explanation)
Perform the union of this internal signed literal and {v
}:default void
unionLit(IntIterableRangeSet set, ExplanationForSignedClause explanation)
Perform the union of this internal signed literal andset
:boolean
updateBounds(int lb, int ub, ICause cause)
Updates the lower bound and the upper bound of the domain ofthis
to, resp.boolean
updateLowerBound(int value, ICause cause)
Updates the lower bound of the domain ofthis
tovalue
.default boolean
updateLowerBound(long value, ICause cause)
Updates the lower bound of the domain ofthis
tovalue
.boolean
updateUpperBound(int value, ICause cause)
Updates the upper bound of the domain ofthis
tovalue
.default boolean
updateUpperBound(long value, ICause cause)
Updates the upper bound of the domain ofthis
tovalue
.-
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, in, in, le, le, lt, lt, max, max, max, min, min, min, mod, mod, mul, mul, mul, ne, ne, neg, notin, notin, pow, pow, primitive, sqr, sub, sub
-
Methods inherited from interface org.chocosolver.solver.variables.Variable
addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, contradiction, createDelta, forEachPropagator, getCause, getDelta, getDomainSize, getEnvironment, getEvtScheduler, getMask, getModel, getName, getNbProps, getNbViews, getTypeAndKind, getView, instantiationWorldIndex, isAConstant, isInstantiated, isScheduled, link, notifyMonitors, notifyPropagators, notifyViews, recordWorldIndex, removeMonitor, schedule, schedulePropagators, storeEvents, streamPropagators, subscribeView, swapOnPassivate, unlink, unschedule
-
-
-
-
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 ContradictionException
Removesvalue
from the domain ofthis
. The instruction comes frompropagator
.- If
value
is out of the domain, nothing is done and the return value isfalse
, - if removing
value
leads to a dead-end (domain wipe-out), aContradictionException
is thrown, - otherwise, if removing
value
from 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
-
removeValue
default boolean removeValue(long value, ICause cause) throws ContradictionException
Removesvalue
from the domain ofthis
. The instruction comes frompropagator
.This method deals with
value
as long. If such a long can be safely cast to an int, this falls back to regular case (int). Otherwise, it can either trivially do nothing or fail.- If
value
is out of the domain, nothing is done and the return value isfalse
, - if removing
value
leads to a dead-end (domain wipe-out), aContradictionException
is thrown, - otherwise, if removing
value
from 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 invalues
from 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
ContradictionException
is thrown, - otherwise, if removing the
values
from 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 ofthis
except those invalues
. The instruction comes frompropagator
.- If all values are out of the domain,
a
ContradictionException
is thrown, - if the domain is a subset of values,
nothing is done and the return value is
false
, - otherwise, if removing all values but
values
from 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 ContradictionException
Removes 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
value
leads to a dead-end (domain wipe-out), aContradictionException
is thrown, - otherwise, if removing at least a
value
from 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 ContradictionException
Instantiates the domain ofthis
tovalue
. The instruction comes frompropagator
.- If the domain of
this
is already instantiated tovalue
, nothing is done and the return value isfalse
, - If the domain of
this
is already instantiated to another value, then aContradictionException
is thrown, - Otherwise, the domain of
this
is restricted tovalue
and 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
-
instantiateTo
default boolean instantiateTo(long value, ICause cause) throws ContradictionException
Instantiates the domain ofthis
tovalue
. The instruction comes frompropagator
.This method deals with
value
as long. If such a long can be safely cast to an int, this falls back to regular case (int). Otherwise, it can either trivially do nothing or fail.- If the domain of
this
is already instantiated tovalue
, nothing is done and the return value isfalse
, - If the domain of
this
is already instantiated to another value, then aContradictionException
is thrown, - Otherwise, the domain of
this
is restricted tovalue
and 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 ContradictionException
Updates the lower bound of the domain ofthis
tovalue
. The instruction comes frompropagator
.- If
value
is smaller than the lower bound of the domain, nothing is done and the return value isfalse
, - if updating the lower bound to
value
leads to a dead-end (domain wipe-out), aContradictionException
is thrown, - otherwise, if updating the lower bound to
value
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
- 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
-
updateLowerBound
default boolean updateLowerBound(long value, ICause cause) throws ContradictionException
Updates the lower bound of the domain ofthis
tovalue
. The instruction comes frompropagator
.This method deals with
value
as long. If such a long can be safely cast to an int, this falls back to regular case (int). Otherwise, it can either trivially do nothing or fail.- If
value
is smaller than the lower bound of the domain, nothing is done and the return value isfalse
, - if updating the lower bound to
value
leads to a dead-end (domain wipe-out), aContradictionException
is thrown, - otherwise, if updating the lower bound to
value
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
- 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 ContradictionException
Updates the upper bound of the domain ofthis
tovalue
. The instruction comes frompropagator
.- If
value
is greater than the upper bound of the domain, nothing is done and the return value isfalse
, - if updating the upper bound to
value
leads to a dead-end (domain wipe-out), aContradictionException
is thrown, - otherwise, if updating the upper bound to
value
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
- 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
-
updateUpperBound
default boolean updateUpperBound(long value, ICause cause) throws ContradictionException
Updates the upper bound of the domain ofthis
tovalue
. The instruction comes frompropagator
.This method deals with
value
as long. If such a long can be safely cast to an int, this falls back to regular case (int). Otherwise, it can either trivially do nothing or fail.- If
value
is greater than the upper bound of the domain, nothing is done and the return value isfalse
, - if updating the upper bound to
value
leads to a dead-end (domain wipe-out), aContradictionException
is thrown, - otherwise, if updating the upper bound to
value
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
- 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 ContradictionException
Updates the lower bound and the upper bound of the domain ofthis
to, resp.lb
andub
. The instruction comes frompropagator
.- If
lb
is smaller than the lower bound of the domain andub
is 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 toub
leads to a dead-end (domain wipe-out), or iflb
is strictly greater thanub
, aContradictionException
is thrown, - otherwise, if updating the lower bound to
lb
and/or the upper bound toub
can 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 valuev
belongs to the domain ofthis
- Parameters:
value
- int- Returns:
true
if the value belongs to the domain ofthis
,false
otherwise.
-
isInstantiatedTo
boolean isInstantiatedTo(int value)
Checks wetherthis
is instantiated toval
- Parameters:
value
- int- Returns:
- true if
this
is instantiated toval
, false otherwise
-
getValue
int getValue() throws java.lang.IllegalStateException
Retrieves the current value of the variable if instantiated- Returns:
- the current value
- Throws:
java.lang.IllegalStateException
- when the variable is not 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
-
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 inthis
which 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 inthis
which 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 inthis
which 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 a
IntVar
, 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.true
means from lower bound to upper bound,false
means 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 a
IntVar
, 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.true
means from lower bound to upper bound,false
means from upper bound to lower bound.- Returns:
- a disposable iterator over ranges of
this
.
-
hasEnumeratedDomain
boolean hasEnumeratedDomain()
Indicates wether (or not)this
has an enumerated domain (represented in extension) or not (only bounds)- Returns:
true
if the domain is enumerated,false
otherwise.
-
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
-
forEachIntVar
default void forEachIntVar(java.util.function.Consumer<IntVar> action)
Description copied from interface:ICause
Apply an action on each variable declared on the scope of this cause, if any.- Specified by:
forEachIntVar
in interfaceICause
- Parameters:
action
- action to perform on each variable declared in this cause.
-
transformEvent
default IEventType transformEvent(IEventType evt)
- Parameters:
evt
- original event- Returns:
- transforms the original event wrt this IntVar
-
intVar
default IntVar intVar()
- Specified by:
intVar
in interfaceArExpression
- Returns:
- the arithmetic expression as an
IntVar
. If necessary, it creates intermediary variable and posts intermediary constraints
-
getNoChild
default int getNoChild()
- Specified by:
getNoChild
in interfaceArExpression
- Returns:
- the child of this expression, or null if thid
-
isExpressionLeaf
default boolean isExpressionLeaf()
- Specified by:
isExpressionLeaf
in interfaceArExpression
- Returns:
- true if this expression is a leaf, ie a variable, false otherwise
-
createLit
void createLit(IntIterableRangeSet rootDomain)
Create the signed literal.- Parameters:
rootDomain
- the domain at root node
-
getLit
SignedLiteral getLit()
- Returns:
- the current signed literal
-
flushLit
default void flushLit()
Flush the current signed literal
-
unionLit
default void unionLit(IntIterableRangeSet set, ExplanationForSignedClause explanation)
Perform the union of this internal signed literal andset
:lit
=set
∪lit
- Parameters:
set
- set of ints to join this signed literal withexplanation
- the explanation
-
unionLit
default void unionLit(int l, int u, ExplanationForSignedClause explanation)
Perform the union of this internal signed literal and the range [l
,u
]:lit
= [l
,u
] ∪lit
- Parameters:
l
- inclusive lower boundu
- inclusive upper boundexplanation
- the explanation
-
unionLit
default void unionLit(int v, ExplanationForSignedClause explanation)
Perform the union of this internal signed literal and {v
}:lit
= {v
} ∪lit
- Parameters:
v
- int valueexplanation
- the explanation
-
intersectLit
default void intersectLit(IntIterableRangeSet set, ExplanationForSignedClause explanation)
Perform the intersection of this internal signed literal andset
:lit
=set
∩lit
- Parameters:
set
- set of ints to cross this signed literal with.explanation
- the explanation
-
intersectLit
default void intersectLit(int l, int u, ExplanationForSignedClause explanation)
Perform the intersection of this internal signed literal and the range [l
,u
]:lit
= [l
,u
] ∩lit
- Parameters:
l
- inclusive lower boundu
- inclusive upper boundexplanation
- the explanation
-
intersectLit
default void intersectLit(int v, ExplanationForSignedClause explanation)
Perform the intersection of this internal signed literal and {v
}:lit
= {v
} ∩lit
- Parameters:
v
- int valueexplanation
- the explanation
-
stream
default java.util.stream.IntStream stream()
-
-