ptolemy.domains.ct.kernel
Class CTScheduler

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.actor.sched.Scheduler
              extended by ptolemy.domains.ct.kernel.CTScheduler
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class CTScheduler
extends Scheduler

The Static scheduler for the CT domain. A CT (sub)system can be mathematically represented as:

     dx/dt = f(x, u, t)
         y = g(x, u, t)
 
where x is the state of the system, u is the input, y is the output, f() is the state transition map and g() is the output map.

The system is built using actors. That is, all the functions, f() and g(), are built up by chains of actors. For higher order systems, x is a vector, built using more than one integrator. In general, actors that have the functionality of integration from their inputs to their outputs are called dynamic actors. Other actors are called arithmetic actors.

In order to interact with discrete domains, some actors in the CT domain are able to convert continuous waveforms to discrete events, and vice versa. An actor that has continuous input and discrete output is call an event generator; an actor that has discrete input and continuous output is called a waveform generator.

The interaction with some discrete domains requires that the CT simulation be able to remember its state and roll-back to the remembered state when needed. This in turn requires that all actors that have internal states to be able to remember and restore their states. These actors are called stateful actors.

In continuous-time simulation, time progresses in a discrete way. The distance between two consecutive time points is called the integration step size or step size, for short. Some actors may put constraints on the choice of the step size. These actors are called step size control actors. Examples of step size control actors include integrators, which control the accuracy and speed of numerical ODE solutions, and event generators, which produce discrete events.

To help with scheduling, the actors are partitioned into several clusters, including continuous actors, discrete actors, arithmetic actors, stateTransition actors, dynamic actors, sink actors, event generators, waveform generators, CT subsystems , and non-CT subsystems. This scheduler uses the cluster information and the system topology to provide the firing sequences for evaluating f() and g(). It also provides a firing order for all the dynamic actors. The firing sequence for evaluating f() is called the state transition schedule; the firing sequence for evaluating g() is called the output schedule; and the firing sequence for dynamic actors is called the dynamic actor schedule.

The state transition schedule is the actors in the f() function sorted in topological order, such that, after the integrators emit their state x, a chain of firings according to the schedule evaluates the f() function and returns tokens corresponding to dx/dt to the integrators.

The output schedule is the actors in the g() function sorted in their topological order.

The dynamic actor schedule is a list of dynamic actors in their reverse topological order.

If there are loops of arithmetic actors or loops of integrators, then the (sub)system are not schedulable, and a NotSchedulableException will be thrown if schedules are requested.

This CTScheduler does not support mutation.

Since:
Ptolemy II 0.2
Version:
$Id: CTScheduler.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Jie Liu, Haiyang Zheng, Ye Zhou
See Also:
Scheduler, Serialized Form
Accepted Rating:
Red (hyzheng)
Proposed Rating:
Yellow (hyzheng)

Nested Class Summary
private  class CTScheduler.SignalTypeMap
           
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  CTScheduler.SignalTypeMap _signalTypeMap
           
private static java.lang.String _STATIC_NAME
           
static CTReceiver.SignalType CONTINUOUS
          These are syntactic sugar for signal types, which are defined in CTReceiver.
static CTReceiver.SignalType DISCRETE
          Signal type: DISCRETE.
static CTReceiver.SignalType UNKNOWN
          Signal type: UNKNOWN.
 
Fields inherited from class ptolemy.actor.sched.Scheduler
_DEFAULT_SCHEDULER_NAME
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
CTScheduler()
          Construct a CT scheduler in the default workspace with an empty string as the name.
CTScheduler(Workspace workspace)
          Construct a CT scheduler in the given workspace with the name "CTScheduler".
 
Method Summary
protected  Schedule _getSchedule()
          Return the CTSchedule.
private static void _setOrCreate(NamedObj container, java.lang.String name, java.lang.String value)
          Set or create a not-visible, not-persistent parameter with the specified name in the specified container with the specified value.
private  void _setPortSignalTypes(CTScheduler.SignalTypeMap typeMap)
          Create and set a parameter in each port according to the resolved. continuous/discrete nature of the port.
private  DirectedAcyclicGraph _toArithmeticGraph(java.util.List list)
          Convert the given list of actors to a directed acyclic graph.
private  DirectedAcyclicGraph _toGraph(java.util.List list)
          Convert the given actors to a directed acyclic graph.
 boolean isContinuous(Actor actor)
          Return true if the given actor is in the continuous cluster of the model.
 boolean isDiscrete(Actor actor)
          Return true if the given actor is in the discrete cluster of the model.
 java.util.List predecessorList(Actor actor)
          Return the predecessors of the given actor in the same level of hierarchy.
 java.lang.String signalTypeToString(CTReceiver.SignalType signalType)
          Return the SignalType as a String.
 java.util.List successorList(Actor actor)
          Return the successive actors of the given actor in the same level of hierarchy.
 java.lang.String toString()
          Return the full name of this scheduler.
 
