ptolemy.domains.fsm.kernel
Class FSMActor

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.domains.fsm.kernel.FSMActor
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, Initializable, TypedActor, ExplicitChangeContext, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
FmvAutomaton, InterfaceAutomaton, ModalController, TDLActor

public class FSMActor
extends CompositeEntity
implements TypedActor, ExplicitChangeContext

An FSMActor contains a set of states and transitions. A transition has a guard expression and a trigger expression. A transition is enabled and can be taken when its guard is true. A transition is triggered and must be taken when its trigger is true. A transition can contain a set of actions.

When an FSMActor is fired, the outgoing transitions of the current state are examined. An IllegalActionException is thrown if there is more than one enabled transition. If there is exactly one enabled transition then it is chosen and the choice actions contained by the transition are executed. An FSMActor does not change state during successive firings in one iteration in order to support domains that iterate to a fixed point. When the FSMActor is postfired, the chosen transition of the latest firing of the actor is committed. The commit actions contained by the transition are executed and the current state of the actor is set to the destination state of the transition.

An FSMActor enters its initial state during initialization. The initial state is the unique state whose isInitialState parameter is true. A final state is a state that has its isFinalState parameter set to true. When the actor reaches a final state, then the postfire method will return false, indicating that the actor does not wish to be fired again.

The guards and actions of FSM transitions are specified using expressions. These expressions are evaluated in the scope returned by getPortScope. This scope binds identifiers for FSM ports as defined in the following paragraph. These identifiers are in the scope of guard and action expressions prior to any variables, and may shadow variables with appropriately chosen names. Given appropriately chosen port names, there may be conflicts between these various identifiers. These conflicts are detected and an exception is thrown during execution.

For every input port, the identifier "portName_channelIndex" refers to the last input received from the port on the given channel. The type of this identifier is the same as the type of the port. This token may have been consumed in the current firing or in a previous firing. The identifier "portName_channelIndex_isPresent" is true if the port consumed an input on the given channel in the current firing of the FSM. The type of this identifier is always boolean. Lastly, the identifier "portName_channelIndexArray" refers the array of all tokens consumed from the port in the last firing. This identifier has an array type whose element type is the type of the corresponding input port. Additionally, for conciseness when referencing single ports, the first channel may be referred to without the channel index, i.e. by the identifiers "portName", "portName_isPresent", and "portNameArray".

An FSMActor can be used in a modal model to represent the mode control logic. A state can have a TypedActor refinement. A transition in an FSMActor can be preemptive or non-preemptive. When a preemptive transition is chosen, the refinement of its source state is not fired. A non-preemptive transition can only be chosen after the refinement of its source state is fired.

By default, this actor has a conservative causality interface, implemented by the DefaultCausalityInterface, which declares that all outputs depend on all inputs. If, however, the enclosing director and all state refinement directors implement the strict actor semantics (as indicated by their implementsStrictActorSemantics() method), then the returned causality interface is implemented by the FSMCausalityInterface class. 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. See FSMCausalityInterface for details.

Since:
Ptolemy II 0.4
Version:
$Id: FSMActor.java 57046 2010-01-27 23:35:53Z cxh $
Author:
Xiaojun Liu, Haiyang Zheng, Ye Zhou
See Also:
State, Transition, Action, FSMDirector, Serialized Form
Accepted Rating:
Yellow (kienhuis)
Proposed Rating:
Yellow (liuxj)

Nested Class Summary
 class FSMActor.PortScope
          This class implements a scope, which is used to evaluate the parsed expressions.
 
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
 
Field Summary
private  java.util.LinkedList _cachedInputPorts
           
private  java.util.LinkedList _cachedOutputPorts
           
private  CausalityInterface _causalityInterface
          The causality interface, if it has been created, for the case where the causality interface is not state dependent.
private  Director _causalityInterfaceDirector
          The director for which the causality interface was created.
