ptolemy.domains.giotto.kernel
Class GiottoDirector

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.actor.Director
              extended by ptolemy.actor.sched.StaticSchedulingDirector
                  extended by ptolemy.domains.giotto.kernel.GiottoDirector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Executable, Initializable, TimedDirector, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class GiottoDirector
extends StaticSchedulingDirector
implements TimedDirector

This class implements a director for the Giotto model of computation without Giotto modes. Schedules are generated according to the Giotto semantics. The GiottoScheduler class contains methods to compute the schedules. The GiottoReceiver class implements the data flow between actors using double-buffering.

If the parameter synchronizeToRealTime is set to true, then the director will not process events until the real time elapsed since the model started matches the time stamp of the event. This ensures that the director does not get ahead of real time, but, of course, it does not ensure that the director keeps up with real time.

Since:
Ptolemy II 1.0
Version:
$Id: GiottoDirector.java 59203 2010-09-23 21:41:27Z cxh $
Author:
Christoph Meyer Kirsch, Edward A. Lee and Haiyang Zheng
See Also:
GiottoScheduler, GiottoReceiver, Serialized Form
Accepted Rating:
Red (eal)
Proposed Rating:
Yellow (cm)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
protected static double _DEFAULT_GIOTTO_PERIOD
          The static default Giotto period is 100ms.
private  Time _expectedNextIterationTime
           
private  int _iterationCount
           
private  double _periodValue
           
private  boolean _readyToFire
           
private  long _realStartTime
           
private  java.util.LinkedList _receivers
           
private  Schedule _schedule
           
private  boolean _synchronizeToRealTime
           
private  int _unitIndex
           
private  double _unitTimeIncrement
           
 Parameter iterations
          The number of times that postfire may be called before it returns false.
 Parameter period
          The period of an iteration.
 Parameter synchronizeToRealTime
          Specify whether the execution should synchronize to the real time.
 
Fields inherited from class ptolemy.actor.sched.StaticSchedulingDirector
_postfireReturns
 
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
GiottoDirector()
          Construct a director in the default workspace with an empty string as its name.
GiottoDirector(CompositeEntity container, java.lang.String name)
          Construct a director in the given container with the given name.
GiottoDirector(Workspace workspace)
          Construct a director in the given workspace with an empty name.
 
Method Summary
private  int _getActorFrequency(NamedObj actor)
          Return the frequency of the specified actor by accessing a parameter named "frequency".
private  void _init()
           
private  void _requestFiring()
           
 void attributeChanged(Attribute attribute)
          If the specified attribute is filename, then close the current file (if there is one) and open the new one.
 Dependency delayDependency(double delay)
          Return a boolean dependency representing a model-time delay of the specified amount.
 void fire()
          Fire a complete iteration and advance time to the current time plus the period value.
 Time fireAt(Actor actor, Time time)
          Request a firing of the given actor at the given absolute time.
 int getIntPeriod()
          Get the period of the giotto director in ms.
 Time getModelNextIterationTime()
          Return the next time that this director expects activity.
 double getPeriod()
          Get the period of the giotto director in ms.
 void initialize()
          Initialize the actors associated with this director.
 Receiver newReceiver()
          Return a new receiver consistent with the Giotto domain.
 boolean postfire()
          Return false if the system has finished executing, either by reaching the iteration limit, or by having an actor in the model return false in postfire.
 boolean prefire()
          This method always return true.
 void preinitialize()
          Preinitialize the actors associated with this director.
 java.lang.String[] suggestedModalModelDirectors()
          Return an array of suggested directors to be used with ModalModel.
 boolean transferInputs(IOPort port)
          Transfer data from an input port of the container to the ports it is connected to on the inside.
 boolean transferOutputs(IOPort port)
          Transfer data from this port to the ports it is connected to on the outside.
 
Methods inherited from class ptolemy.actor.sched.StaticSchedulingDirector
_setScheduler, addDebugListener, clone, getScheduler, invalidateSchedule, isScheduleValid, removeDebugListener, setScheduler
 
