ptolemy.domains.modal.kernel
Class NonStrictFSMDirector

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.actor.Director
              extended by ptolemy.domains.modal.kernel.FSMDirector
                  extended by ptolemy.domains.modal.kernel.NonStrictFSMDirector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Executable, Initializable, QuasiTransparentDirector, SuperdenseTimeDirector, ExplicitChangeContext, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class NonStrictFSMDirector
extends FSMDirector

This director extends FSMDirector by consuming only input tokens that are needed in the current state. An input port will consume at most one token if:

1. The port is referred by any guard expression of the preemptive transitions leaving the current state, the output actions and/or set actions of the enabled transition.

2. No preemptive transition is enabled and the port is referred by the refinements of the current state, any guard expression of the nonpreemptive transitions leaving the current state, the output actions and/or set actions of the enabled transition.

A port is said to be referred by a guard/output action/set action expression of a transition if the port name appears in that expression. A port is said to be referred by a state refinement if the it is not a dangling port and has a consumption rate greater than zero in the refinement.

FIXME: This is highly preliminary. Missing capabilities: FIXME: Currently this director uses the default receiver of FSMDirector, which is a mailbox, so there is no way to consume more than one token. This director could use a different receiver and support a syntax in the guard expression language to support consumption of more than one token.

Since:
Ptolemy II 8.0
Version:
$Id: NonStrictFSMDirector.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Ye Zhou
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (zhouye)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  java.util.Set _nonpreemptiveTransitionsInputs
           
private  java.util.Set _outputActionReferredInputPorts
           
private  java.util.Set _preemptiveTransitionsInputs
           
private  java.util.Set _referredInputPorts
           
private  java.util.Set _refinementReferredInputPorts
           
private  java.util.Set _setActionReferredInputPorts
           
 
Fields inherited from class ptolemy.domains.modal.kernel.FSMDirector
_currentLocalReceiverMap, _disabledActors, _enabledRefinements, _indexOffset, _localReceiverMaps, _stateRefinementsToPostfire, _transitionRefinementsToPostfire, controllerName
 
Fields inherited from class ptolemy.actor.Director
_actorsFinishedExecution, _currentTime, _finishRequested, _initializables, _stopRequested, timeResolution
 
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
NonStrictFSMDirector(CompositeEntity container, java.lang.String name)
          Construct a director in the given container with the given name.
 
Method Summary
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 void fire()
          Fire the modal model.
 void getNonpreemptiveTransitionsReferredInputPorts(State state)
          Given a state, get a set of input ports referred in the guards of the preemptive transitions leaving that state.
 void getOutputActionsReferredInputPorts(Transition transition)
          Given a transition, get a set of input ports referred in the outputActions of that transition.
 void getPreemptiveTransitionsReferredInputPorts(State state)
          Given a state, get a set of input ports referred in the guards of the preemptive transitions leaving that state.
 void getReferredInputPorts(java.util.Set portSet, java.util.Set referredInputPorts)
          Given a set of ports, get those that are input ports of the container and put them in the indicated referred set.
 void getRefinementReferredInputPorts(State state)
          Given a state, get a set of input ports referred by the refinements of that state.
 void getSetActionsReferredInputPorts(Transition transition)
          Given a transition, get a set of input ports referred in the set actions of that transition.
 java.util.Set getTransitionReferredInputPorts(java.util.List transitionList)
          Given a list of transitions, get a set of referred input ports in the guard expressions of all the transitions leaving this state.
 void initialize()
          Initialize the director.
 boolean postfire()
          Call the postfire() method of the super class.
 boolean transferInputs(IOPort port)
          Override the super class by only transferring inputs for those input ports that are referred by the guard expressions of the preemptive transitions leaving the current state.
 
Methods inherited from class ptolemy.domains.modal.kernel.FSMDirector
_buildLocalReceiverMaps, _chooseTransition, _currentLocalReceivers, _enableActor, _getLastChosenTransition, _readInputs, _readOutputsFromRefinement, _setCurrentConnectionMap, _setCurrentState, _transferOutputs, attributeChanged, defaultDependency, fireAt, getContext, getController, getIndex, getModelNextIterationTime, getModifiedVariables, getParseTreeEvaluator, handleModelError, implementsStrictActorSemantics, invalidateSchedule, isStrict, newReceiver, prefire, setContainer, setIndex, setModelTime
 
Methods inherited from class ptolemy.actor.Director
_description, _fireContainerAt, _isEmbedded, _isTopLevel, _transferInputs, addInitializable, createSchedule, finish, fireAt, fireAtCurrentTime, getCausalityInterface, getCurrentTime, getErrorTolerance, getGlobalTime, getModelStartTime, getModelStopTime, getModelTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, initialize, invalidateResolvedTypes, isFireFunctional, isStopRequested, iterate, preinitialize, preinitialize, removeInitializable, requestInitialization, setCurrentTime, stop, stopFire, suggestedModalModelDirectors, supportMultirateFiring, terminate, transferOutputs, wrapup
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, 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
 

Field Detail

_nonpreemptiveTransitionsInputs

private java.util.Set _nonpreemptiveTransitionsInputs

_outputActionReferredInputPorts

private java.util.Set _outputActionReferredInputPorts

_preemptiveTransitionsInputs

private java.util.Set _preemptiveTransitionsInputs