private  java.util.Map<State,FSMCausalityInterface> _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.
private  java.util.Map _connectionMaps
           
private  long _connectionMapsVersion
           
private  java.util.Map _currentConnectionMap
           
protected  State _currentState
          Current state.
private  java.util.HashSet<java.lang.String> _finalStateNames
           
protected  java.util.HashMap _identifierToPort
          A map that associates each identifier with the unique port that that identifier describes.
protected  java.util.List<Initializable> _initializables
          List of objects whose (pre)initialize() and wrapup() methods should be slaved to these.
(package private)  State _initialState
          The initial state.
private  long _inputPortsVersion
           
protected  java.util.Map _inputTokenMap
          A map from ports to corresponding input variables.
protected  Transition _lastChosenTransition
          The last chosen transition.
private  boolean _newIteration
           
private  long _outputPortsVersion
           
private  boolean _reachedFinalState
           
private  long _receiversVersion
           
protected  boolean _stopRequested
          Indicator that a stop has been requested by a call to stop().
private  boolean _supportMultirate
           
private  java.util.Hashtable _tokenListArrays
           
 StringAttribute finalStateNames
          Attribute specifying the names of the final states of this actor.
 StringAttribute initialStateName
          Attribute specifying the name of the initial state of this actor.
 Parameter stateDependentCausality
          Indicate whether input/output dependencies can depend on the state.
 
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
 
Constructor Summary
FSMActor()
          Construct an FSMActor in the default workspace with an empty string as its name.
FSMActor(CompositeEntity container, java.lang.String name)
          Create an FSMActor in the specified container with the specified name.
FSMActor(Workspace workspace)
          Construct an FSMActor in the specified workspace with an empty string as its name.
 
Method Summary
protected  void _addEntity(ComponentEntity entity)
          Add a state to this FSMActor.
protected  void _addRelation(ComponentRelation relation)
          Add a transition to this FSMActor.
private  void _buildConnectionMaps()
           
protected  void _commitLastChosenTransition()
          Execute all commit actions contained by the transition chosen during the last call to _chooseTransition().
private  void _createReceivers()
          Create receivers for each input port.
private  void _init()
           
protected  boolean _isRefinementOutput(IOPort port, int channel)
          Return true if the channel of the port is connected to an output port of the refinement of current state.
private  void _parseFinalStates(java.lang.String names)
          Parse the final state names.
protected  void _readInputs(IOPort port, int channel)
          Read tokens from the given channel of the given input port and make them accessible to the expressions of guards and transitions through the port scope.
private  void _resetReceivers()
          Reset receivers for each input port.
protected  void _setCurrentConnectionMap()
          Set the map from input ports to boolean flags indicating whether a channel is connected to an output port of the refinement of the current state.
private  void _setIdentifierToPort(java.lang.String name, Port inputPort)
           
private  void _setInputTokenMap(java.lang.String name, Port inputPort, Token token)
           
