Class AbstractVariable

    • 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 in monitors.
    • Constructor Detail

      • AbstractVariable

        protected AbstractVariable​(String name,
                                   Model model)
        Create the shared data of any type of variable.
        Parameters:
        name - name of the variable
        model - model which declares this variable
    • Method Detail

      • createScheduler

        protected abstract EvtScheduler createScheduler()
      • getId

        public final int getId()
        Specified by:
        getId in interface Identity
      • link

        public final int link​(Propagator propagator,
                              int idxInProp)
        Description copied from interface: Variable
        Link the propagator to this
        Specified by:
        link in interface Variable
        Parameters:
        propagator - a newly added propagator
        idxInProp - index of the variable in the propagator
        Returns:
        return the index of the propagator within the variable
      • 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 interface Variable
        Parameters:
        propagator - the propagator to swap
        idxInProp - 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 interface Variable
        Parameters:
        propagator - the propagator to swap
        idxInProp - 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 of this. SHOULD BE CONTAINED IN THIS.
        Specified by:
        unlink in interface Variable
        Parameters:
        propagator - the propagator to remove
        idxInProp - index of the variable in the propagator
      • getPropagators

        public final Propagator[] getPropagators()
        Description copied from interface: Variable
        Return the array of propagators this
        Specified by:
        getPropagators in interface Variable
        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 interface Variable
        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 interface Variable
        Returns:
        number of propagators of this
      • getPIndices

        public final int[] getPIndices()
        Specified by:
        getPIndices in interface Variable
        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 in Variable.getPropagators().
        Specified by:
        setPIndice in interface Variable
        Parameters:
        pos - position of the propagator
        val - 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 of is, passed as parameter, which help returning the right propagators.
        Specified by:
        getDindex in interface Variable
        Parameters:
        i - dependency index
        Returns:
        index of the first propagator associated with that dependency.
      • 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 interface Variable
        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 of this
        Specified by:
        getName in interface Variable
        Returns:
        a String representing the name of this
      • notifyPropagators

        public void notifyPropagators​(IEventType event,
                                      ICause cause)
                               throws ContradictionException
        Description copied from interface: Variable
        If this has changed, then notify all of its observers.
        Each observer has its update method.
        Specified by:
        notifyPropagators in interface Variable
        Parameters:
        event - event on this object
        cause - object which leads to the modification of this object
        Throws:
        ContradictionException - if a contradiction occurs during notification
      • addMonitor

        public void addMonitor​(IVariableMonitor monitor)
        Description copied from interface: Variable
        Build and add a monitor to the monitor list of this. The monitor is inactive at the creation and must be activated (by the engine propagation).
        Specified by:
        addMonitor in interface Variable
        Parameters:
        monitor - a variable monitor
      • removeMonitor

        public void removeMonitor​(IVariableMonitor monitor)
        Description copied from interface: Variable
        Removes monitor form the list of this variable's monitors.
        Specified by:
        removeMonitor in interface Variable
        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 interface Variable
        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 interface Variable
        Parameters:
        cause - ICause causing the exception
        message - 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
        Specified by:
        getModel in interface Variable
        Returns:
        a Model object
      • getNbViews

        public int getNbViews()
        Specified by:
        getNbViews in interface Variable
        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 position Variable.getNbViews() excluded.
        Specified by:
        getView in interface Variable
        Parameters:
        idx - position of the view to return
        Returns:
        view observing this variable, at position p
      • 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 interface Variable
        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 interface Variable
        Returns:
        the event scheduler
      • asIntVar

        public IntVar asIntVar()
        Specified by:
        asIntVar in interface Variable
        Returns:
        this cast into an IntVar.
      • asBoolVar

        public BoolVar asBoolVar()
        Specified by:
        asBoolVar in interface Variable
        Returns:
        this cast into an BoolVar.
      • asRealVar

        public RealVar asRealVar()
        Specified by:
        asRealVar in interface Variable
        Returns:
        this cast into an RealVar.
      • asSetVar

        public SetVar asSetVar()
        Specified by:
        asSetVar in interface Variable
        Returns:
        this cast into an SetVar.
      • 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 interface Variable
        Parameters:
        m - event's mask
        cause - what causes the modification (cannot be null)