Methods inherited from class ptolemy.actor.sched.Scheduler
clone, getSchedule, isValid, setContainer, setValid
 
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, _description, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, 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, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONTINUOUS

public static final CTReceiver.SignalType CONTINUOUS
These are syntactic sugar for signal types, which are defined in CTReceiver. Signal type: CONTINUOUS.


DISCRETE

public static final CTReceiver.SignalType DISCRETE
Signal type: DISCRETE.


UNKNOWN

public static final CTReceiver.SignalType UNKNOWN
Signal type: UNKNOWN.


_STATIC_NAME

private static final java.lang.String _STATIC_NAME
See Also:
Constant Field Values

_signalTypeMap

private CTScheduler.SignalTypeMap _signalTypeMap
Constructor Detail

CTScheduler

public CTScheduler()
Construct a CT scheduler in the default workspace with an empty string as the name. There is no director containing this scheduler. To attach this scheduler to a CTDirector, call setScheduler() on the CTDirector.


CTScheduler

public CTScheduler(Workspace workspace)
Construct a CT scheduler in the given workspace with the name "CTScheduler". There is no director containing this scheduler. To attach this scheduler to a CTDirector, call setScheduler() on the CTDirector.

Parameters:
workspace - The workspace.
Method Detail

isContinuous

public boolean isContinuous(Actor actor)
                     throws IllegalActionException
Return true if the given actor is in the continuous cluster of the model.

Parameters:
actor - The given actor.
Returns:
True if the actor is a continuous actor.
Throws:
IllegalActionException - If this method is called before initialization, where the schedule is computed.

isDiscrete

public boolean isDiscrete(Actor actor)
                   throws IllegalActionException
Return true if the given actor is in the discrete cluster of the model.

Parameters:
actor - The given actor.
Returns:
True if the actor is a discrete actor.
Throws:
IllegalActionException - If this method is called before initialization, where the schedule is computed.

predecessorList

public java.util.List predecessorList(Actor actor)
Return the predecessors of the given actor in the same level of hierarchy. If the argument is null, return null. If the actor is a source, return an empty list.

Parameters:
actor - The given actor.
Returns:
The list of predecessors, unordered.

signalTypeToString

public java.lang.String signalTypeToString(CTReceiver.SignalType signalType)
Return the SignalType as a String.

Parameters:
signalType - The type of signal.
Returns:
A string of the signal type.

successorList

public java.util.List successorList(Actor actor)
Return the successive actors of the given actor in the same level of hierarchy. If the argument is null, return null. If the actor is a sink, return an empty list.

Parameters:
actor - The specified actor. If the actor is null, returns null.
Returns:
The enumerations of predecessors.

toString

public java.lang.String toString()
Return the full name of this scheduler.

Overrides:
toString in class NamedObj
Returns:
The full name of this scheduler.

_getSchedule

protected Schedule _getSchedule()
                         throws NotSchedulableException,
                                IllegalActionException
Return the CTSchedule. Caching of the schedule is done in the super class, so this method does not test for the validation of the schedule.

Overrides:
_getSchedule in class Scheduler
Returns:
A Schedule of the deeply contained opaque entities in the firing order.
Throws:
NotSchedulableException - If the CompositeActor is not schedulable. Not thrown in this base class, but may be thrown by derived classes.
IllegalActionException - If the scheduling algorithm throws it. Not thrown in this base class, but may be thrown by derived classes.
See Also:
CompositeEntity.deepEntityList()

_setOrCreate

private static void _setOrCreate(NamedObj container,
                                 java.lang.String name,
                                 java.lang.String value)
                          throws IllegalActionException
Set or create a not-visible, not-persistent parameter with the specified name in the specified container with the specified value.

Parameters:
container - The container for the parameter.
name - The name for the parameter.
value - The value for the parameter.
Throws:
IllegalActionException - If the parameter cannot contain the specified value.

_setPortSignalTypes

private void _setPortSignalTypes(CTScheduler.SignalTypeMap typeMap)
Create and set a parameter in each port according to the resolved. continuous/discrete nature of the port.

Parameters:
typeMap - A map from ports to

_toArithmeticGraph

private DirectedAcyclicGraph _toArithmeticGraph(java.util.List list)
Convert the given list of actors to a directed acyclic graph. CTDynamicActors are treated as sinks to break closed loops. Each actor in the argument is a node in the graph, each link between a pair of actors, except the output links from dynamic actors, is a edge between the corresponding nodes. The existence of the director and containers is not checked in this method, so the caller should check.

Parameters:
list - The list of actors to be scheduled.
Returns:
A graph representation of the actors.

_toGraph

private DirectedAcyclicGraph _toGraph(java.util.List list)
Convert the given actors to a directed acyclic graph. CTDynamicActors are NOT treated as sinks. This method is used to construct the dynamic actor schedule. Each actor in the argument is a node in the graph, and each link between a pair of actors is a edge between the corresponding nodes.

Parameters:
list - The list of actors to be converted to a graph.
Returns:
A graph representation of the actors.