private  void _setTimeForRefinement(Actor refinement)
          If the specified refinement implements Suspendable, then set its current time equal to the current environment time minus the refinement's total accumulated suspension time.
 void addInitializable(Initializable initializable)
          Add the specified object to the list of objects whose preinitialize(), intialize(), and wrapup() methods should be invoked upon invocation of the corresponding methods of this object.
 void attributeChanged(Attribute attribute)
          React to a change in an attribute.
 Transition chooseTransition(java.util.List transitionList)
          Return an enabled transition among the given list of transitions.
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 void createReceivers()
          Create receivers for each input port.
 State currentState()
          Return the current state of this actor.
 java.util.List enabledTransitions(java.util.List transitionList)
          Return a list of enabled transitions among the given list of transitions.
 void exportSubmodel(java.io.Writer output, int depth, java.lang.String name)
          Write this FSMActor into the output writer as a submodel.
 void fire()
          Set the values of input variables.
 CausalityInterface getCausalityInterface()
          Return a causality interface for this actor.
 Entity getContext()
          Return the change context being made explicit.
 Director getDirector()
          Return the director responsible for the execution of this actor.
 Director getExecutiveDirector()
          Return the executive director (same as getDirector()).
 State getInitialState()
          Return the initial state of this actor.
 Manager getManager()
          Return the Manager responsible for execution of this actor, if there is one.
 java.util.List getModifiedVariables()
          Return a list of variables that this entity modifies.
 ParserScope getPortScope()
          Return a scope object that has current values from input ports of this FSMActor in scope.
 boolean hasInput()
          Test whether new input tokens have been received at the input ports.
 boolean hasInput(Port port)
          Test whether new input tokens have been received at the given input port.
 void initialize()
          Initialize this actor by setting the current state to the initial state.
 java.util.List inputPortList()
          Return a list of the input ports.
 boolean isFireFunctional()
          Return false.
 boolean isOpaque()
          Return true.
 boolean isStrict()
          Return false if there is any output does not depend directly on all inputs.
 int iterate(int count)
          Invoke a specified number of iterations of the actor.
 Port newPort(java.lang.String name)
          Create a new TypedIOPort with the specified name.
 Receiver newReceiver()
          Return a new receiver obtained from the director.
 ComponentRelation newRelation(java.lang.String name)
          Create a new instance of Transition with the specified name in this actor, and return it.
 java.util.List outputPortList()
          Return a list of the output ports.
 boolean postfire()
          Execute actions on the last chosen transition.
 boolean prefire()
          Return true.
 void preinitialize()
          Create receivers and input variables for the input ports of this actor, and validate attributes of this actor, and attributes of the ports of this actor.
 void readInputs()
          Set the value of the shadow variables for input ports of this actor.
 void readOutputsFromRefinement()
          Set the input variables for channels that are connected to an output port of the refinement of current state.
 void removeInitializable(Initializable initializable)
          Remove the specified object from the list of objects whose preinitialize(), intialize(), and wrapup() methods should be invoked upon invocation of the corresponding methods of this object.
 void reset()
          Reset current state to the initial state.
 void setLastChosenTransition(Transition transition)
          Set the last chosen transition.
 void setNewIteration(boolean newIteration)
          Set the flag indicating whether we are at the start of a new iteration (firing).
 void setSupportMultirate(boolean supportMultirate)
          Set true indicating that this actor supports multirate firing.
 void stop()
          Request that execution of the current iteration stop as soon as possible.
 void stopFire()
          Do nothing.
 void terminate()
          Call stop().
 java.util.Set<Inequality> typeConstraints()
          Return the type constraints of this actor.
 void wrapup()
          Do nothing except invoke the wrapup method of any objects that have been added using addInitializable().
 
Methods inherited from class ptolemy.kernel.CompositeEntity
_adjustDeferrals, _deepOpaqueEntityList, _description, _exportMoMLContents, _finishedAddEntity, _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, setContainer, statistics, uniqueName
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_addPort, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_removePort, connectedPortList, connectedPorts, connectionsChanged, 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, requestChange, 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.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

finalStateNames

public StringAttribute finalStateNames
Attribute specifying the names of the final states of this actor. This attribute is kept for backward compatibility only, and is set to expert visibility. To set the final states, set the isFinalState parameter of a States.


initialStateName

public StringAttribute initialStateName
Attribute specifying the name of the initial state of this actor. This attribute is kept for backward compatibility only, and is set to expert visibility. To set the initial state, set the isInitialState parameter of a State.


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.


_currentState

protected State _currentState
Current state.


_identifierToPort

protected java.util.HashMap _identifierToPort
A map that associates each identifier with the unique port that that identifier describes. This map is used to detect port names that result in ambiguous identifier bindings.


_initializables

protected transient java.util.List<Initializable> _initializables
List of objects whose (pre)initialize() and wrapup() methods should be slaved to these.


_inputTokenMap

