public class BoolVarImpl extends AbstractVariable implements BoolVar
Modifier and Type | Field and Description |
---|---|
protected int |
mValue
indicate the value of the domain : false = 0, true = 1
|
protected BasicIndexedBipartiteSet |
notInstanciated
A bi partite set indicating for each value whether it is present or not.
|
protected int |
offset
The offset, that is the minimal value of the domain (stored at index 0).
|
protected boolean |
reactOnRemoval |
_plugexpl, mIdx, monitors, MSG_BOUND, MSG_EMPTY, MSG_INST, MSG_LOW, MSG_REMOVE, MSG_UNKNOWN, MSG_UPP, name, solver
Constructor and Description |
---|
BoolVarImpl(String name,
Solver solver) |
Modifier and Type | Method and Description |
---|---|
void |
_setNot(BoolVar neg) |
boolean |
contains(int aValue)
Checks if a value
v belongs to the domain of this |
void |
contradiction(ICause cause,
String message)
Throws a contradiction exception based on
|
void |
createDelta()
Create a delta, if necessary, in order to observe removed values of a this.
|
BoolVar |
duplicate()
Duplicate
this . |
ESat |
getBooleanValue() |
IEnumDelta |
getDelta()
Return the delta domain of this
|
int |
getDomainSize()
Returns the size of this domain, that is the number of elements in this domain.
|
int |
getLB()
Retrieves the lower bound of the variable
|
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) of
this . |
int |
getTypeAndKind()
Return a MASK composed of 2 main information: TYPE and KIND.
|
int |
getUB()
Retrieves the upper bound of the variable
|
int |
getValue()
Retrieves the current value of the variable if instantiated, otherwier the lower bound.
|
DisposableValueIterator |
getValueIterator(boolean bottomUp)
Retrieves an iterator over values of
this . |
boolean |
hasEnumeratedDomain()
Indicates wether (or not)
this has an enumerated domain (represented in extension)
or not (only bounds) |
boolean |
hasNot() |
boolean |
instantiateTo(int value,
ICause cause)
Instantiates the domain of
this to value . |
boolean |
isInstantiated()
Indicates whether
this is instantiated (see implemtations to know what instantiation means). |
boolean |
isInstantiatedTo(int aValue)
Checks wether
this is instantiated to val |
boolean |
isLit()
Current tree is a literal
|
boolean |
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 of
this . |
int |
nextValue(int v)
Returns the next value just after v in
this . |
BoolVar |
not() |
void |
notifyMonitors(IEventType event)
Notify monitors of observed variable modifications
|
int |
previousValue(int v)
Returns the previous value just befor v in
this . |
boolean |
removeAllValuesBut(IntIterableSet values,
ICause cause)
Removes all values from the domain of
this except those in values . |
boolean |
removeInterval(int from,
int to,
ICause cause)
Removes values between [
from, to ] from the domain of this . |
boolean |
removeValue(int value,
ICause cause)
Removes
value from the domain of this . |
boolean |
removeValues(IntIterableSet values,
ICause cause)
Removes the value in
values from the domain of this . |
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 of
this to, resp. |
boolean |
updateLowerBound(int value,
ICause cause)
Updates the lower bound of the domain of
this to value . |
boolean |
updateUpperBound(int value,
ICause cause)
Updates the upper bound of the domain of
this to value . |
_schedIter, addMonitor, compareTo, getDindex, getId, getIndexInPropagator, getName, getNbProps, getPIndices, getPropagator, getPropagators, getSolver, getViews, isBool, link, notifyPropagators, notifyViews, recordMask, removeMonitor, subscribeView, unlink
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
_schedIter, addMonitor, getDindex, getIndexInPropagator, getName, getNbProps, getPIndices, getPropagator, getPropagators, getSolver, getViews, link, notifyPropagators, notifyViews, recordMask, removeMonitor, subscribeView, unlink
compareTo
protected final int offset
protected int mValue
protected final BasicIndexedBipartiteSet notInstanciated
protected boolean reactOnRemoval
public boolean removeValue(int value, ICause cause) throws ContradictionException
value
from the domain of this
. The instruction comes from propagator
.
value
is out of the domain, nothing is done and the return value is false
,value
leads to a dead-end (domain wipe-out),
a ContradictionException
is thrown,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 is true
removeValue
in interface IntVar
value
- value to remove from the domain (int)cause
- removal releaserContradictionException
- if the domain become empty due to this actionpublic boolean removeValues(IntIterableSet values, ICause cause) throws ContradictionException
IntVar
values
from the domain of this
. The instruction comes from propagator
.
false
,ContradictionException
is thrown,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 is true
removeValues
in interface IntVar
values
- set of ordered values to removecause
- removal releaseContradictionException
- if the domain become empty due to this actionpublic boolean removeAllValuesBut(IntIterableSet values, ICause cause) throws ContradictionException
IntVar
this
except those in values
. The instruction comes from propagator
.
ContradictionException
is thrown,false
,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 is true
removeAllValuesBut
in interface IntVar
values
- set of ordered values to keep in the domaincause
- removal releaseContradictionException
- if the domain become empty due to this actionpublic boolean removeInterval(int from, int to, ICause cause) throws ContradictionException
from, to
] from the domain of this
. The instruction comes from propagator
.
false
,value
leads to a dead-end (domain wipe-out),
a ContradictionException
is thrown,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 is true
removeInterval
in interface IntVar
from
- lower bound of the interval to remove (int)to
- upper bound of the interval to remove(int)cause
- removal releaserContradictionException
- if the domain become empty due to this actionpublic boolean instantiateTo(int value, ICause cause) throws ContradictionException
this
to value
. The instruction comes from propagator
.
this
is already instantiated to value
,
nothing is done and the return value is false
,this
is already instantiated to another value,
then a ContradictionException
is thrown,this
is restricted to value
and the observers are notified
and the return value is true
.instantiateTo
in interface IntVar
value
- instantiation value (int)cause
- instantiation releaserContradictionException
- if the domain become empty due to this actionpublic boolean updateLowerBound(int value, ICause cause) throws ContradictionException
this
to value
.
The instruction comes from propagator
.
value
is smaller than the lower bound of the domain, nothing is done and the return value is false
,value
leads to a dead-end (domain wipe-out),
a ContradictionException
is thrown,value
can be done safely,
the event type is created (the original event can be promoted) and observers are notified
and the return value is true
updateLowerBound
in interface IntVar
value
- new lower bound (included)cause
- updating releaserContradictionException
- if the domain become empty due to this actionpublic boolean updateUpperBound(int value, ICause cause) throws ContradictionException
this
to value
.
The instruction comes from propagator
.
value
is greater than the upper bound of the domain, nothing is done and the return value is false
,value
leads to a dead-end (domain wipe-out),
a ContradictionException
is thrown,value
can be done safely,
the event type is created (the original event can be promoted) and observers are notified
and the return value is true
updateUpperBound
in interface IntVar
value
- new upper bound (included)cause
- update releaserContradictionException
- if the domain become empty due to this actionpublic boolean updateBounds(int lb, int ub, ICause cause) throws ContradictionException
IntVar
this
to, resp. lb
and ub
.
The instruction comes from propagator
.
lb
is smaller than the lower bound of the domain
and ub
is greater than the upper bound of the domain,
nothing is done and the return value is false
,
lb
, or updating the upper bound to ub
leads to a dead-end (domain wipe-out),
or if lb
is strictly greater than ub
,
a ContradictionException
is thrown,lb
and/or the upper bound to ub
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 is true
updateBounds
in interface IntVar
lb
- new lower bound (included)ub
- new upper bound (included)cause
- update releaserContradictionException
- if the domain become empty due to this actionpublic boolean setToTrue(ICause cause) throws ContradictionException
setToTrue
in interface BoolVar
ContradictionException
public boolean setToFalse(ICause cause) throws ContradictionException
setToFalse
in interface BoolVar
ContradictionException
public boolean isInstantiated()
Variable
this
is instantiated (see implemtations to know what instantiation means).isInstantiated
in interface Variable
true
if this
is instantiatedpublic boolean isInstantiatedTo(int aValue)
IntVar
this
is instantiated to val
isInstantiatedTo
in interface IntVar
aValue
- intthis
is instantiated to val
, false otherwisepublic boolean contains(int aValue)
IntVar
v
belongs to the domain of this
public int getValue()
public ESat getBooleanValue()
getBooleanValue
in interface BoolVar
public int getLB()
public int getUB()
public int getDomainSize()
IntVar
getDomainSize
in interface IntVar
public int getRange()
IntVar
public int nextValue(int v)
IntVar
this
.
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 }
public int previousValue(int v)
IntVar
this
.
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 }
previousValue
in interface IntVar
v
- the value to start checking (exclusive)public boolean hasEnumeratedDomain()
IntVar
this
has an enumerated domain (represented in extension)
or not (only bounds)hasEnumeratedDomain
in interface IntVar
true
if the domain is enumerated, false
otherwise.public IEnumDelta getDelta()
Variable
public String toString()
toString
in class AbstractVariable
public void createDelta()
Variable
createDelta
in interface Variable
public IIntDeltaMonitor monitorDelta(ICause propagator)
IntVar
this
.monitorDelta
in interface IntVar
propagator
- the cause that requires to monitor deltapublic void notifyMonitors(IEventType event) throws ContradictionException
Variable
notifyMonitors
in interface Variable
event
- the event which occurred on the variableContradictionException
- if the monitor detects contradiction.public void contradiction(ICause cause, String message) throws ContradictionException
Variable
contradiction
in interface Variable
cause
- ICause causing the exceptionmessage
- the detailed message @throws ContradictionException expected behaviorContradictionException
- the build contradiction.public int getTypeAndKind()
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;
getTypeAndKind
in interface Variable
public DisposableValueIterator getValueIterator(boolean bottomUp)
IntVar
this
.
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.
getValueIterator
in interface IntVar
bottomUp
- way to iterate over values. true
means from lower bound to upper bound,
false
means from upper bound to lower bound.this
.public DisposableRangeIterator getRangeIterator(boolean bottomUp)
IntVar
this
.
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.
getRangeIterator
in interface IntVar
bottomUp
- way to iterate over ranges. true
means from lower bound to upper bound,
false
means from upper bound to lower bound.this
.public boolean isLit()
ILogical
public boolean isNot()
ILogical
public void setNot(boolean isNot)
ILogical
Copyright © 2015. All rights reserved.