Methods inherited from class ptolemy.actor.Director
_description, _fireContainerAt, _isEmbedded, _isTopLevel, _transferInputs, _transferOutputs, addInitializable, createSchedule, defaultDependency, finish, fireAt, fireAtCurrentTime, getCausalityInterface, getCurrentTime, getErrorTolerance, getGlobalTime, getModelStartTime, getModelStopTime, getModelTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, implementsStrictActorSemantics, initialize, invalidateResolvedTypes, isFireFunctional, isStopRequested, isStrict, iterate, preinitialize, removeInitializable, requestInitialization, setContainer, setCurrentTime, setModelTime, stop, stopFire, supportMultirateFiring, terminate, 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, 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, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, 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.actor.TimedDirector
getModelTime, getTimeResolution
 

Field Detail

iterations

public Parameter iterations
The number of times that postfire may be called before it returns false. If the value is less than or equal to zero, then the execution will never return false in postfire, and thus the execution can continue forever. The default value is an IntToken with the value zero.


period

public Parameter period
The period of an iteration. This is a double that defaults to 0.1.


synchronizeToRealTime

public Parameter synchronizeToRealTime
Specify whether the execution should synchronize to the real time. This parameter must contain a BooleanToken. If this parameter is true, then do not process events until the elapsed real time matches the time stamp of the events. The value defaults to false.


_DEFAULT_GIOTTO_PERIOD

protected static final double _DEFAULT_GIOTTO_PERIOD
The static default Giotto period is 100ms.

See Also:
Constant Field Values

_expectedNextIterationTime

private Time _expectedNextIterationTime

_iterationCount

private int _iterationCount

_periodValue

private double _periodValue

_readyToFire

private boolean _readyToFire

_realStartTime

private long _realStartTime

_receivers

private java.util.LinkedList _receivers

_schedule

private Schedule _schedule

_synchronizeToRealTime

private boolean _synchronizeToRealTime

_unitIndex

private int _unitIndex

_unitTimeIncrement

private double _unitTimeIncrement
Constructor Detail

GiottoDirector

public GiottoDirector()
Construct a director in the default workspace with an empty string as its name. The director is added to the list of objects in the workspace. Increment the version number of the workspace.


GiottoDirector