protected java.util.Map _inputTokenMap
A map from ports to corresponding input variables.


_lastChosenTransition

protected Transition _lastChosenTransition
The last chosen transition.


_stopRequested

protected boolean _stopRequested
Indicator that a stop has been requested by a call to stop().


_initialState

State _initialState
The initial state. This is package friendly so that State can access it.


_cachedInputPorts

private transient java.util.LinkedList _cachedInputPorts

_cachedOutputPorts

private transient java.util.LinkedList _cachedOutputPorts

_causalityInterface

private CausalityInterface _causalityInterface
The causality interface, if it has been created, for the case where the causality interface is not state dependent.


_causalityInterfaceDirector

private Director _causalityInterfaceDirector
The director for which the causality interface was created.


_causalityInterfaces

private java.util.Map<State,FSMCausalityInterface> _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.


_connectionMaps

private java.util.Map _connectionMaps

_connectionMapsVersion

private long _connectionMapsVersion

_currentConnectionMap

private java.util.Map _currentConnectionMap

_finalStateNames

private java.util.HashSet<java.lang.String> _finalStateNames

_inputPortsVersion

private transient long _inputPortsVersion

_newIteration

private boolean _newIteration

_outputPortsVersion

private transient long _outputPortsVersion

_reachedFinalState

private boolean _reachedFinalState

_receiversVersion

private long _receiversVersion

_supportMultirate

private boolean _supportMultirate

_tokenListArrays

private java.util.Hashtable _tokenListArrays
Constructor Detail

FSMActor

public FSMActor()
Construct an FSMActor in the default workspace with an empty string as its name. Add the actor to the workspace directory. Increment the version number of the workspace.


FSMActor

public FSMActor(CompositeEntity container,
                java.lang.String name)
         throws IllegalActionException,
                NameDuplicationException
Create an FSMActor in the specified container with the specified name. The name must be unique within the container or an exception is thrown. The container argument must not be null, or a NullPointerException will be thrown.

Parameters:
container - The container.
name - The name of this actor within the container.
Throws:
IllegalActionException - If the entity cannot be contained by the proposed container.
NameDuplicationException - If the name coincides with an entity already in the container.

FSMActor

public FSMActor(Workspace workspace)
Construct an FSMActor in the specified workspace with an empty string as its name. You can then change the name with setName(). If the workspace argument is null, then use the default workspace. Add the actor to the workspace directory. Increment the version number of the workspace.

Parameters:
workspace - The workspace that will list the actor.
Method Detail

addInitializable

public void addInitializable(Initializable initializable)
Add the specified object to the list of objects whose preinitialize(), intialize(), and wrapup() methods should be invoked upon invocation of the corresponding methods of this object.

Specified by:
addInitializable in interface Initializable
Parameters:
initializable - The object whose methods should be invoked.
See Also:
removeInitializable(Initializable), CompositeActor.addPiggyback(Executable)

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
React to a change in an attribute.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that changed.
Throws:
IllegalActionException - If thrown by the superclass attributeChanged() method.

chooseTransition

public Transition chooseTransition(java.util.List transitionList)
                            throws IllegalActionException
Return an enabled transition among the given list of transitions. If there is only one transition enabled, return that transition. In case there are multiple enabled transitions, if any of them is not nondeterministic, throw an exception. See Transition for the explanation of "nondeterministic". Otherwise, randomly choose one from the enabled transitions and return it.

Execute the choice actions contained by the returned transition.

Parameters:
transitionList - A list of transitions.
Returns:
An enabled transition, or null if none is enabled.
Throws:
IllegalActionException - If there is more than one transition enabled and not all of them are nondeterministic.

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace. This calls the base class and then sets the attribute public members to refer to the attributes of the new actor.

Overrides:
clone in class CompositeEntity
Parameters:
workspace - The workspace for the new actor.
Returns:
A new FSMActor.
Throws:
java.lang.CloneNotSupportedException - If a derived class contains an attribute that cannot be cloned.
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

