Package org.chocosolver.solver.variables
Interface Variable
-
- All Superinterfaces:
Comparable<Variable>,Identity
- All Known Implementing Classes:
AbstractVariable,BitsetArrayIntVarImpl,BitsetIntVarImpl,BoolNotView,BoolVarImpl,FixedBoolVarImpl,FixedIntVarImpl,FixedRealVarImpl,IntervalIntVarImpl,IntView,MinusView,OffsetView,RealVarImpl,RealView,ScaleView,SetVarImpl
public interface Variable extends Identity, Comparable<Variable>
To developers: any constructor of variable must pass in parameter the back-end ISolver, that is, in decreasing order: - the model portfolio, - the model (or portfolio workers but fes). Created by IntelliJ IDEA. User: xlorca, Charles Prud'homme
-
-
Field Summary
Fields Modifier and Type Field Description static intBOOLKind of variable: boolean and integer too (unique).static intCSTEType of variable: fixed (unique).static intINTKind of variable: integer (unique).static intKINDMask to get the kind of a variable.static intREALKind of variable: real.static intSETKind of variable: set.static intTYPEMask to get the type of a variable.static intVARType of variable: variable (unique).static intVIEWType of variable: view (unique).
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddMonitor(IVariableMonitor monitor)Build and add a monitor to the monitor list ofthis.BoolVarasBoolVar()IntVarasIntVar()RealVarasRealVar()SetVarasSetVar()voidclearEvents()Clear events stored temporarily bystoreEvents(int, ICause)voidcontradiction(ICause cause, String message)Throws a contradiction exception based onvoidcreateDelta()Create a delta, if necessary, in order to observe removed values of a this.ICausegetCause()IDeltagetDelta()Return the delta domain of thisintgetDindex(int i)This variable's propagators are stored in specific way which ease iteration based on propagation conditions.default IEnvironmentgetEnvironment()EvtSchedulergetEvtScheduler()For scheduling purpose onlyintgetIndexInPropagator(int pidx)Return the position of the variable in the propagator at position pidxintgetMask()ModelgetModel()Return the associated modelStringgetName()Returns the name ofthisintgetNbProps()Return the number of propagatorsint[]getPIndices()PropagatorgetPropagator(int idx)Return the "idx" th propagator of thisPropagator[]getPropagators()Return the array of propagators thisintgetTypeAndKind()Return a MASK composed of 2 main information: TYPE and KIND.IView[]getViews()Get the views observing this variablesbooleanisAConstant()booleanisInstantiated()Indicates whetherthisis instantiated (see implemtations to know what instantiation means).intlink(Propagator propagator, int idxInProp)Link the propagator to thisvoidnotifyMonitors(IEventType event)Notify monitors of observed variable modificationsvoidnotifyPropagators(IEventType event, ICause cause)Ifthishas changed, then notify all of its observers.
Each observer has its update method.voidnotifyViews(IEventType event, ICause cause)Notify views of observed variable modificationsvoidremoveMonitor(IVariableMonitor monitor)Removesmonitorform the list of this variable's monitors.voidsetPIndice(int pos, int val)Update the position of the variable in the propagator at position ingetPropagators().voidstoreEvents(int mask, ICause cause)Temporarily store modification events made on this.voidsubscribeView(IView view)Attaches a view to this variable.intswapOnActivate(Propagator propagator, int idxInProp)The propagator will be informed back of any modification of this.intswapOnPassivate(Propagator propagator, int idxInProp)The propagator will not be informed of any modification of this anymore.voidunlink(Propagator propagator, int idxInProp)Remove a propagator from the list of propagator ofthis.-
Methods inherited from interface java.lang.Comparable
compareTo
-
-
-
-
Field Detail
-
VAR
static final int VAR
Type of variable: variable (unique).- See Also:
- Constant Field Values
-
CSTE
static final int CSTE
Type of variable: fixed (unique).- See Also:
- Constant Field Values
-
VIEW
static final int VIEW
Type of variable: view (unique).- See Also:
- Constant Field Values
-
TYPE
static final int TYPE
Mask to get the type of a variable.- See Also:
- Constant Field Values
-
INT
static final int INT
Kind of variable: integer (unique).- See Also:
- Constant Field Values
-
BOOL
static final int BOOL
Kind of variable: boolean and integer too (unique).- See Also:
- Constant Field Values
-
SET
static final int SET
Kind of variable: set.- See Also:
- Constant Field Values
-
REAL
static final int REAL
Kind of variable: real.- See Also:
- Constant Field Values
-
KIND
static final int KIND
Mask to get the kind of a variable.- See Also:
- Constant Field Values
-
-
Method Detail
-
isInstantiated
boolean isInstantiated()
Indicates whetherthisis instantiated (see implemtations to know what instantiation means).- Returns:
trueifthisis instantiated
-
getName
String getName()
Returns the name ofthis- Returns:
- a String representing the name of
this
-
getPropagators
Propagator[] getPropagators()
Return the array of propagators this- Returns:
- the array of proapgators of this
-
getPropagator
Propagator getPropagator(int idx)
Return the "idx" th propagator of this- Parameters:
idx- position of the propagator- Returns:
- a propagator
-
getNbProps
int getNbProps()
Return the number of propagators- Returns:
- number of propagators of this
-
getPIndices
int[] getPIndices()
- Returns:
- the array of indices of this variable in its propagators.
-
setPIndice
void setPIndice(int pos, int val)Update the position of the variable in the propagator at position ingetPropagators().- Parameters:
pos- position of the propagatorval- position of this variable in the propagator
-
getDindex
int getDindex(int i)
This variable's propagators are stored in specific way which ease iteration based on propagation conditions. Any event indicates, through the dependency list which propagators should be executed. Thus, an event indicates a list ofis, passed as parameter, which help returning the right propagators.- Parameters:
i- dependency index- Returns:
- index of the first propagator associated with that dependency.
-
getIndexInPropagator
int getIndexInPropagator(int pidx)
Return the position of the variable in the propagator at position pidx- Parameters:
pidx- index of the propagator within the list of propagators of this- Returns:
- position of this in the propagator pidx
-
addMonitor
void addMonitor(IVariableMonitor monitor)
Build and add a monitor to the monitor list ofthis. The monitor is inactive at the creation and must be activated (by the engine propagation).- Parameters:
monitor- a variable monitor
-
removeMonitor
void removeMonitor(IVariableMonitor monitor)
Removesmonitorform the list of this variable's monitors.- Parameters:
monitor- the monitor to remove.
-
subscribeView
void subscribeView(IView view)
Attaches a view to this variable.- Parameters:
view- a view to add to this variable.
-
getDelta
IDelta getDelta()
Return the delta domain of this- Returns:
- the delta domain of the variable
-
createDelta
void createDelta()
Create a delta, if necessary, in order to observe removed values of a this. If the delta already exists, has no effect.
-
link
int link(Propagator propagator, int idxInProp)
Link the propagator to this- Parameters:
propagator- a newly added propagatoridxInProp- index of the variable in the propagator- Returns:
- return the index of the propagator within the variable
-
swapOnPassivate
int swapOnPassivate(Propagator propagator, int idxInProp)
The propagator will not be informed of any modification of this anymore.- Parameters:
propagator- the propagator to swapidxInProp- index of the variable in the propagator- Returns:
- return the index of the propagator within the variable
-
swapOnActivate
int swapOnActivate(Propagator propagator, int idxInProp)
The propagator will be informed back of any modification of this.- Parameters:
propagator- the propagator to swapidxInProp- index of the variable in the propagator- Returns:
- return the index of the propagator within the variable
-
unlink
void unlink(Propagator propagator, int idxInProp)
Remove a propagator from the list of propagator ofthis. SHOULD BE CONTAINED IN THIS.- Parameters:
propagator- the propagator to removeidxInProp- index of the variable in the propagator
-
notifyPropagators
void notifyPropagators(IEventType event, ICause cause) throws ContradictionException
Ifthishas changed, then notify all of its observers.
Each observer has its update method.- Parameters:
event- event on this objectcause- object which leads to the modification of this object- Throws:
ContradictionException- if a contradiction occurs during notification
-
notifyViews
void notifyViews(IEventType event, ICause cause) throws ContradictionException
Notify views of observed variable modifications- Parameters:
event- the event which occurred on the variablecause- the cause of the notification- Throws:
ContradictionException- if the notification detects contradiction.
-
getViews
IView[] getViews()
Get the views observing this variables- Returns:
- views observing this variables
-
notifyMonitors
void notifyMonitors(IEventType event) throws ContradictionException
Notify monitors of observed variable modifications- Parameters:
event- the event which occurred on the variable- Throws:
ContradictionException- if the monitor detects contradiction.
-
contradiction
void contradiction(ICause cause, String message) throws ContradictionException
Throws a contradiction exception based on- Parameters:
cause- ICause causing the exceptionmessage- the detailed message @throws ContradictionException expected behavior- Throws:
ContradictionException- the build contradiction.
-
getModel
Model getModel()
Return the associated model- Returns:
- a Model object
-
getEnvironment
default IEnvironment getEnvironment()
- Returns:
- the backtracking environment used for this variable
-
getTypeAndKind
int getTypeAndKind()
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;- Returns:
- an int representing the type and kind of the variable
-
isAConstant
boolean isAConstant()
- Returns:
- true iff the variable is a constant (created with a singleton domain)
-
getEvtScheduler
EvtScheduler getEvtScheduler()
For scheduling purpose only- Returns:
- the scheduler
-
asIntVar
IntVar asIntVar()
- Returns:
- this cast into an IntVar.
- Throws:
ClassCastException- if type is not compatible
-
asBoolVar
BoolVar asBoolVar()
- Returns:
- this cast into an BoolVar.
- Throws:
ClassCastException- if type is not compatible
-
asRealVar
RealVar asRealVar()
- Returns:
- this cast into an RealVar.
- Throws:
ClassCastException- if type is not compatible
-
asSetVar
SetVar asSetVar()
- Returns:
- this cast into an SetVar.
- Throws:
ClassCastException- if type is not compatible
-
storeEvents
void storeEvents(int mask, ICause cause)Temporarily store modification events made on this. This is requiered by the propagation engine.- Parameters:
mask- event's maskcause- what causes the modification (cannot be null)
-
clearEvents
void clearEvents()
Clear events stored temporarily bystoreEvents(int, ICause)
-
getMask
int getMask()
- Returns:
- possibly aggregated mask stored through by
storeEvents(int, ICause)
-
getCause
ICause getCause()
- Returns:
- cause stored through by
storeEvents(int, ICause)orCause.Nullif differents causes modified this variable (this may happen when a view refers to this).
-
-