Class MinusView
- java.lang.Object
-
- org.chocosolver.solver.variables.impl.AbstractVariable
-
- org.chocosolver.solver.variables.view.IntView<IntVar>
-
- org.chocosolver.solver.variables.view.MinusView
-
- All Implemented Interfaces:
Comparable<Variable>,Iterable<Integer>,ArExpression,ICause,Identity,IntVar,Variable,IView
public class MinusView extends IntView<IntVar>
View for -V, where V is a IntVar or viewBased on "Views and Iterators for Generic Constraint Implementations"
C. Shulte and G. Tack.
Eleventh International Conference on Principles and Practice of Constraint Programming- Since:
- 23/08/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 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 booleancontains(int value)Checks if a valuevbelongs to the domain ofthisprotected EvtSchedulercreateScheduler()protected booleandoInstantiateVar(int value)Action to execute onIntView.varwhen this view requires to instantiate itprotected booleandoRemoveIntervalFromVar(int from, int to)Action to execute onIntView.varwhen this view requires to remove an interval from itprotected booleandoRemoveValueFromVar(int value)Action to execute onIntView.varwhen this view requires to remove a value from itprotected booleandoUpdateLowerBoundOfVar(int value)Action to execute onIntView.varwhen this view requires to update its lower boundprotected booleandoUpdateUpperBoundOfVar(int value)Action to execute onIntView.varwhen this view requires to update its upper boundintgetLB()Retrieves the lower bound of the variableDisposableRangeIteratorgetRangeIterator(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.booleanisInstantiatedTo(int value)Checks wetherthisis instantiated tovalvoidjustifyEvent(IntVar var, ICause cause, 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.IIntDeltaMonitormonitorDelta(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.intreverseValue(int value)StringtoString()IEventTypetransformEvent(IEventType evt)inttransformValue(int value)booleanupdateBounds(int lb, int ub, ICause cause)Updates the lower bound and the upper bound of the domain ofthisto, resp.-
Methods inherited from class org.chocosolver.solver.variables.view.IntView
compareTo, createDelta, getDelta, getDomainSize, getRange, getTypeAndKind, getVariable, hasEnumeratedDomain, instantiateTo, isInstantiated, iterator, notify, notifyMonitors, removeAllValuesBut, removeInterval, removeValue, removeValues, updateLowerBound, updateUpperBound, why
-
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, getPIndices, getPropagator, getPropagators, getViews, isAConstant, isBool, link, 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, getPIndices, getPropagator, getPropagators, getViews, isAConstant, link, notifyPropagators, notifyViews, removeMonitor, setPIndice, storeEvents, subscribeView, swapOnActivate, swapOnPassivate, unlink
-
-
-
-
Constructor Detail
-
MinusView
public MinusView(IntVar var)
Create a -var view- Parameters:
var- a integer variable
-
-
Method Detail
-
monitorDelta
public IIntDeltaMonitor monitorDelta(ICause propagator)
Description copied from interface:IntVarAllow to monitor removed values ofthis.- Parameters:
propagator- the cause that requires to monitor delta- Returns:
- a delta monitor
-
updateBounds
public boolean updateBounds(int lb, int ub, ICause cause) throws ContradictionExceptionDescription copied from interface:IntVarUpdates 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
- Specified by:
updateBoundsin interfaceIntVar- Overrides:
updateBoundsin 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
-
doInstantiateVar
protected boolean doInstantiateVar(int value) throws ContradictionExceptionDescription copied from class:IntViewAction to execute onIntView.varwhen this view requires to instantiate it- Overrides:
doInstantiateVarin classIntView<IntVar>- Parameters:
value- value before modification of the view- Returns:
- true if
IntView.varhas been modified - Throws:
ContradictionException- if modification fails
-
doUpdateLowerBoundOfVar
protected boolean doUpdateLowerBoundOfVar(int value) throws ContradictionExceptionDescription copied from class:IntViewAction to execute onIntView.varwhen this view requires to update its lower bound- Overrides:
doUpdateLowerBoundOfVarin classIntView<IntVar>- Parameters:
value- value before modification of the view- Returns:
- true if
IntView.varhas been modified - Throws:
ContradictionException- if modification fails
-
doUpdateUpperBoundOfVar
protected boolean doUpdateUpperBoundOfVar(int value) throws ContradictionExceptionDescription copied from class:IntViewAction to execute onIntView.varwhen this view requires to update its upper bound- Overrides:
doUpdateUpperBoundOfVarin classIntView<IntVar>- Parameters:
value- value before modification of the view- Returns:
- true if
IntView.varhas been modified - Throws:
ContradictionException- if modification fails
-
doRemoveValueFromVar
protected boolean doRemoveValueFromVar(int value) throws ContradictionExceptionDescription copied from class:IntViewAction to execute onIntView.varwhen this view requires to remove a value from it- Overrides:
doRemoveValueFromVarin classIntView<IntVar>- Parameters:
value- value before modification of the view- Returns:
- true if
IntView.varhas been modified - Throws:
ContradictionException- if modification fails
-
doRemoveIntervalFromVar
protected boolean doRemoveIntervalFromVar(int from, int to) throws ContradictionExceptionDescription copied from class:IntViewAction to execute onIntView.varwhen this view requires to remove an interval from it- Overrides:
doRemoveIntervalFromVarin 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.varhas been modified - Throws:
ContradictionException- if modification fails
-
contains
public boolean contains(int value)
Description copied from interface:IntVarChecks if a valuevbelongs to the domain ofthis- Parameters:
value- int- Returns:
trueif the value belongs to the domain ofthis,falseotherwise.
-
isInstantiatedTo
public boolean isInstantiatedTo(int value)
Description copied from interface:IntVarChecks wetherthisis instantiated toval- Parameters:
value- int- Returns:
- true if
thisis instantiated toval, false otherwise
-
getValue
public int getValue()
Description copied from interface:IntVarRetrieves 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:IntVarRetrieves the lower bound of the variable- Returns:
- the lower bound
-
getUB
public int getUB()
Description copied from interface:IntVarRetrieves the upper bound of the variable- Returns:
- the upper bound
-
nextValue
public int nextValue(int v)
Description copied from interface:IntVarReturns 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
public int nextValueOut(int v)
Description copied from interface:IntVarReturns the first value just after v inthiswhich 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:IntVarReturns 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:IntVarReturns the first value just before v inthiswhich 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:
createSchedulerin classAbstractVariable
-
toString
public String toString()
- Overrides:
toStringin classAbstractVariable
-
getValueIterator
public DisposableValueIterator getValueIterator(boolean bottomUp)
Description copied from interface:IntVarRetrieves 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:
getValueIteratorin interfaceIntVar- Overrides:
getValueIteratorin classIntView<IntVar>- 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
public DisposableRangeIterator getRangeIterator(boolean bottomUp)
Description copied from interface:IntVarRetrieves 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:
getRangeIteratorin interfaceIntVar- Overrides:
getRangeIteratorin classIntView<IntVar>- 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.
-
transformValue
public int transformValue(int value)
- Parameters:
value- original value- Returns:
- transforms the original value wrt this IntVar
-
reverseValue
public int reverseValue(int value)
- Parameters:
value- original value- Returns:
- reverses the original value wrt this IntVar
-
transformEvent
public IEventType transformEvent(IEventType evt)
- Specified by:
transformEventin interfaceIntVar- Overrides:
transformEventin classIntView<IntVar>- Parameters:
evt- original event- Returns:
- transforms the original event wrt this IntVar
-
justifyEvent
public void justifyEvent(IntVar var, ICause cause, IntEventType mask, int one, int two, int three)
Description copied from interface:IViewThis methods is related to explanations, it binds an event occurring on the observed variable to the view.- Parameters:
var- modified variablecause- cause of the modificationmask- type of modificationone- an inttwo- an intthree- an int
-
-