createReceivers

public void createReceivers()
                     throws IllegalActionException
Create receivers for each input port. In case the receivers don't need to be created they are reset

Specified by:
createReceivers in interface Actor
Throws:
IllegalActionException - If any port throws it.
See Also:
AtomicActor.createReceivers(), CompositeActor.createReceivers()

currentState

public State currentState()
Return the current state of this actor.

Returns:
The current state of this actor.

enabledTransitions

public java.util.List enabledTransitions(java.util.List transitionList)
                                  throws IllegalActionException
Return a list of enabled transitions among the given list of transitions.

Parameters:
transitionList - A list of transitions.
Returns:
A list of enabled transition.
Throws:
IllegalActionException - If the guard expression of any transition can not be evaluated.

exportSubmodel

public void exportSubmodel(java.io.Writer output,
                           int depth,
                           java.lang.String name)
                    throws java.io.IOException
Write this FSMActor into the output writer as a submodel. All refinements of the events in this FSMActor will be exported as configurations of those events, not as composite entities belonging to the closest modal model.

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.

fire

public void fire()
          throws IllegalActionException
Set the values of input variables. Choose the enabled transition among the outgoing transitions of the current state. Throw an exception if there is more than one transition enabled. Otherwise, execute the choice actions contained by the chosen transition.

Specified by:
fire in interface Executable
Throws:
IllegalActionException - If there is more than one transition enabled.

getCausalityInterface

public CausalityInterface getCausalityInterface()
Return a causality interface for this actor. This method returns an instance of class FSMCausalityInterface if the enclosing director returns true in its implementsStrictActorSemantics() method. Otherwise, it returns an interface of class DefaultCausalityInterface.

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

getContext

public Entity getContext()
Return the change context being made explicit. This class returns this.

Specified by:
getContext in interface ExplicitChangeContext
Returns:
The change context being made explicit

getDirector

public Director getDirector()
Return the director responsible for the execution of this actor. In this class, this is always the executive director. Return null if either there is no container or the container has no director.

Specified by:
getDirector in interface Actor
Returns:
The director that invokes this actor.

getExecutiveDirector

public Director getExecutiveDirector()
Return the executive director (same as getDirector()).

Specified by:
getExecutiveDirector in interface Actor
Returns:
The executive director.

getInitialState

public State getInitialState()
                      throws IllegalActionException
Return the initial state of this actor. The initial state is the unique state with its isInitialState parameter set to true. An exception is thrown if this actor does not contain an initial state. This method is read-synchronized on the workspace.

Returns:
The initial state of this actor.
Throws:
IllegalActionException - If this actor does not contain a state with the specified name.

getManager

public Manager getManager()
Return the Manager responsible for execution of this actor, if there is one. Otherwise, return null.

Specified by:
getManager in interface Actor
Returns:
The manager.

getModifiedVariables

public java.util.List getModifiedVariables()
                                    throws IllegalActionException
Return a list of variables that this entity modifies. The variables are assumed to have a change context of the given entity. This method returns the destinations of all choice and commit identifiers that are deeply contained by this actor. Note that this actor is also used as the controller of modal models and FSMDirector reports destinations of all choice and commit identifiers, even those not contained by the finite state machine.

Specified by:
getModifiedVariables in interface ExplicitChangeContext
Returns:
A list of variables.
Throws:
IllegalActionException - If a valid destination object can not be found.
See Also:
FSMDirector.getModifiedVariables()

getPortScope

public ParserScope getPortScope()
Return a scope object that has current values from input ports of this FSMActor in scope. This scope is used to evaluate guard expressions and set and output actions.

Returns:
A scope object that has current values from input ports of this FSMActor in scope.

hasInput

public boolean hasInput()
Test whether new input tokens have been received at the input ports.

Returns:
true if new input tokens have been received.

