|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.kernel.CompositeEntity
ptolemy.domains.fsm.kernel.FSMActor
public class FSMActor
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.
State
,
Transition
,
Action
,
FSMDirector
,
Serialized Form
Yellow (kienhuis) |
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.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 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 |
---|
public StringAttribute finalStateNames
public StringAttribute initialStateName
public Parameter stateDependentCausality
protected State _currentState
protected java.util.HashMap _identifierToPort
protected transient java.util.List<Initializable> _initializables
protected java.util.Map _inputTokenMap
protected Transition _lastChosenTransition
protected boolean _stopRequested
State _initialState
private transient java.util.LinkedList _cachedInputPorts
private transient java.util.LinkedList _cachedOutputPorts
private CausalityInterface _causalityInterface
private Director _causalityInterfaceDirector
private java.util.Map<State,FSMCausalityInterface> _causalityInterfaces
private java.util.Map<State,java.lang.Long> _causalityInterfacesVersions
private java.util.Map _connectionMaps
private long _connectionMapsVersion
private java.util.Map _currentConnectionMap
private java.util.HashSet<java.lang.String> _finalStateNames
private transient long _inputPortsVersion
private boolean _newIteration
private transient long _outputPortsVersion
private boolean _reachedFinalState
private long _receiversVersion
private boolean _supportMultirate
private java.util.Hashtable _tokenListArrays
Constructor Detail |
---|
public FSMActor()
public FSMActor(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of this actor within the container.
IllegalActionException
- If the entity cannot be contained
by the proposed container.
NameDuplicationException
- If the name coincides with
an entity already in the container.public FSMActor(Workspace workspace)
workspace
- The workspace that will list the actor.Method Detail |
---|
public void addInitializable(Initializable initializable)
addInitializable
in interface Initializable
initializable
- The object whose methods should be invoked.removeInitializable(Initializable)
,
CompositeActor.addPiggyback(Executable)
public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class NamedObj
attribute
- The attribute that changed.
IllegalActionException
- If thrown by the superclass
attributeChanged() method.public Transition chooseTransition(java.util.List transitionList) throws IllegalActionException
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.
transitionList
- A list of transitions.
IllegalActionException
- If there is more than one
transition enabled and not all of them are nondeterministic.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class CompositeEntity
workspace
- The workspace for the new actor.
java.lang.CloneNotSupportedException
- If a derived class contains
an attribute that cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public void createReceivers() throws IllegalActionException
createReceivers
in interface Actor
IllegalActionException
- If any port throws it.AtomicActor.createReceivers()
,
CompositeActor.createReceivers()
public State currentState()
public java.util.List enabledTransitions(java.util.List transitionList) throws IllegalActionException
transitionList
- A list of transitions.
IllegalActionException
- If the guard expression of any
transition can not be evaluated.public void exportSubmodel(java.io.Writer output, int depth, java.lang.String name) throws java.io.IOException
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.
java.io.IOException
- If an I/O error occurs.public void fire() throws IllegalActionException
fire
in interface Executable
IllegalActionException
- If there is more than one
transition enabled.public CausalityInterface getCausalityInterface()
FSMCausalityInterface
if the enclosing director
returns true in its implementsStrictActorSemantics() method.
Otherwise, it returns an interface of class
DefaultCausalityInterface
.
getCausalityInterface
in interface Actor
public Entity getContext()
getContext
in interface ExplicitChangeContext
public Director getDirector()
getDirector
in interface Actor
public Director getExecutiveDirector()
getExecutiveDirector
in interface Actor
public State getInitialState() throws IllegalActionException
IllegalActionException
- If this actor does not contain
a state with the specified name.public Manager getManager()
getManager
in interface Actor
public java.util.List getModifiedVariables() throws IllegalActionException
getModifiedVariables
in interface ExplicitChangeContext
IllegalActionException
- If a valid destination object can not
be found.FSMDirector.getModifiedVariables()
public ParserScope getPortScope()
public boolean hasInput()
public boolean hasInput(Port port)
port
- The input port.
public void initialize() throws IllegalActionException
initialize
in interface Initializable
IllegalActionException
- If a derived class throws it.public java.util.List inputPortList()
inputPortList
in interface Actor
public boolean isFireFunctional()
isFireFunctional
in interface Executable
public boolean isOpaque()
isOpaque
in class CompositeEntity
CompositeEntity
public boolean isStrict() throws IllegalActionException
isStrict
in interface Executable
IllegalActionException
- Thrown if causality interface
cannot be computed.public int iterate(int count) throws IllegalActionException
iterate
in interface Executable
count
- The number of iterations to perform.
IllegalActionException
- If iterating is not
permitted, or if prefire(), fire(), or postfire() throw it.public Port newPort(java.lang.String name) throws NameDuplicationException
newPort
in class ComponentEntity
name
- The name for the new port.
NameDuplicationException
- If the actor already has a port
with the specified name.public Receiver newReceiver() throws IllegalActionException
newReceiver
in interface Actor
IllegalActionException
- If there is no director.public ComponentRelation newRelation(java.lang.String name) throws IllegalActionException, NameDuplicationException
newRelation
in class CompositeEntity
name
- The name of the new transition.
IllegalActionException
- If the name argument is null.
NameDuplicationException
- If name collides with that
of a transition already in this actor.public java.util.List outputPortList()
outputPortList
in interface Actor
public boolean postfire() throws IllegalActionException
postfire
in interface Executable
IllegalActionException
- If any action throws it.public boolean prefire() throws IllegalActionException
prefire
in interface Executable
IllegalActionException
- Not thrown in this base class.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
IllegalActionException
- If this actor does not contain an
initial state.public void readInputs() throws IllegalActionException
IllegalActionException
- If a shadow variable cannot take
the token read from its corresponding channel (should not occur).public void readOutputsFromRefinement() throws IllegalActionException
IllegalActionException
- If a value variable cannot take
the token read from its corresponding channel.public void removeInitializable(Initializable initializable)
removeInitializable
in interface Initializable
initializable
- The object whose methods should no longer be invoked.addInitializable(Initializable)
,
CompositeActor.removePiggyback(Executable)
public void reset() throws IllegalActionException
IllegalActionException
- If thrown while
getting the initial state or setting the current connection map.public void setLastChosenTransition(Transition transition)
transition
- The last chosen transition.public void setNewIteration(boolean newIteration)
newIteration
- A boolean variable indicating whether this is
a new iteration.public void setSupportMultirate(boolean supportMultirate)
supportMultirate
- A boolean variable indicating whether this
actor supports multirate firing.public void stop()
stop
in interface Executable
public void stopFire()
stopFire
in interface Executable
public void terminate()
terminate
in interface Executable
public java.util.Set<Inequality> typeConstraints()
typeConstraints
in interface TypedActor
Inequality
public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
IllegalActionException
- Not thrown in this base class.protected void _addEntity(ComponentEntity entity) throws IllegalActionException, NameDuplicationException
_addEntity
in class CompositeEntity
entity
- State to contain.
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.protected void _addRelation(ComponentRelation relation) throws IllegalActionException, NameDuplicationException
_addRelation
in class CompositeEntity
relation
- Transition to contain.
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.protected void _commitLastChosenTransition() throws IllegalActionException
IllegalActionException
- If any commit action throws it,
or the last chosen transition does not have a destination state.protected boolean _isRefinementOutput(IOPort port, int channel) throws IllegalActionException
port
- An input port of this actor.channel
- A channel of the input port.
IllegalActionException
- If the refinement specified for
one of the states is not valid.protected void _readInputs(IOPort port, int channel) throws IllegalActionException
port
- An input port of this actor.channel
- A channel of the input port.
IllegalActionException
- If the port is not contained by
this actor.protected void _setCurrentConnectionMap() throws IllegalActionException
IllegalActionException
- If the refinement specified
for one of the states is not valid.private void _buildConnectionMaps() throws IllegalActionException
IllegalActionException
private void _createReceivers() throws IllegalActionException
IllegalActionException
- If any port throws it.private void _init()
private void _parseFinalStates(java.lang.String names)
private void _resetReceivers() throws IllegalActionException
IllegalActionException
- If any port throws it.private void _setIdentifierToPort(java.lang.String name, Port inputPort) throws IllegalActionException
IllegalActionException
private void _setInputTokenMap(java.lang.String name, Port inputPort, Token token) throws IllegalActionException
IllegalActionException
private void _setTimeForRefinement(Actor refinement) throws IllegalActionException
refinement
- The refinement.
IllegalActionException
- If setModelTime() throws it.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |