ptolemy.domains.continuous.kernel
Class HybridModalDirector

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.continuous.kernel.HybridModalDirector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Executable, Initializable, QuasiTransparentDirector, SuperdenseTimeDirector, ExplicitChangeContext, ContinuousStatefulComponent, ContinuousStepSizeController, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class HybridModalDirector
extends FSMDirector
implements ContinuousStatefulComponent, ContinuousStepSizeController

An HybridModalDirector governs the execution of the discrete dynamics of a hybrid system model. It extends ModalDirector by implementing the ContinuousStatefulComponent and ContinuousStepSizeController interfaces by delegating the function of those interfaces to the currently active state refinement.

Note that when a multi-step solver is used, the guards on the transitions are only evaluated when either the step size is zero or the multi-step solver has just completed its last step. The guards are not evaluated during intermediate steps.

This director is based on HSFSMDirector by Xiaojun Liu and Haiyang Zheng.

Since:
Ptolemy II 5.2
Version:
$Id: HybridModalDirector.java 57046 2010-01-27 23:35:53Z cxh $
Author:
Edward A. Lee, Haiyang Zheng
See Also:
Serialized Form
Accepted Rating:
Red (liuxj)
Proposed Rating:
Yellow (eal)

Nested Class Summary
private  class HybridModalDirector.ActorsFiredIterator
          Iterator over _stateRefinementsToPostfire followed by _transitionRefinementsToPostfire.
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  double _distanceToBoundary
          Local variable to indicate the distance to boundary.
private  ContinuousDirector _enclosingContinuousDirector
          The enclosing continuous director, if there is one.
private  long _enclosingContinuousDirectorVersion
          The version for __enclosingContinuousDirector.
private  double _lastDistanceToBoundary
          Local variable to indicate the last committed distance to boundary.
 
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
HybridModalDirector(CompositeEntity container, java.lang.String name)
          Construct a director in the given container with the given name.
 
Method Summary
private  Transition _checkEvent(java.util.List transitionList)
          Return the first transition in the specified list that has an "event", which is a change in the boolean value of its guard since the last evaluation.
protected  ContinuousDirector _enclosingContinuousDirector()
          Return the enclosing continuous director, or null if there is none.
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 void fire()
          Fire the model model for one iteration.
 double getErrorTolerance()
          Return error tolerance used for detecting enabled transitions.
 ParseTreeEvaluator getParseTreeEvaluator()
          Return the parse tree evaluator used to evaluate guard expressions.
 boolean isStepSizeAccurate()
          Return true if all actors that were fired in the current iteration report that the step size is accurate and if no transition is enabled.
 boolean postfire()
          Override the base class so that if there is no enabled transition then we record for each comparison operation in each guard expression the distance between the current value of the variable being compared and the threshold.
 boolean prefire()
          Override the base class to set current time to match that of the enclosing executive director, if there is one, regardless of whether that time is in the future or past.
 double refinedStepSize()
          Return the minimum of the step sizes suggested by any actors that were fired in the current iteration.
 void rollBackToCommittedState()
          Roll back to committed state.
 double suggestedStepSize()
          Return the minimum of the step sizes suggested by any actors that were fired in current iteration.
 
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, handleModelError, implementsStrictActorSemantics, initialize, invalidateSchedule, isStrict, newReceiver, setContainer, setIndex, setModelTime, transferInputs
 
Methods inherited from class ptolemy.actor.Director
_description, _fireContainerAt, _isEmbedded, _isTopLevel, _transferInputs, addInitializable, createSchedule, finish, fireAt, fireAtCurrentTime, getCausalityInterface, getCurrentTime, 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

_distanceToBoundary

private double _distanceToBoundary
Local variable to indicate the distance to boundary.


_enclosingContinuousDirector

private ContinuousDirector _enclosingContinuousDirector
The enclosing continuous director, if there is one.


_enclosingContinuousDirectorVersion

private long _enclosingContinuousDirectorVersion
The version for __enclosingContinuousDirector.


_lastDistanceToBoundary

private double _lastDistanceToBoundary
Local variable to indicate the last committed distance to boundary.

Constructor Detail

HybridModalDirector

public HybridModalDirector(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 is 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 model model for one iteration. Override the base class to avoid firing the controller during intermediate stages of a multi-step solver.

Specified by:
fire in interface Executable
Overrides:
fire in class FSMDirector
Throws:
IllegalActionException - If there is more than one transition enabled and nondeterminism is not permitted, or there is no controller, or it is thrown by any choice action.

getErrorTolerance

public final double getErrorTolerance()
Return error tolerance used for detecting enabled transitions. If there is an enclosing continuous director, then get the error tolerance from that director. Otherwise, return 1e-4.

Overrides:
getErrorTolerance in class Director
Returns:
The error tolerance used for detecting enabled transitions.

getParseTreeEvaluator

public ParseTreeEvaluator getParseTreeEvaluator()
Return the parse tree evaluator used to evaluate guard expressions. In this class, an instance of ParseTreeEvaluatorForGuardExpression is returned. The parse tree evaluator is set to construction mode.

Overrides:
getParseTreeEvaluator in class FSMDirector
Returns:
ParseTreeEvaluator used to evaluate guard expressions.

isStepSizeAccurate

public boolean isStepSizeAccurate()
Return true if all actors that were fired in the current iteration report that the step size is accurate and if no transition is enabled.

Specified by:
isStepSizeAccurate in interface ContinuousStepSizeController
Returns:
True if the current step is accurate.

postfire

public boolean postfire()
                 throws IllegalActionException
Override the base class so that if there is no enabled transition then we record for each comparison operation in each guard expression the distance between the current value of the variable being compared and the threshold.

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 thrown by any commit action or there is no controller.

prefire

public boolean prefire()
                throws IllegalActionException
Override the base class to set current time to match that of the enclosing executive director, if there is one, regardless of whether that time is in the future or past. The superclass sets current time only if the local time is less than the environment time. Initialize the firing of the director by resetting all receivers to unknown.

Specified by:
prefire in interface Executable
Overrides:
prefire in class FSMDirector
Returns:
Whatever the superclass returns.
Throws:
IllegalActionException - If thrown by the superclass.

refinedStepSize

public double refinedStepSize()
                       throws IllegalActionException
Return the minimum of the step sizes suggested by any actors that were fired in the current iteration.

Specified by:
refinedStepSize in interface ContinuousStepSizeController
Returns:
The suggested refined step size.
Throws:
IllegalActionException - If the step size cannot be further refined.

rollBackToCommittedState

public void rollBackToCommittedState()
Roll back to committed state. This will roll back any actors that were fired in the current iteration.

Specified by:
rollBackToCommittedState in interface ContinuousStatefulComponent

suggestedStepSize

public double suggestedStepSize()
                         throws IllegalActionException
Return the minimum of the step sizes suggested by any actors that were fired in current iteration.

Specified by:
suggestedStepSize in interface ContinuousStepSizeController
Returns:
The suggested next step size.
Throws:
IllegalActionException - If an actor requests an illegal step size.

_enclosingContinuousDirector

protected ContinuousDirector _enclosingContinuousDirector()
Return the enclosing continuous director, or null if there is none. The enclosing continuous director is a director above this in the hierarchy, possibly separated by composite actors with other foreign directors.

Returns:
The enclosing ContinuousDirector, or null if there is none.

_checkEvent

private Transition _checkEvent(java.util.List transitionList)
Return the first transition in the specified list that has an "event", which is a change in the boolean value of its guard since the last evaluation.

Returns:
A transition with a change in the value of the guard.