- java.lang.Object
-
- org.chocosolver.solver.variables.impl.AbstractVariable
-
- org.chocosolver.solver.variables.view.IntView<IntVar>
-
- org.chocosolver.solver.variables.view.IntBoolView
-
- All Implemented Interfaces:
Cloneable
,Comparable<Variable>
,Iterable<Integer>
,ILogical
,ArExpression
,ReExpression
,ICause
,Identity
,BoolVar
,IntVar
,Variable
,IView
public abstract class IntBoolView extends IntView<IntVar> implements BoolVar
An abstract class for boolean views overIntVar
.- Since:
- 04/12/2018.
- Author:
- Charles Prud'homme
- See Also:
EqView
,Project: choco-solver.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.chocosolver.solver.expression.discrete.arithmetic.ArExpression
ArExpression.Operator
-
Nested classes/interfaces inherited from interface org.chocosolver.solver.expression.discrete.relational.ReExpression
ReExpression.Operator
-
-
Field Summary
Fields Modifier and Type Field Description int
cste
A constant value-
Fields inherited from class org.chocosolver.solver.variables.impl.AbstractVariable
mIdx, model, monitors, MSG_EMPTY, MSG_INST, name, propagators
-
Fields inherited from interface org.chocosolver.solver.expression.discrete.arithmetic.ArExpression
NO_CHILD
-
Fields inherited from interface org.chocosolver.solver.variables.IntVar
MAX_INT_BOUND, MIN_INT_BOUND
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
_setNot(BoolVar neg)
void
createDelta()
Create a delta, if necessary, in order to observe removed values of a this.protected EvtScheduler
createScheduler()
DisposableRangeIterator
getRangeIterator(boolean bottomUp)
Retrieves an iterator over ranges (or intervals) ofthis
.int
getTypeAndKind()
Return a MASK composed of 2 main information: TYPE and KIND.int
getValue()
Retrieves the current value of the variable if instantiated, otherwier the lower bound.DisposableValueIterator
getValueIterator(boolean bottomUp)
Retrieves an iterator over values ofthis
.boolean
hasNot()
boolean
isLit()
Current tree is a literalboolean
isNot()
Current tree is rooted with NOT logical operator This is a one way relationship: in case a = not(b) a.isNot() returns true whereas b.isNot() returns false (unless b = not(c)...)IIntDeltaMonitor
monitorDelta(ICause propagator)
Allow to monitor removed values ofthis
.BoolVar
not()
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
.boolean
removeValues(IntIterableSet values, ICause cause)
Removes the value invalues
from the domain ofthis
.void
setNot(boolean isNot)
States whether or not this variable is the negation of another.boolean
setToFalse(ICause cause)
boolean
setToTrue(ICause cause)
String
toString()
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
.boolean
updateUpperBound(int value, ICause cause)
Updates the upper bound of the domain ofthis
tovalue
.-
Methods inherited from class org.chocosolver.solver.variables.view.IntView
compareTo, doInstantiateVar, doRemoveIntervalFromVar, doRemoveValueFromVar, doUpdateLowerBoundOfVar, doUpdateUpperBoundOfVar, forEachIntVar, getDelta, getDomainSize, getRange, getVariable, hasEnumeratedDomain, instantiateTo, isInstantiated, iterator, notify, transformEvent
-
Methods inherited from class org.chocosolver.solver.variables.impl.AbstractVariable
addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, contradiction, getCause, getDindex, getEvtScheduler, getId, getIndexInPropagator, getMask, getModel, getName, getNbProps, getNbViews, getPIndices, getPropagator, getPropagators, getView, isAConstant, isBool, link, notifyMonitors, notifyPropagators, notifyViews, removeMonitor, setPIndice, storeEvents, subscribeView, swapOnActivate, swapOnPassivate, unlink
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.chocosolver.solver.expression.discrete.arithmetic.ArExpression
abs, add, add, add, dist, dist, div, div, eq, eq, eq, ge, ge, getExpressionChild, gt, gt, 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 org.chocosolver.solver.variables.BoolVar
boolVar, extractVar, getBooleanValue, intVar
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface org.chocosolver.solver.variables.IntVar
contains, forEachIntVar, getDomainSize, getLB, getNoChild, getRange, getUB, hasEnumeratedDomain, instantiateTo, isBool, isExpressionLeaf, isInstantiatedTo, nextValue, nextValueOut, previousValue, previousValueOut, transformEvent
-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Methods inherited from interface org.chocosolver.solver.variables.view.IView
explain, justifyEvent
-
Methods inherited from interface org.chocosolver.solver.expression.discrete.relational.ReExpression
and, beval, decompose, extension, getModel, ieval, iff, ift, ift, ift, ift, imp, or, post, xor
-
Methods inherited from interface org.chocosolver.solver.variables.Variable
addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, contradiction, getCause, getDelta, getDindex, getEnvironment, getEvtScheduler, getIndexInPropagator, getMask, getModel, getName, getNbProps, getNbViews, getPIndices, getPropagator, getPropagators, getView, isAConstant, isInstantiated, link, notifyMonitors, notifyPropagators, notifyViews, removeMonitor, setPIndice, storeEvents, subscribeView, swapOnActivate, swapOnPassivate, unlink
-
-
-
-
Method Detail
-
setToTrue
public final boolean setToTrue(ICause cause) throws ContradictionException
- Specified by:
setToTrue
in interfaceBoolVar
- Throws:
ContradictionException
-
setToFalse
public final boolean setToFalse(ICause cause) throws ContradictionException
- Specified by:
setToFalse
in interfaceBoolVar
- Throws:
ContradictionException
-
removeValue
public final boolean removeValue(int value, ICause cause) throws ContradictionException
Description copied from interface:IntVar
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
- Specified by:
removeValue
in interfaceIntVar
- Overrides:
removeValue
in classIntView<IntVar>
- 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
public final boolean removeValues(IntIterableSet values, ICause cause) throws ContradictionException
Description copied from interface:IntVar
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
- Specified by:
removeValues
in interfaceIntVar
- Overrides:
removeValues
in classIntView<IntVar>
- 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
public final boolean removeAllValuesBut(IntIterableSet values, ICause cause) throws ContradictionException
Description copied from interface:IntVar
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
- Specified by:
removeAllValuesBut
in interfaceIntVar
- Overrides:
removeAllValuesBut
in classIntView<IntVar>
- 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
public final boolean removeInterval(int from, int to, ICause cause) throws ContradictionException
Description copied from interface:IntVar
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
- Specified by:
removeInterval
in interfaceIntVar
- Overrides:
removeInterval
in classIntView<IntVar>
- 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
-
updateLowerBound
public final boolean updateLowerBound(int value, ICause cause) throws ContradictionException
Description copied from interface:IntVar
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
- Specified by:
updateLowerBound
in interfaceIntVar
- Overrides:
updateLowerBound
in classIntView<IntVar>
- 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
public final boolean updateUpperBound(int value, ICause cause) throws ContradictionException
Description copied from interface:IntVar
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
- Specified by:
updateUpperBound
in interfaceIntVar
- Overrides:
updateUpperBound
in classIntView<IntVar>
- 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
public final boolean updateBounds(int lb, int ub, ICause cause) throws ContradictionException
Description copied from interface:IntVar
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
- Specified by:
updateBounds
in interfaceIntVar
- Overrides:
updateBounds
in classIntView<IntVar>
- 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
-
getTypeAndKind
public final int getTypeAndKind()
Description copied from interface:Variable
Return a MASK composed of 2 main information: TYPE and KIND.
TYPE is defined in the 3 first bits : VAR ( 1 << 0), CSTE (1 << 1) or VIEW (1 << 2)
KIND is defined on the other bits : INT (1 << 3), BOOL (INT + 1 << 4), GRAPH (1 << 5) or META (1 << 6) To get the TYPE of a variable:int type = var.getTypeAndKind() & Variable.TYPE;
To get the KIND of a variable:int kind = var.getTypeAndKind() & Variable.KIND;
To check a specific type or kind of a variable:boolean isVar = (var.getTypeAndKind() & Variable.VAR) !=0; boolean isInt = (var.getTypeAndKind() & Variable.INT) !=0;
- Specified by:
getTypeAndKind
in interfaceVariable
- Overrides:
getTypeAndKind
in classIntView<IntVar>
- Returns:
- an int representing the type and kind of the variable
-
getValue
public final int getValue()
Description copied from interface:IntVar
Retrieves the current value of the variable if instantiated, otherwier the lower bound.
-
createScheduler
protected final EvtScheduler createScheduler()
- Specified by:
createScheduler
in classAbstractVariable
-
toString
public final String toString()
- Overrides:
toString
in classAbstractVariable
-
getValueIterator
public final DisposableValueIterator getValueIterator(boolean bottomUp)
Description copied from interface:IntVar
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.- Specified by:
getValueIterator
in interfaceIntVar
- Overrides:
getValueIterator
in classIntView<IntVar>
- 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
public final DisposableRangeIterator getRangeIterator(boolean bottomUp)
Description copied from interface:IntVar
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.- Specified by:
getRangeIterator
in interfaceIntVar
- Overrides:
getRangeIterator
in classIntView<IntVar>
- 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
.
-
createDelta
public final void createDelta()
Description copied from interface:Variable
Create a delta, if necessary, in order to observe removed values of a this. If the delta already exists, has no effect.- Specified by:
createDelta
in interfaceVariable
- Overrides:
createDelta
in classIntView<IntVar>
-
monitorDelta
public final IIntDeltaMonitor monitorDelta(ICause propagator)
Description copied from interface:IntVar
Allow to monitor removed values ofthis
.- Specified by:
monitorDelta
in interfaceIntVar
- Parameters:
propagator
- the cause that requires to monitor delta- Returns:
- a delta monitor
-
not
public final BoolVar not()
- Specified by:
not
in interfaceBoolVar
- Specified by:
not
in interfaceReExpression
- Returns:
- return the expression "¬x" where this is "x"
-
isLit
public final boolean isLit()
Description copied from interface:ILogical
Current tree is a literal
-
isNot
public final boolean isNot()
Description copied from interface:ILogical
Current tree is rooted with NOT logical operator This is a one way relationship: in case a = not(b) a.isNot() returns true whereas b.isNot() returns false (unless b = not(c)...)
-
setNot
public final void setNot(boolean isNot)
Description copied from interface:ILogical
States whether or not this variable is the negation of another. This is a one way relationship: in case a = not(b) a.isNot() returns true whereas b.isNot() returns false (unless b = not(c)...)
-
-