- java.lang.Object
-
- org.chocosolver.solver.variables.impl.AbstractVariable
-
- org.chocosolver.solver.variables.view.IntView<IntVar>
-
- org.chocosolver.solver.variables.view.ScaleView
-
- All Implemented Interfaces:
Comparable<Variable>
,Iterable<Integer>
,ArExpression
,ICause
,Identity
,IntVar
,Variable
,IView
public final class ScaleView extends IntView<IntVar>
declare an IntVar based on X and C, such as X * CBased on "Views and Iterators for Generic Constraint Implementations"
C. Shulte and G. Tack.
Eleventh International Conference on Principles and Practice of Constraint Programming- Since:
- 04/02/11
- 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 int
cste
-
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 boolean
contains(int value)
Checks if a valuev
belongs to the domain ofthis
protected EvtScheduler
createScheduler()
protected boolean
doInstantiateVar(int value)
Action to execute onIntView.var
when this view requires to instantiate itprotected boolean
doRemoveIntervalFromVar(int from, int to)
Action to execute onIntView.var
when this view requires to remove an interval from itprotected boolean
doRemoveValueFromVar(int value)
Action to execute onIntView.var
when this view requires to remove a value from itprotected boolean
doUpdateLowerBoundOfVar(int value)
Action to execute onIntView.var
when this view requires to update its lower boundprotected boolean
doUpdateUpperBoundOfVar(int value)
Action to execute onIntView.var
when this view requires to update its upper boundint
getLB()
Retrieves the lower bound of the variableDisposableRangeIterator
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 instantiated, otherwier the lower bound.DisposableValueIterator
getValueIterator(boolean bottomUp)
Retrieves an iterator over values ofthis
.boolean
isInstantiatedTo(int value)
Checks wetherthis
is instantiated toval
void
justifyEvent(IntEventType mask, int one, int two, int three)
This methods is related to explanations, it binds an event occurring on the observed variable to the view.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.String
toString()
-
Methods inherited from class org.chocosolver.solver.variables.view.IntView
compareTo, createDelta, forEachIntVar, getDelta, getDomainSize, getRange, getTypeAndKind, getVariable, hasEnumeratedDomain, instantiateTo, isInstantiated, iterator, notify, removeAllValuesBut, removeInterval, removeValue, removeValues, transformEvent, updateBounds, updateLowerBound, updateUpperBound
-
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, 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 org.chocosolver.solver.variables.IntVar
getNoChild, intVar, isBool, isExpressionLeaf
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface org.chocosolver.solver.variables.Variable
addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, contradiction, getCause, getDindex, getEnvironment, getEvtScheduler, getIndexInPropagator, getMask, getModel, getName, getNbProps, getNbViews, getPIndices, getPropagator, getPropagators, getView, isAConstant, link, notifyMonitors, notifyPropagators, notifyViews, removeMonitor, setPIndice, storeEvents, subscribeView, swapOnActivate, swapOnPassivate, unlink
-
-
-
-
Constructor Detail
-
ScaleView
public ScaleView(IntVar var, int cste)
Create a cste × var view- Parameters:
var
- a variablecste
- a positive integer
-
-
Method Detail
-
monitorDelta
public IIntDeltaMonitor monitorDelta(ICause propagator)
Description copied from interface:IntVar
Allow to monitor removed values ofthis
.- Parameters:
propagator
- the cause that requires to monitor delta- Returns:
- a delta monitor
-
doInstantiateVar
protected boolean doInstantiateVar(int value) throws ContradictionException
Description copied from class:IntView
Action to execute onIntView.var
when this view requires to instantiate it- Overrides:
doInstantiateVar
in classIntView<IntVar>
- Parameters:
value
- value before modification of the view- Returns:
- true if
IntView.var
has been modified - Throws:
ContradictionException
- if modification fails
-
doUpdateLowerBoundOfVar
protected boolean doUpdateLowerBoundOfVar(int value) throws ContradictionException
Description copied from class:IntView
Action to execute onIntView.var
when this view requires to update its lower bound- Overrides:
doUpdateLowerBoundOfVar
in classIntView<IntVar>
- Parameters:
value
- value before modification of the view- Returns:
- true if
IntView.var
has been modified - Throws:
ContradictionException
- if modification fails
-
doUpdateUpperBoundOfVar
protected boolean doUpdateUpperBoundOfVar(int value) throws ContradictionException
Description copied from class:IntView
Action to execute onIntView.var
when this view requires to update its upper bound- Overrides:
doUpdateUpperBoundOfVar
in classIntView<IntVar>
- Parameters:
value
- value before modification of the view- Returns:
- true if
IntView.var
has been modified - Throws:
ContradictionException
- if modification fails
-
doRemoveValueFromVar
protected boolean doRemoveValueFromVar(int value) throws ContradictionException
Description copied from class:IntView
Action to execute onIntView.var
when this view requires to remove a value from it- Overrides:
doRemoveValueFromVar
in classIntView<IntVar>
- Parameters:
value
- value before modification of the view- Returns:
- true if
IntView.var
has been modified - Throws:
ContradictionException
- if modification fails
-
doRemoveIntervalFromVar
protected boolean doRemoveIntervalFromVar(int from, int to) throws ContradictionException
Description copied from class:IntView
Action to execute onIntView.var
when this view requires to remove an interval from it- Overrides:
doRemoveIntervalFromVar
in classIntView<IntVar>
- Parameters:
from
- first value of the interval before modification of the viewto
- last value of the interval before modification of the view- Returns:
- true if
IntView.var
has been modified - Throws:
ContradictionException
- if modification fails
-
contains
public boolean contains(int value)
Description copied from interface:IntVar
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
public boolean isInstantiatedTo(int value)
Description copied from interface:IntVar
Checks wetherthis
is instantiated toval
- Parameters:
value
- int- Returns:
- true if
this
is instantiated toval
, false otherwise
-
getValue
public int getValue()
Description copied from interface:IntVar
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
public int getLB()
Description copied from interface:IntVar
Retrieves the lower bound of the variable- Returns:
- the lower bound
-
getUB
public int getUB()
Description copied from interface:IntVar
Retrieves the upper bound of the variable- Returns:
- the upper bound
-
nextValue
public int nextValue(int v)
Description copied from interface:IntVar
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
public int nextValueOut(int v)
Description copied from interface:IntVar
Returns the first value just after v inthis
which is out of the domain. If v is less than or equal toIntVar.getLB()
-2, returns v + 1, if v is greater than or equal toIntVar.getUB()
, returns v + 1.- Parameters:
v
- the value to start checking (exclusive)- Returns:
- the next value out of the domain
-
previousValue
public int previousValue(int v)
Description copied from interface:IntVar
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
public int previousValueOut(int v)
Description copied from interface:IntVar
Returns the first value just before v inthis
which is out of the domain. If v is greater than or equal toIntVar.getUB()
+2, returns v - 1, if v is less than or equal toIntVar.getLB()
, returns v - 1.- Parameters:
v
- the value to start checking (exclusive)- Returns:
- the previous value out of the domain
-
createScheduler
protected EvtScheduler createScheduler()
- Specified by:
createScheduler
in classAbstractVariable
-
toString
public String toString()
- Overrides:
toString
in classAbstractVariable
-
getValueIterator
public 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 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
.
-
justifyEvent
public void justifyEvent(IntEventType mask, int one, int two, int three)
Description copied from interface:IView
This methods is related to explanations, it binds an event occurring on the observed variable to the view.- Parameters:
mask
- type of modificationone
- an inttwo
- an intthree
- an int
-
-