hasInput

public boolean hasInput(Port port)
Test whether new input tokens have been received at the given input port.

Parameters:
port - The input port.
Returns:
true if new input tokens have been received.

initialize

public void initialize()
                throws IllegalActionException
Initialize this actor by setting the current state to the initial state.

Specified by:
initialize in interface Initializable
Throws:
IllegalActionException - If a derived class throws it.

inputPortList

public java.util.List inputPortList()
Return a list of the input ports. This method is read-synchronized on the workspace.

Specified by:
inputPortList in interface Actor
Returns:
A list of input IOPort objects.

isFireFunctional

public boolean isFireFunctional()
Return false. During the fire() method, if a transition is enabled, it will be taken and the actions associated with this transition are executed. We assume the actions will change states of this actor.

Specified by:
isFireFunctional in interface Executable
Returns:
False.

isOpaque

public boolean isOpaque()
Return true.

Overrides:
isOpaque in class CompositeEntity
Returns:
True.
See Also:
CompositeEntity

isStrict

public boolean isStrict()
                 throws IllegalActionException
Return false if there is any output does not depend directly on all inputs.

Specified by:
isStrict in interface Executable
Returns:
False if there is any output that does not depend directly on an input.
Throws:
IllegalActionException - Thrown if causality interface cannot be computed.

iterate

public int iterate(int count)
            throws IllegalActionException
Invoke a specified number of iterations of the actor. An iteration is equivalent to invoking prefire(), fire(), and postfire(), in that order. In an iteration, if prefire() returns true, then fire() will be called once, followed by postfire(). Otherwise, if prefire() returns false, fire() and postfire() are not invoked, and this method returns NOT_READY. If postfire() returns false, then no more iterations are invoked, and this method returns STOP_ITERATING. Otherwise, it returns COMPLETED. If stop() is called while this is executing, then cease executing and return STOP_ITERATING.

Specified by:
iterate in interface Executable
Parameters:
count - The number of iterations to perform.
Returns:
NOT_READY, STOP_ITERATING, or COMPLETED.
Throws:
IllegalActionException - If iterating is not permitted, or if prefire(), fire(), or postfire() throw it.

newPort

public Port newPort(java.lang.String name)
             throws NameDuplicationException
Create a new TypedIOPort with the specified name. The container of the port is set to this actor. This method is write-synchronized on the workspace.

Overrides:
newPort in class ComponentEntity
Parameters:
name - The name for the new port.
Returns:
The new port.
Throws:
NameDuplicationException - If the actor already has a port with the specified name.

newReceiver

public Receiver newReceiver()
                     throws IllegalActionException
Return a new receiver obtained from the director.

Specified by:
newReceiver in interface Actor
Returns:
A new object implementing the Receiver interface.
Throws:
IllegalActionException - If there is no director.

newRelation

public ComponentRelation newRelation(java.lang.String name)
                              throws IllegalActionException,
                                     NameDuplicationException
Create a new instance of Transition with the specified name in this actor, and return it. This method is write-synchronized on the workspace.

Overrides:
newRelation in class CompositeEntity
Parameters:
name - The name of the new transition.
Returns:
A transition with the given name.
Throws:
IllegalActionException - If the name argument is null.
NameDuplicationException - If name collides with that of a transition already in this actor.

outputPortList

public java.util.List outputPortList()
Return a list of the output ports. This method is read-synchronized on the workspace.

Specified by:
outputPortList in interface Actor
Returns:
A list of output IOPort objects.

postfire

public boolean postfire()
                 throws IllegalActionException
Execute actions on the last chosen transition. Change state to the destination state of the last chosen transition.

Specified by:
postfire in interface Executable
Returns:
True, unless stop() has been called, in which case, false.
Throws:
IllegalActionException - If any action throws it.

prefire

public boolean prefire()
                throws IllegalActionException
Return true.