_referredInputPorts

private java.util.Set _referredInputPorts

_refinementReferredInputPorts

private java.util.Set _refinementReferredInputPorts

_setActionReferredInputPorts

private java.util.Set _setActionReferredInputPorts
Constructor Detail

NonStrictFSMDirector

public NonStrictFSMDirector(CompositeEntity container,
                            java.lang.String name)
                     throws IllegalActionException,
                            NameDuplicationException
Construct a director in the given container with the given name. The container argument must not be null, or a NullPointerException will be thrown. If the name argument is null, then the name is set to the empty string. Increment the version number of the workspace.

Parameters:
container - Container of this director.
name - Name of this director.
Throws:
IllegalActionException - If the name has a period in it, or the director is not compatible with the specified container.
NameDuplicationException - If the container not a CompositeActor and the name collides with an entity in the container.
Method Detail

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 FSMDirector
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)

fire

public void fire()
          throws IllegalActionException
Fire the modal model. The preemptive transitions from the current state are examined. If there is more than one transition enabled, an exception is thrown. If there is exactly one preemptive transition enabled, then it is chosen. Get additional input ports referred by the output actions and set actions of the enabled transition and executed the output actions. The refinements of the current state will not be fired.

If no preemptive transition is enabled, get additional input ports referred by the refinements of the current state and transfer at most one token from these input ports. Fire the refinements. After this, get additional input ports referred by the nonpreemptive transitions from the current state and transfer at most one token from these input ports. Then examine the nonpreemptive transitions. If there is more than one transition enabled, an exception is thrown. If there is exactly one nonpreemptive transition enabled, then it is chosen. Get additional input ports referred by the output actions and set actions of the enabled transition and executed the output actions.

Specified by:
fire in interface Executable
Overrides:
fire in class FSMDirector
Throws:
IllegalActionException - If the super class throws it.

getNonpreemptiveTransitionsReferredInputPorts

public void getNonpreemptiveTransitionsReferredInputPorts(State state)
                                                   throws IllegalActionException
Given a state, get a set of input ports referred in the guards of the preemptive transitions leaving that state.

Parameters:
state - The given state.
Throws:
IllegalActionException - If there is no controller or if any guard expression is illegal.

getOutputActionsReferredInputPorts

public void getOutputActionsReferredInputPorts(Transition transition)
                                        throws IllegalActionException
Given a transition, get a set of input ports referred in the outputActions of that transition.

Parameters:
transition - The transition.
Throws:
IllegalActionException - If there is no controller or if the outputActions is illegal.

getPreemptiveTransitionsReferredInputPorts

public void getPreemptiveTransitionsReferredInputPorts(State state)
                                                throws IllegalActionException
Given a state, get a set of input ports referred in the guards of the preemptive transitions leaving that state.

Parameters:
state - The given state.
Throws:
IllegalActionException - If there is no controller or if any guard expression is illegal.

getReferredInputPorts

public void getReferredInputPorts(java.util.Set portSet,
                                  java.util.Set referredInputPorts)
Given a set of ports, get those that are input ports of the container and put them in the indicated referred set.

Parameters:
portSet - The given set of ports
referredInputPorts - The referred set.

getRefinementReferredInputPorts

public void getRefinementReferredInputPorts(State state)
                                     throws IllegalActionException
Given a state, get a set of input ports referred by the refinements of that state.

Parameters:
state - The given state.
Throws:
IllegalActionException - If refinement with given name is not found, or if the port rate does not contain a valid expression.

getSetActionsReferredInputPorts

public void getSetActionsReferredInputPorts(Transition transition)
                                     throws IllegalActionException
Given a transition, get a set of input ports referred in the set actions of that transition.

Parameters:
transition - The given transition.
Throws:
IllegalActionException - If there is no controller or if any set action expression is illegal.

getTransitionReferredInputPorts

public java.util.Set getTransitionReferredInputPorts(java.util.List transitionList)
                                              throws IllegalActionException
Given a list of transitions, get a set of referred input ports in the guard expressions of all the transitions leaving this state.

Parameters:
transitionList - The list of Transitions.
Returns:
A set of input ports referred by the guard expressions of the given transition list.
Throws:
IllegalActionException - If there is no controller or if the guard expression is illegal.

initialize

public void initialize()
                throws IllegalActionException
Initialize the director. Get the referred input ports in the guard expressions of all preemptive transitions leaving the initial state.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class FSMDirector
Throws:
IllegalActionException - If the super class throws it.

postfire

public boolean postfire()
                 throws IllegalActionException
Call the postfire() method of the super class. Get the referred input ports in the guard expressions of all preemptive transitions that go out from the current state.

Specified by:
postfire in interface Executable
Overrides:
postfire in class FSMDirector
Returns:
True if the mode controller wishes to be scheduled for another iteration.
Throws:
IllegalActionException - If the super class throws it.

transferInputs

public boolean transferInputs(IOPort port)
                       throws IllegalActionException
Override the super class by only transferring inputs for those input ports that are referred by the guard expressions of the preemptive transitions leaving the current state.

Overrides:
transferInputs in class FSMDirector
Parameters:
port - The input port to transfer tokens from.
Returns:
True if at least one data token is transferred.
Throws:
IllegalActionException - If the port is not an opaque input port.