Class ModalModel
- java.lang.Object
-
- 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)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description 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, _derivedPiggybacks, _initializables, _notifyingActorFiring, _piggybacks, _publishedPorts, _publisherRelations, _stopRequested, _subscribedPorts
-
Fields inherited from class ptolemy.kernel.CompositeEntity
_levelCrossingLinks
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
exportMoML(java.io.Writer output, int depth, java.lang.String name)
Override the base class to remove any unused refinements before exporting.Attribute
getAttribute(java.lang.String name)
Get the attribute with the given name.CausalityInterface
getCausalityInterface()
Get representation of dependencies between input ports and output ports.FSMActor
getController()
Get the FSM controller.boolean
handleModelError(NamedObj context, IllegalActionException exception)
Handle a model error.void
initialize()
Initialize the mode controller and all the refinements by calling the initialize() method in the super class.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.actor.TypedCompositeActor
_addEntity, _addPort, _addRelation, _checkTypesFromTo, _destinationTypeConstraints, attributeTypeChanged, isBackwardTypeInferenceEnabled, newRelation, resolveTypes, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.CompositeActor
_actorFiring, _actorFiring, _finishedAddEntity, _setDirector, _transferPortParameterInputs, addActorFiringListener, addInitializable, addPiggyback, connectionsChanged, createReceivers, createSchedule, fire, getDirector, getExecutiveDirector, getManager, getPublishedPort, getPublishedPortChannel, getPublishedPorts, getSubscribedPortChannel, inferringWidths, inferWidths, inputPortList, isFireFunctional, isOpaque, isPublishedPort, isStrict, iterate, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, needsWidthInference, newInsideReceiver, newReceiver, notifyConnectivityChange, outputPortList, postfire, prefire, preinitialize, recordFiring, registerPublisherPort, registerPublisherPort, removeActorFiringListener, removeInitializable, removePiggyback, requestChange, setContainer, setDirector, setManager, stop, stopFire, terminate, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unregisterPublisherPort, unregisterPublisherPort, wrapup
-
Methods inherited from class ptolemy.kernel.CompositeEntity
_adjustDeferrals, _containedDecorators, _deepOpaqueEntityList, _description, _exportMoMLContents, _removeEntity, _removeRelation, _validateSettables, allAtomicEntityList, allowLevelCrossingConnect, classDefinitionList, connect, connect, containedObjectsIterator, deepCompositeEntityList, deepEntityList, deepGetEntities, deepNamedObjList, deepOpaqueEntityList, deepRelationSet, entityList, entityList, exportLinks, getEntities, getEntity, getPort, getRelation, getRelations, isAtomic, lazyAllAtomicEntityList, lazyAllCompositeEntityList, lazyAllCompositeTransparentAndOpaqueEntityList, 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, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, clone, decorators, 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, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, 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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
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.
-
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 classTypedCompositeActor
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- Not thrown in this base class. Derived classes can throw this exception if type change is not allowed.
-
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 interfaceChangeListener
- 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 interfaceChangeListener
- 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 classCompositeActor
- 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 interfaceMoMLExportable
- Overrides:
exportMoML
in classCompositeEntity
- 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 classCompositeEntity
- Parameters:
name
- The name of the desired attribute.- Returns:
- The requested attribute if it is found, null otherwise.
-
getCausalityInterface
public CausalityInterface getCausalityInterface()
Get representation of dependencies between input ports and output ports.- Specified by:
getCausalityInterface
in interfaceActor
- Overrides:
getCausalityInterface
in classCompositeActor
- Returns:
- A representation of the dependencies between input ports and output ports.
-
getController
public FSMActor getController()
Get the FSM controller.- Returns:
- The FSM controller.
-
handleModelError
public boolean handleModelError(NamedObj context, IllegalActionException exception) throws IllegalActionException
Handle a model error.- Specified by:
handleModelError
in interfaceModelErrorHandler
- Overrides:
handleModelError
in classNamedObj
- Parameters:
context
- The object in which the error occurred.exception
- An exception that represents the error.- Returns:
- True if the error has been handled, or false if the error is not handled.
- Throws:
IllegalActionException
- If the handler handles the error by throwing an exception.- See Also:
NamedObj.setModelErrorHandler(ModelErrorHandler handler)
-
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 interfaceInitializable
- Overrides:
initialize
in classCompositeActor
- 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 classTypedCompositeActor
- 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.
-
-