Specified by:
prefire in interface Executable
Returns:
True.
Throws:
IllegalActionException - Not thrown in this base class.

preinitialize

public void preinitialize()
                   throws IllegalActionException
Create receivers and input variables for the input ports of this actor, and validate attributes of this actor, and attributes of the ports of this actor. Set current state to the initial state.

Specified by:
preinitialize in interface Initializable
Throws:
IllegalActionException - If this actor does not contain an initial state.

readInputs

public void readInputs()
                throws IllegalActionException
Set the value of the shadow variables for input ports of this actor.

Throws:
IllegalActionException - If a shadow variable cannot take the token read from its corresponding channel (should not occur).

readOutputsFromRefinement

public void readOutputsFromRefinement()
                               throws IllegalActionException
Set the input variables for channels that are connected to an output port of the refinement of current state.

Throws:
IllegalActionException - If a value variable cannot take the token read from its corresponding channel.

removeInitializable

public void removeInitializable(Initializable initializable)
Remove the specified object from the list of objects whose preinitialize(), intialize(), and wrapup() methods should be invoked upon invocation of the corresponding methods of this object. If the specified object is not on the list, do nothing.

Specified by:
removeInitializable in interface Initializable
Parameters:
initializable - The object whose methods should no longer be invoked.
See Also:
addInitializable(Initializable), CompositeActor.removePiggyback(Executable)

reset

public void reset()
           throws IllegalActionException
Reset current state to the initial state.

Throws:
IllegalActionException - If thrown while getting the initial state or setting the current connection map.

setLastChosenTransition

public void setLastChosenTransition(Transition transition)
Set the last chosen transition.

Parameters:
transition - The last chosen transition.

setNewIteration

public void setNewIteration(boolean newIteration)
Set the flag indicating whether we are at the start of a new iteration (firing). Normally, the flag is set to true. It is only set to false in HDF.

Parameters:
newIteration - A boolean variable indicating whether this is a new iteration.

setSupportMultirate

public void setSupportMultirate(boolean supportMultirate)
Set true indicating that this actor supports multirate firing.

Parameters:
supportMultirate - A boolean variable indicating whether this actor supports multirate firing.

stop

public void stop()
Request that execution of the current iteration stop as soon as possible. In this class, we set a flag indicating that this request has been made (the protected variable _stopRequested). This will result in postfire() returning false.

Specified by:
stop in interface Executable

stopFire

public void stopFire()
Do nothing.

Specified by:
stopFire in interface Executable

terminate

public void terminate()
Call stop().

Specified by:
terminate in interface Executable

typeConstraints

public java.util.Set<Inequality> typeConstraints()
Return the type constraints of this actor. The constraints have the form of a set of inequalities. This method first creates constraints such that the type of any input port that does not have its type declared must be less than or equal to the type of any output port that does not have its type declared. Type constraints from the contained Typeables (ports, variables, and parameters) are collected. In addition, type constraints from all the transitions are added. These constraints are determined by the guard and trigger expressions of transitions, and actions contained by the transitions. This method is read-synchronized on the workspace.

Specified by:
typeConstraints in interface TypedActor
Returns:
A list of inequalities.
See Also:
Inequality

wrapup

public void wrapup()
            throws IllegalActionException
Do nothing except invoke the wrapup method of any objects that have been added using addInitializable(). Derived classes override this method to define operations to be performed exactly once at the end of a complete execution of an application. It typically closes files, displays final results, etc.

Specified by:
wrapup in interface Initializable
Throws:
IllegalActionException - Not thrown in this base class.

_addEntity

protected void _addEntity(ComponentEntity entity)
                   throws IllegalActionException,
                          NameDuplicationException
Add a state to this FSMActor. This overrides the base-class method to make sure the argument is an instance of State. This method is not synchronized on the workspace, so the caller should be.