public GiottoDirector(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 the director.
name - Name of this director.
Throws:
IllegalActionException - If the director is not compatible with the specified container.
NameDuplicationException - If the name collides with an attribute in the container.

GiottoDirector

public GiottoDirector(Workspace workspace)
Construct a director in the given workspace with an empty name. The director is added to the list of objects in the workspace. Increment the version number of the workspace.

Parameters:
workspace - The workspace for this object.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
If the specified attribute is filename, then close the current file (if there is one) and open the new one. If the specified attribute is period or synchronizeToRealTime, then cache the new values. If the specified attribute is timeResolution, then cache the new value.

Overrides:
attributeChanged in class Director
Parameters:
attribute - The attribute that has changed.
Throws:
IllegalActionException - If the specified attribute is filename and the file cannot be opened.

delayDependency

public Dependency delayDependency(double delay)
Return a boolean dependency representing a model-time delay of the specified amount.

Specified by:
delayDependency in interface TimedDirector
Parameters:
delay - A non-negative delay.
Returns:
A boolean dependency representing a delay.

fire

public void fire()
          throws IllegalActionException
Fire a complete iteration and advance time to the current time plus the period value. A complete iteration consists of several minor cycles. At each minor cycle, iterate actors in the corresponding minor cycle schedule. After iterating the actors, increment time by the minor cycle time. Also, update the receivers that are destinations of all actors that will be invoked in the next minor cycle of the schedule. This works because all actors in Giotto are invoked periodically, and the ones that will be invoked in the next cycle are the ones that are completing invocation at the end of this cycle.

Specified by:
fire in interface Executable
Overrides:
fire in class StaticSchedulingDirector
Throws:
IllegalActionException - If this director does not have a container.

fireAt

public Time fireAt(Actor actor,
                   Time time)
            throws IllegalActionException
Request a firing of the given actor at the given absolute time. This method calculates the period of invocation of the specified actor (which is the period of this director divided by the actor's frequency), and if the requested time is ahead of current time by some multiple of the actor's period, then return the requested time.

Overrides:
fireAt in class Director
Parameters:
actor - The actor scheduled to be fired.
time - The requested time.
Returns:
The time at which the actor passed as an argument will be fired.
Throws:
IllegalActionException - If the operation is not permissible (e.g. the given time is in the past).
See Also:
Director.fireAtCurrentTime(Actor)

getIntPeriod

public int getIntPeriod()
Get the period of the giotto director in ms.

Returns:
int value of period in ms.

getModelNextIterationTime

public Time getModelNextIterationTime()
Return the next time that this director expects activity.

Overrides:
getModelNextIterationTime in class Director
Returns:
The time of the next iteration.
See Also:
Director.getModelTime()

getPeriod

public double getPeriod()
Get the period of the giotto director in ms.

Returns:
double value of period in ms.

initialize

public void initialize()
                throws IllegalActionException
Initialize the actors associated with this director. The order in which the actors are initialized is arbitrary.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class Director
Throws:
IllegalActionException - If the initialize() method of one of the associated actors throws it.

newReceiver

public Receiver newReceiver()
Return a new receiver consistent with the Giotto domain.

Overrides:
newReceiver in class Director
Returns:
A new GiottoReceiver.

postfire

public boolean postfire()
                 throws IllegalActionException
Return false if the system has finished executing, either by reaching the iteration limit, or by having an actor in the model return false in postfire.

Specified by:
postfire in interface Executable
Overrides:
postfire in class StaticSchedulingDirector
Returns:
True if the execution is not finished.
Throws:
IllegalActionException - If the iterations parameter does not have a valid token.

prefire

public boolean prefire()
                throws IllegalActionException
This method always return true. If this director is at the top level, returning true means always ready to fire. If embedded, return true usually means that the current time of the outside domain is greater than or equal to the current time. However, when a giotto model is used inside a CT model, its inputs may either be DISCRETE or CONTINUOUS. When the inputs are of type CONTINUOUS, this method should always return true. To accommodate this requirement, the prefire method still returns true but an internal flag will be set to false and the fire and postfire methods are forced to do nothing.

Specified by:
prefire in interface Executable
Overrides:
prefire in class StaticSchedulingDirector
Returns:
True if the director is ready to run for one iteration.
Throws:
IllegalActionException - If time is set backwards.

preinitialize

public void preinitialize()
                   throws IllegalActionException
Preinitialize the actors associated with this director. Generate the giotto schedule.

Specified by:
preinitialize in interface Initializable
Overrides:
preinitialize in class Director
Throws:
IllegalActionException - If the preinitialize() method of one of the associated actors throws it.

suggestedModalModelDirectors

public java.lang.String[] suggestedModalModelDirectors()
Return an array of suggested directors to be used with ModalModel. Each director is specified by its full class name. The first director in the array will be the default director used by a modal model.

Overrides:
suggestedModalModelDirectors in class Director
Returns:
An array of suggested directors to be used with ModalModel.
See Also:
Director.suggestedModalModelDirectors()

transferInputs

public boolean transferInputs(IOPort port)
                       throws IllegalActionException
Transfer data from an input port of the container to the ports it is connected to on the inside. The port argument must be an opaque input port. If any channel of the input port has no data, then that channel is ignored. This method will transfer exactly one token on each input channel that has at least one token available. Update all receivers to which a token is transferred.

Overrides:
transferInputs in class Director
Parameters:
port - The 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.

transferOutputs

public boolean transferOutputs(IOPort port)
                        throws IllegalActionException
Transfer data from this port to the ports it is connected to on the outside. This port must be an opaque output port. If any channel of this port has no data, then that channel is ignored. This method will transfer exactly one token on each output channel that has at least one token available.

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

_getActorFrequency

private int _getActorFrequency(NamedObj actor)
                        throws IllegalActionException
Return the frequency of the specified actor by accessing a parameter named "frequency". If there is no such parameter, return 1.

Throws:
IllegalActionException

_init

private void _init()

_requestFiring

private void _requestFiring()
                     throws IllegalActionException
Throws:
IllegalActionException