ptolemy.domains.fsm.modal
Class ModalModel

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.kernel.CompositeEntity
                      extended by ptolemy.actor.CompositeActor
                          extended by ptolemy.actor.TypedCompositeActor
                              extended by ptolemy.domains.ct.kernel.CTCompositeActor
                                  extended by ptolemy.domains.fsm.modal.ModalModel
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, CTDynamicActor, CTEventGenerator, CTStatefulActor, CTStepSizeControlActor, CTWaveformGenerator, Changeable, ChangeListener, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
Case, TDLModule

public class ModalModel
extends CTCompositeActor
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 2.0
Version:
$Id: ModalModel.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
See Also:
ModalController, Refinement, Serialized Form
Accepted Rating:
Red (reviewmoderator)
Proposed Rating:
Red (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
 
Field Summary
private  java.util.Map<State,MirrorCausalityInterface> _causalityInterfaces
          The causality interfaces by state, for the case where the causality interface is state dependent.
private  java.util.Map<State,java.lang.Long> _causalityInterfacesVersions
          The workspace version for causality interfaces by state, for the case where the causality interface is state dependent.
protected  FSMActor _controller
          The FSM controller.
 StringParameter directorClass
          A director class name.
 Parameter stateDependentCausality
          Indicate whether input/output dependencies can depend on the state.
 
Fields inherited from class ptolemy.actor.CompositeActor
_actorFiringListeners, _causalityInterface, _initializables, _notifyingActorFiring, _publishedPorts, _publisherRelations, _stopRequested
 
Fields inherited from class ptolemy.kernel.CompositeEntity
_levelCrossingLinks
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
ModalModel(CompositeEntity container, java.lang.String name)
          Construct a modal model with a name and a container.
ModalModel(Workspace workspace)
          Construct a modal model in the specified workspace with no container and an empty string as a name.
 
Method Summary
private  void _init()
           
 void attributeChanged(Attribute attribute)
          React to a change of the director or other property.
 void changeExecuted(ChangeRequest change)
          React to a change request has been successfully executed.
 void changeFailed(ChangeRequest change, java.lang.Exception exception)
          React to a change request has resulted in an exception.
 java.lang.Object clone(Workspace workspace)
          Override the base class to ensure that the _controller private variable is reset to the controller of the cloned object.
 boolean containsDynamicActors()
          Return true if any refinements contain at least one dynamic actor.
 boolean containsWaveformGenerators()
          Return true if any refinements contain at least one event generator.
 CausalityInterface getCausalityInterface()
          Get representation of dependencies between input ports and output ports.
 FSMActor getController()
          Get the FSM controller.
 Port newPort(java.lang.String name)
          Create a new port with the specified name in this entity, the controller, and all the refinements.
 
Methods inherited from class ptolemy.domains.ct.kernel.CTCompositeActor
emitCurrentStates, goToMarkedState, hasCurrentEvent, isOutputAccurate, isStateAccurate, markState, predictedStepSize, prefireDynamicActors, refinedStepSize
 
Methods inherited from class ptolemy.actor.TypedCompositeActor
_addEntity, _addPort, _addRelation, _checkTypesFromTo, _typeConstraintsFromTo, newRelation, resolveTypes, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.CompositeActor
_actorFiring, _actorFiring, _finishedAddEntity, _getPublishedPort, _setDirector, addActorFiringListener, addInitializable, addPiggyback, connectionsChanged, createReceivers, createSchedule, fire, getDirector, getExecutiveDirector, getManager, inferringWidths, inferWidths, initialize, inputPortList, isFireFunctional, isOpaque, isStrict, iterate, linkToPublishedPort, linkToPublishedPort, needsWidthInference, newInsideReceiver, newReceiver, notifyConnectivityChange, outputPortList, postfire, prefire, preinitialize, recordFiring, registerPublisherPort, removeActorFiringListener, removeInitializable, removePiggyback, requestChange, setContainer, setDirector, setManager, stop, stopFire, terminate, unlinkToPublishedPort, unlinkToPublishedPort, unregisterPublisherPort, wrapup
 
Methods inherited from class ptolemy.kernel.CompositeEntity
_adjustDeferrals, _deepOpaqueEntityList, _description, _exportMoMLContents, _recordDecoratedAttributes, _removeEntity, _removeRelation, _validateSettables, allAtomicEntityList, allCompositeEntityList, allowLevelCrossingConnect, classDefinitionList, connect, connect, containedObjectsIterator, deepEntityList, deepGetEntities, deepOpaqueEntityList, deepRelationSet, entityList, entityList, exportLinks, exportMoML, getAttribute, getEntities, getEntity, getPort, getRelation, getRelations, isAtomic, lazyAllAtomicEntityList, lazyAllCompositeEntityList, lazyClassDefinitionList, lazyDeepEntityList, lazyEntityList, lazyRelationList, numberOfEntities, numberOfRelations, numEntities, numRelations, relationList, removeAllEntities, removeAllRelations, setClassDefinition, statistics, uniqueName
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_removePort, connectedPortList, connectedPorts, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, attributeTypeChanged, clone, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

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.fsm.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.


_causalityInterfaces

private java.util.Map<State,MirrorCausalityInterface> _causalityInterfaces
The causality interfaces by state, for the case where the causality interface is state dependent.


_causalityInterfacesVersions

private java.util.Map<State,java.lang.Long> _causalityInterfacesVersions
The workspace version for causality interfaces by state, for the case where the causality interface is state dependent.

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.

ModalModel

public ModalModel(CompositeEntity container,
                  java.lang.String name)
           throws IllegalActionException,
                  NameDuplicationException
Construct a modal model with a name and a container. The container argument must not be null, or a NullPointerException will be thrown.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the container is incompatible with this actor.
NameDuplicationException - If the name coincides with an actor already in the container.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
React to a change of the director or other property.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that changed.
Throws:
IllegalActionException - If the change is not acceptable to this container (not thrown in this base class).

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)

containsDynamicActors

public boolean containsDynamicActors()
Return true if any refinements contain at least one dynamic actor.

Overrides:
containsDynamicActors in class CTCompositeActor
Returns:
True if any refinements contain at least one dynamic actor.

containsWaveformGenerators

public boolean containsWaveformGenerators()
Return true if any refinements contain at least one event generator.

Overrides:
containsWaveformGenerators in class CTCompositeActor
Returns:
True if any refinements contain at least one event generator.

getCausalityInterface

public CausalityInterface getCausalityInterface()
Get representation of dependencies between input ports and output ports.

Specified by:
getCausalityInterface in interface Actor
Overrides:
getCausalityInterface in class CompositeActor
Returns:
A representation of the dependencies between input ports and output ports.

getController

public FSMActor getController()
Get the FSM controller.

Returns:
The FSM controller.

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.

_init

private void _init()
            throws IllegalActionException,
                   NameDuplicationException
Throws:
IllegalActionException
NameDuplicationException