Class ModalModel

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, ChangeListener, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
    Direct Known Subclasses:
    Case, FactorOracleTop, MetroIIModalModel, ModalRefinement, PteraModalModel, SCRModel, TDLModule

    public class ModalModel
    extends TypedCompositeActor
    implements ChangeListener
    This is a typed composite actor designed to be a modal model. Inside the modal model is a finite-state machine controller, and inside each state in the FSM is a refinement model. To use this actor, just drag it into a model, and look inside to start constructing the controller. You may add ports to get inputs and outputs, and add states to the controller. You may add one or more refinements to a state (each of these refinements will be executed when this actor is executed). Each refinement is required to have its own director, so you will need to choose a director.

    The controller is a finite-state machine (FSM), which consists of states and transitions. One of the states is an initial state. When this actor executes, if the current state has a refinement, then that refinement is executed. Then the guards on all the outgoing transitions of the current state are evaluated, and if one of those guards is true, then the transition is taken. Taking the transition means that the actions associated with the transition are executed (which can result in producing outputs), and the new current state is the state at the destination of the transition. It is an error if more than one of the guards evaluates to true.

    To add a state, click on a state button in the toolbar, or drag in a state from the library at the left. To add a transition, position the mouse over the source state, hold the control button, and drag to the destination state. The destination state may be the same state, in which case the transition is used simply to execute its actions.

    Adding or removing ports in this actor results in the same ports appearing or disappearing in the FSM controller and in each of the refinements. Similarly, adding or removing ports in the controller or in the refinements results in this actor and the other refinements reflecting the same change to the ports. That is, this actor, the controller, and the refinments all contain the same ports.

    There is one subtlety regarding ports however. If you add an output port to a refinement, then the corresponding port in the controller will be both an input and an output. The reason for this is that the controller can access the results of executing a refinement in order to choose a transition.

    This class is designed to work closely with ModalController and Refinement, since changes to ports can be initiated in this class or in those. It works with continuous-time as well as discrete-time models.

    By default, this actor has a conservative causality interface, which examines the FSMActor controller and all the refinements and defines input/output dependencies that are the oPlus combination of all their dependencies. If the stateDependentCausality is false (the default), then this causality interface in conservative and valid in all states. If it is true, then the causality interface will show different input/output dependencies depending on the state. In each state, only the controller and the current refinement will be considered, and in the controller, only the outgoing transitions from the current state will be considered.

    This class also fulfills the CTEventGenerator interface so that it can report events generated inside.

    Since:
    Ptolemy II 8.0
    Version:
    $Id$
    Author:
    Edward A. Lee and Shanna-Shaye Forbes
    See Also:
    ModalController, Refinement
    Pt.AcceptedRating:
    Red (reviewmoderator)
    Pt.ProposedRating:
    Red (eal)
    • Field Detail

      • directorClass

        public StringParameter directorClass
        A director class name. The default value and the list of choices are obtained from the suggestedModalModelDirectors() method of the executive director. If there is no executive director, then the default is "ptolemy.domains.modal.kernel.FSMDirector".
      • stateDependentCausality

        public Parameter stateDependentCausality
        Indicate whether input/output dependencies can depend on the state. By default, this is false (the default), indicating that a conservative dependency is provided by the causality interface. Specifically, if there is a dependency in any state, then the causality interface indicates that there is a dependency. If this is true, then a less conservative dependency is provided, indicating a dependency only if there can be one in the current state. If this is true, then upon any state transition, this actor issues a change request, which forces causality analysis to be redone. Note that this can be expensive.
      • _controller

        protected FSMActor _controller
        The FSM controller.
    • Constructor Detail

      • ModalModel

        public ModalModel​(Workspace workspace)
                   throws IllegalActionException,
                          NameDuplicationException
        Construct a modal model in the specified workspace with no container and an empty string as a name. You can then change the name with setName(). If the workspace argument is null, then use the default workspace.
        Parameters:
        workspace - The workspace that will list the actor.
        Throws:
        IllegalActionException - If the name has a period in it, or the director is not compatible with the specified container.
        NameDuplicationException - If the container already contains an entity with the specified name.
    • Method Detail

      • changeExecuted

        public void changeExecuted​(ChangeRequest change)
        React to a change request has been successfully executed. This method is called after a change request has been executed successfully. This implementation does nothing.
        Specified by:
        changeExecuted in interface ChangeListener
        Parameters:
        change - The change that has been executed, or null if the change was not done via a ChangeRequest.
      • changeFailed

        public void changeFailed​(ChangeRequest change,
                                 java.lang.Exception exception)
        React to a change request has resulted in an exception. This method is called after a change request was executed, but during the execution an exception was thrown.
        Specified by:
        changeFailed in interface ChangeListener
        Parameters:
        change - The change that was attempted or null if the change was not done via a ChangeRequest.
        exception - The exception that resulted.
      • clone

        public java.lang.Object clone​(Workspace workspace)
                               throws java.lang.CloneNotSupportedException
        Override the base class to ensure that the _controller private variable is reset to the controller of the cloned object.
        Overrides:
        clone in class CompositeActor
        Parameters:
        workspace - The workspace for the cloned object.
        Returns:
        The new Entity.
        Throws:
        java.lang.CloneNotSupportedException - If cloned ports cannot have as their container the cloned entity (this should not occur), or if one of the attributes cannot be cloned.
        See Also:
        NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)
      • exportMoML

        public void exportMoML​(java.io.Writer output,
                               int depth,
                               java.lang.String name)
                        throws java.io.IOException
        Override the base class to remove any unused refinements before exporting.
        Specified by:
        exportMoML in interface MoMLExportable
        Overrides:
        exportMoML in class CompositeEntity
        Parameters:
        output - The output stream to write to.
        depth - The depth in the hierarchy, to determine indenting.
        name - The name to use in the exported MoML.
        Throws:
        java.io.IOException - If an I/O error occurs.
        See Also:
        MoMLExportable
      • getAttribute

        public Attribute getAttribute​(java.lang.String name)
        Get the attribute with the given name. The name may be compound, with fields separated by periods, in which case the attribute returned is contained by a (deeply) contained attribute, port, relation, or entity. If the name contains one or more periods, then it is assumed to be the relative name of an attribute contained by one of the contained attributes, ports, entities or relations. This method is read-synchronized on the workspace.
        Overrides:
        getAttribute in class CompositeEntity
        Parameters:
        name - The name of the desired attribute.
        Returns:
        The requested attribute if it is found, null otherwise.
      • getController

        public FSMActor getController()
        Get the FSM controller.
        Returns:
        The FSM controller.
      • initialize

        public void initialize()
                        throws IllegalActionException
        Initialize the mode controller and all the refinements by calling the initialize() method in the super class. Build the local maps for receivers. Suspend all the refinements of states that are not the current state.
        Specified by:
        initialize in interface Initializable
        Overrides:
        initialize in class CompositeActor
        Throws:
        IllegalActionException - If thrown by the initialize() method of the super class, or can not find mode controller, or can not find refinement of the current state.
      • newPort

        public Port newPort​(java.lang.String name)
                     throws NameDuplicationException
        Create a new port with the specified name in this entity, the controller, and all the refinements. Link these ports so that if the new port is set to be an input, output, or multiport, then the change is mirrored in the other ports. The new port will be an instance of ModalPort, which extends TypedIOPort. This method is write-synchronized on the workspace, and increments its version number.
        Overrides:
        newPort in class TypedCompositeActor
        Parameters:
        name - The name to assign to the newly created port.
        Returns:
        The new port.
        Throws:
        NameDuplicationException - If the entity already has a port with the specified name.