Class AbstractVariable
- 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 intmIdxIndex of the last not null monitor inmonitors.protected ModelmodelReference to the model containing this variable (unique).protected IVariableMonitor[]monitorsList of monitors observing this variable.protected static StringMSG_EMPTYMessage associated with domain wipe out exception.protected static StringMSG_INSTMessage associated with double instantiation exception.protected StringnameName of the variable.protected Propagator[]propagatorsList of propagators of this variable.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractVariable(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 voidaddMonitor(IVariableMonitor monitor)Build and add a monitor to the monitor list ofthis.BoolVarasBoolVar()IntVarasIntVar()RealVarasRealVar()SetVarasSetVar()voidclearEvents()Clear events stored temporarily byVariable.storeEvents(int, ICause)intcompareTo(Variable o)voidcontradiction(ICause cause, String message)Throws a contradiction exception based onprotected abstract EvtSchedulercreateScheduler()ICausegetCause()intgetDindex(int i)This variable's propagators are stored in specific way which ease iteration based on propagation conditions.EvtSchedulergetEvtScheduler()For scheduling purpose onlyintgetId()intgetIndexInPropagator(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 thisIView[]getViews()Get the views observing this variablesbooleanisAConstant()booleanisBool()intlink(Propagator propagator, int idxInProp)Link the propagator to thisvoidnotifyPropagators(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 inVariable.getPropagators().voidstoreEvents(int m, 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.StringtoString()voidunlink(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, notifyMonitors
-
-
-
-
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:VariableLink the propagator to this
-
swapOnPassivate
public int swapOnPassivate(Propagator propagator, int idxInProp)
Description copied from interface:VariableThe propagator will not be informed of any modification of this anymore.- Specified by:
swapOnPassivatein 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:VariableThe propagator will be informed back of any modification of this.- Specified by:
swapOnActivatein 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:VariableRemove a propagator from the list of propagator ofthis. SHOULD BE CONTAINED IN THIS.
-
getPropagators
public final Propagator[] getPropagators()
Description copied from interface:VariableReturn the array of propagators this- Specified by:
getPropagatorsin interfaceVariable- Returns:
- the array of proapgators of this
-
getPropagator
public final Propagator getPropagator(int idx)
Description copied from interface:VariableReturn the "idx" th propagator of this- Specified by:
getPropagatorin interfaceVariable- Parameters:
idx- position of the propagator- Returns:
- a propagator
-
getNbProps
public final int getNbProps()
Description copied from interface:VariableReturn the number of propagators- Specified by:
getNbPropsin interfaceVariable- Returns:
- number of propagators of this
-
getPIndices
public final int[] getPIndices()
- Specified by:
getPIndicesin 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:VariableUpdate the position of the variable in the propagator at position inVariable.getPropagators().- Specified by:
setPIndicein 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:VariableThis 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.
-
getIndexInPropagator
public final int getIndexInPropagator(int pidx)
Description copied from interface:VariableReturn the position of the variable in the propagator at position pidx- Specified by:
getIndexInPropagatorin 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:VariableReturns the name ofthis
-
notifyPropagators
public void notifyPropagators(IEventType event, ICause cause) throws ContradictionException
Description copied from interface:VariableIfthishas changed, then notify all of its observers.
Each observer has its update method.- Specified by:
notifyPropagatorsin interfaceVariable- Parameters:
event- event on this objectcause- object which leads to the modification of this object- Throws:
ContradictionException- if a contradiction occurs during notification
-
notifyViews
public void notifyViews(IEventType event, ICause cause) throws ContradictionException
Description copied from interface:VariableNotify views of observed variable modifications- Specified by:
notifyViewsin 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:VariableBuild 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:
addMonitorin interfaceVariable- Parameters:
monitor- a variable monitor
-
removeMonitor
public void removeMonitor(IVariableMonitor monitor)
Description copied from interface:VariableRemovesmonitorform the list of this variable's monitors.- Specified by:
removeMonitorin interfaceVariable- Parameters:
monitor- the monitor to remove.
-
subscribeView
public void subscribeView(IView view)
Description copied from interface:VariableAttaches a view to this variable.- Specified by:
subscribeViewin 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:VariableThrows a contradiction exception based on- Specified by:
contradictionin 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:VariableReturn the associated model
-
getViews
public final IView[] getViews()
Description copied from interface:VariableGet the views observing this variables
-
compareTo
public int compareTo(Variable o)
- Specified by:
compareToin 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:
isAConstantin interfaceVariable- Returns:
- true if this variable has a singleton domain (different from instantiated)
-
getEvtScheduler
public final EvtScheduler getEvtScheduler()
Description copied from interface:VariableFor scheduling purpose only- Specified by:
getEvtSchedulerin 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:VariableTemporarily store modification events made on this. This is requiered by the propagation engine.- Specified by:
storeEventsin interfaceVariable- Parameters:
m- event's maskcause- what causes the modification (cannot be null)
-
clearEvents
public void clearEvents()
Description copied from interface:VariableClear events stored temporarily byVariable.storeEvents(int, ICause)- Specified by:
clearEventsin interfaceVariable
-
getMask
public int getMask()
- Specified by:
getMaskin interfaceVariable- Returns:
- possibly aggregated mask stored through by
Variable.storeEvents(int, ICause)
-
getCause
public ICause getCause()
- Specified by:
getCausein interfaceVariable- Returns:
- cause stored through by
Variable.storeEvents(int, ICause)orCause.Nullif differents causes modified this variable (this may happen when a view refers to this).
-
-