- java.lang.Object
-
- org.chocosolver.solver.variables.impl.AbstractVariable
-
- All Implemented Interfaces:
Comparable<Variable>
,Identity
,Variable
- Direct Known Subclasses:
BitsetArrayIntVarImpl
,BitsetIntVarImpl
,BoolVarImpl
,FixedIntVarImpl
,FixedRealVarImpl
,IntervalIntVarImpl
,IntView
,RealVarImpl
,RealView
,SetVarImpl
public abstract class AbstractVariable extends Object implements Variable
Class used to factorise code The subclass must implement Variable interface- Since:
- 30 june 2011
- Author:
- Jean-Guillaume Fages, Charles Prud'homme
-
-
Field Summary
Fields Modifier and Type Field Description protected int
mIdx
Index of the last not null monitor inmonitors
.protected Model
model
Reference to the model containing this variable (unique).protected IVariableMonitor[]
monitors
List of monitors observing this variable.protected static String
MSG_EMPTY
Message associated with domain wipe out exception.protected static String
MSG_INST
Message associated with double instantiation exception.protected String
name
Name of the variable.protected Propagator[]
propagators
List of propagators of this variable.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractVariable(String name, Model model)
Create the shared data of any type of variable.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addMonitor(IVariableMonitor monitor)
Build and add a monitor to the monitor list ofthis
.BoolVar
asBoolVar()
IntVar
asIntVar()
RealVar
asRealVar()
SetVar
asSetVar()
void
clearEvents()
Clear events stored temporarily byVariable.storeEvents(int, ICause)
int
compareTo(Variable o)
void
contradiction(ICause cause, String message)
Throws a contradiction exception based onprotected abstract EvtScheduler
createScheduler()
ICause
getCause()
int
getDindex(int i)
This variable's propagators are stored in specific way which ease iteration based on propagation conditions.EvtScheduler
getEvtScheduler()
For scheduling purpose onlyint
getId()
int
getIndexInPropagator(int pidx)
Return the position of the variable in the propagator at position pidxint
getMask()
Model
getModel()
Return the associated modelString
getName()
Returns the name ofthis
int
getNbProps()
Return the number of propagatorsint
getNbViews()
int[]
getPIndices()
Propagator
getPropagator(int idx)
Return the "idx" th propagator of thisPropagator[]
getPropagators()
Return the array of propagators thisIView
getView(int idx)
Get the view at position p in this variable views.boolean
isAConstant()
boolean
isBool()
int
link(Propagator propagator, int idxInProp)
Link the propagator to thisvoid
notifyMonitors(IEventType event)
Notify monitors of observed variable modificationsvoid
notifyPropagators(IEventType event, ICause cause)
Ifthis
has changed, then notify all of its observers.
Each observer has its update method.void
notifyViews(IEventType event, ICause cause)
Notify views of observed variable modificationsvoid
removeMonitor(IVariableMonitor monitor)
Removesmonitor
form the list of this variable's monitors.void
setPIndice(int pos, int val)
Update the position of the variable in the propagator at position inVariable.getPropagators()
.void
storeEvents(int m, ICause cause)
Temporarily store modification events made on this.void
subscribeView(IView view)
Attaches a view to this variable.int
swapOnActivate(Propagator propagator, int idxInProp)
The propagator will be informed back of any modification of this.int
swapOnPassivate(Propagator propagator, int idxInProp)
The propagator will not be informed of any modification of this anymore.String
toString()
void
unlink(Propagator propagator, int idxInProp)
Remove a propagator from the list of propagator ofthis
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.chocosolver.solver.variables.Variable
createDelta, getDelta, getEnvironment, getTypeAndKind, isInstantiated
-
-
-
-
Field Detail
-
MSG_EMPTY
protected static final String MSG_EMPTY
Message associated with domain wipe out exception.- See Also:
- Constant Field Values
-
MSG_INST
protected static final String MSG_INST
Message associated with double instantiation exception.- See Also:
- Constant Field Values
-
model
protected final Model model
Reference to the model containing this variable (unique).
-
name
protected final String name
Name of the variable.
-
propagators
protected Propagator[] propagators
List of propagators of this variable.
-
monitors
protected IVariableMonitor[] monitors
List of monitors observing this variable.
-
mIdx
protected int mIdx
Index of the last not null monitor inmonitors
.
-
-
Method Detail
-
createScheduler
protected abstract EvtScheduler createScheduler()
-
link
public final int link(Propagator propagator, int idxInProp)
Description copied from interface:Variable
Link the propagator to this
-
swapOnPassivate
public int swapOnPassivate(Propagator propagator, int idxInProp)
Description copied from interface:Variable
The propagator will not be informed of any modification of this anymore.- Specified by:
swapOnPassivate
in interfaceVariable
- Parameters:
propagator
- the propagator to swapidxInProp
- index of the variable in the propagator- Returns:
- return the index of the propagator within the variable
-
swapOnActivate
public int swapOnActivate(Propagator propagator, int idxInProp)
Description copied from interface:Variable
The propagator will be informed back of any modification of this.- Specified by:
swapOnActivate
in interfaceVariable
- Parameters:
propagator
- the propagator to swapidxInProp
- index of the variable in the propagator- Returns:
- return the index of the propagator within the variable
-
unlink
public final void unlink(Propagator propagator, int idxInProp)
Description copied from interface:Variable
Remove a propagator from the list of propagator ofthis
. SHOULD BE CONTAINED IN THIS.
-
getPropagators
public final Propagator[] getPropagators()
Description copied from interface:Variable
Return the array of propagators this- Specified by:
getPropagators
in interfaceVariable
- Returns:
- the array of proapgators of this
-
getPropagator
public final Propagator getPropagator(int idx)
Description copied from interface:Variable
Return the "idx" th propagator of this- Specified by:
getPropagator
in interfaceVariable
- Parameters:
idx
- position of the propagator- Returns:
- a propagator
-
getNbProps
public final int getNbProps()
Description copied from interface:Variable
Return the number of propagators- Specified by:
getNbProps
in interfaceVariable
- Returns:
- number of propagators of this
-
getPIndices
public final int[] getPIndices()
- Specified by:
getPIndices
in interfaceVariable
- Returns:
- the array of indices of this variable in its propagators.
-
setPIndice
public final void setPIndice(int pos, int val)
Description copied from interface:Variable
Update the position of the variable in the propagator at position inVariable.getPropagators()
.- Specified by:
setPIndice
in interfaceVariable
- Parameters:
pos
- position of the propagatorval
- position of this variable in the propagator
-
getDindex
public final int getDindex(int i)
Description copied from interface:Variable
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 ofi
s, passed as parameter, which help returning the right propagators.
-
getIndexInPropagator
public final int getIndexInPropagator(int pidx)
Description copied from interface:Variable
Return the position of the variable in the propagator at position pidx- Specified by:
getIndexInPropagator
in interfaceVariable
- Parameters:
pidx
- index of the propagator within the list of propagators of this- Returns:
- position of this in the propagator pidx
-
getName
public final String getName()
Description copied from interface:Variable
Returns the name ofthis
-
notifyPropagators
public void notifyPropagators(IEventType event, ICause cause) throws ContradictionException
Description copied from interface:Variable
Ifthis
has changed, then notify all of its observers.
Each observer has its update method.- Specified by:
notifyPropagators
in interfaceVariable
- Parameters:
event
- event on this objectcause
- object which leads to the modification of this object- Throws:
ContradictionException
- if a contradiction occurs during notification
-
notifyMonitors
public void notifyMonitors(IEventType event) throws ContradictionException
Description copied from interface:Variable
Notify monitors of observed variable modifications- Specified by:
notifyMonitors
in interfaceVariable
- Parameters:
event
- the event which occurred on the variable- Throws:
ContradictionException
- if the monitor detects contradiction.
-
notifyViews
public void notifyViews(IEventType event, ICause cause) throws ContradictionException
Description copied from interface:Variable
Notify views of observed variable modifications- Specified by:
notifyViews
in interfaceVariable
- Parameters:
event
- the event which occurred on the variablecause
- the cause of the notification- Throws:
ContradictionException
- if the notification detects contradiction.
-
addMonitor
public void addMonitor(IVariableMonitor monitor)
Description copied from interface:Variable
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).- Specified by:
addMonitor
in interfaceVariable
- Parameters:
monitor
- a variable monitor
-
removeMonitor
public void removeMonitor(IVariableMonitor monitor)
Description copied from interface:Variable
Removesmonitor
form the list of this variable's monitors.- Specified by:
removeMonitor
in interfaceVariable
- Parameters:
monitor
- the monitor to remove.
-
subscribeView
public void subscribeView(IView view)
Description copied from interface:Variable
Attaches a view to this variable.- Specified by:
subscribeView
in interfaceVariable
- Parameters:
view
- a view to add to this variable.
-
contradiction
public final void contradiction(ICause cause, String message) throws ContradictionException
Description copied from interface:Variable
Throws a contradiction exception based on- Specified by:
contradiction
in interfaceVariable
- Parameters:
cause
- ICause causing the exceptionmessage
- the detailed message @throws ContradictionException expected behavior- Throws:
ContradictionException
- the build contradiction.
-
getModel
public final Model getModel()
Description copied from interface:Variable
Return the associated model
-
getNbViews
public int getNbViews()
- Specified by:
getNbViews
in interfaceVariable
- Returns:
- the number of views attached to the variable
-
getView
public IView getView(int idx)
Description copied from interface:Variable
Get the view at position p in this variable views. The array is filled from position 0 to positionVariable.getNbViews()
excluded.
-
compareTo
public int compareTo(Variable o)
- Specified by:
compareTo
in interfaceComparable<Variable>
-
isBool
public final boolean isBool()
- Returns:
- true if this variable has a domain included in [0,1].
-
isAConstant
public final boolean isAConstant()
- Specified by:
isAConstant
in interfaceVariable
- Returns:
- true if this variable has a singleton domain (different from instantiated)
-
getEvtScheduler
public final EvtScheduler getEvtScheduler()
Description copied from interface:Variable
For scheduling purpose only- Specified by:
getEvtScheduler
in interfaceVariable
- Returns:
- the event scheduler
-
asIntVar
public IntVar asIntVar()
-
asBoolVar
public BoolVar asBoolVar()
-
asRealVar
public RealVar asRealVar()
-
asSetVar
public SetVar asSetVar()
-
storeEvents
public void storeEvents(int m, ICause cause)
Description copied from interface:Variable
Temporarily store modification events made on this. This is requiered by the propagation engine.- Specified by:
storeEvents
in interfaceVariable
- Parameters:
m
- event's maskcause
- what causes the modification (cannot be null)
-
clearEvents
public void clearEvents()
Description copied from interface:Variable
Clear events stored temporarily byVariable.storeEvents(int, ICause)
- Specified by:
clearEvents
in interfaceVariable
-
getMask
public int getMask()
- Specified by:
getMask
in interfaceVariable
- Returns:
- possibly aggregated mask stored through by
Variable.storeEvents(int, ICause)
-
getCause
public ICause getCause()
- Specified by:
getCause
in interfaceVariable
- Returns:
- cause stored through by
Variable.storeEvents(int, ICause)
orCause.Null
if differents causes modified this variable (this may happen when a view refers to this).
-
-