Overrides:
_addEntity in class CompositeEntity
Parameters:
entity - State to contain.
Throws:
IllegalActionException - If the state has no name, or the action would result in a recursive containment structure, or the argument is not an instance of State.
NameDuplicationException - If the name collides with a name already on the state list.

_addRelation

protected void _addRelation(ComponentRelation relation)
                     throws IllegalActionException,
                            NameDuplicationException
Add a transition to this FSMActor. This method should not be used directly. Call the setContainer() method of the transition instead. This method does not set the container of the transition to refer to this container. This method is not synchronized on the workspace, so the caller should be.

Overrides:
_addRelation in class CompositeEntity
Parameters:
relation - Transition to contain.
Throws:
IllegalActionException - If the transition has no name, or is not an instance of Transition.
NameDuplicationException - If the name collides with a name already on the contained transitions list.

_commitLastChosenTransition

protected void _commitLastChosenTransition()
                                    throws IllegalActionException
Execute all commit actions contained by the transition chosen during the last call to _chooseTransition(). Change current state to the destination state of the transition. Reset the refinement of the destination state if the reset parameter of the transition is true.

Throws:
IllegalActionException - If any commit action throws it, or the last chosen transition does not have a destination state.

_isRefinementOutput

protected boolean _isRefinementOutput(IOPort port,
                                      int channel)
                               throws IllegalActionException
Return true if the channel of the port is connected to an output port of the refinement of current state. If the current state does not have refinement, return false.

Parameters:
port - An input port of this actor.
channel - A channel of the input port.
Returns:
True if the channel of the port is connected to an output port of the refinement of current state.
Throws:
IllegalActionException - If the refinement specified for one of the states is not valid.

_readInputs

protected void _readInputs(IOPort port,
                           int channel)
                    throws IllegalActionException
Read tokens from the given channel of the given input port and make them accessible to the expressions of guards and transitions through the port scope. If the specified port is not an input port, then do nothing.

Parameters:
port - An input port of this actor.
channel - A channel of the input port.
Throws:
IllegalActionException - If the port is not contained by this actor.

_setCurrentConnectionMap

protected void _setCurrentConnectionMap()
                                 throws IllegalActionException
Set the map from input ports to boolean flags indicating whether a channel is connected to an output port of the refinement of the current state.

Throws:
IllegalActionException - If the refinement specified for one of the states is not valid.

_buildConnectionMaps

private void _buildConnectionMaps()
                           throws IllegalActionException
Throws:
IllegalActionException

_createReceivers

private void _createReceivers()
                       throws IllegalActionException
Create receivers for each input port. This method gets write permission on the workspace.

Throws:
IllegalActionException - If any port throws it.

_init

private void _init()

_parseFinalStates

private void _parseFinalStates(java.lang.String names)
Parse the final state names. This method handles backward compatibility, because it used to be that final states were specified in a parameter of the FSMActor, as a comma-separated list of names. Now, each state has an attribute that indicates whether it is a final state. This method parses the list of names, sets the attribute of each state, and then sets the list to null. If the model is then saved, it will have switched to the modern method for recording final states.


_resetReceivers

private void _resetReceivers()
                      throws IllegalActionException
Reset receivers for each input port.

Throws:
IllegalActionException - If any port throws it.

_setIdentifierToPort

private void _setIdentifierToPort(java.lang.String name,
                                  Port inputPort)
                           throws IllegalActionException
Throws:
IllegalActionException

_setInputTokenMap

private void _setInputTokenMap(java.lang.String name,
                               Port inputPort,
                               Token token)
                        throws IllegalActionException
Throws:
IllegalActionException

_setTimeForRefinement

private void _setTimeForRefinement(Actor refinement)
                            throws IllegalActionException
If the specified refinement implements Suspendable, then set its current time equal to the current environment time minus the refinement's total accumulated suspension time. Otherwise, set current time to match that of the environment. If there is no environment, do nothing.

Parameters:
refinement - The refinement.
Throws:
IllegalActionException - If setModelTime() throws it.