ptolemy.domains.tdl.kernel
Class TDLActionsGraph

java.lang.Object
  extended by ptolemy.domains.tdl.kernel.TDLActionsGraph

public class TDLActionsGraph
extends java.lang.Object

A representation of the schedule of all actions in a TDL module in a graph. Nodes in this graph describe TDLActions (@see #TDLAction), edges describe the causal dependencies between those actions. The weight of nodes are the TDLAction objects, the weight of edges are the time that passes between two actions.

Since:
Ptolemy II 8.0
Version:
$Id: TDLActionsGraph.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Patricia Derler

Field Summary
private  FSMActor _controller
          Controller of the TDL module.
private  DirectedGraph _graph
          Graph containing all TDL actions.
private  java.util.HashMap<State,java.util.List> _modeSwitches
          store all mode switch entry and exit points for all modes in the form: mode1: modeSwitch1 : Object[](entry, exit) modeSwtich2 : Object[]entry, exit) mode2: ...
private  TDLModule _module
          The TDL module.
private  java.util.HashMap _tmpConnectedTaskPorts
          Store the connection between output ports of one task with input ports of another task.
private  java.util.HashMap<Time,Node> _tmpModeSwitchEnds
          Store end of mode switch subgraphs.
private  java.util.HashMap<Time,Node> _tmpModeSwitchStarts
          Store starts of mode switch subgraphs.
private  java.util.HashMap<Time,java.util.List> _tmpReadSensors
          Store the times sensors are read.
private  java.util.HashMap<IOPort,java.util.List<Time>> _tmpReadTaskInputPorts
          Store the times task input ports are read.
 
Constructor Summary
TDLActionsGraph(TDLModule module, FSMActor controller)
          Create a new TDLActionsGraph for a TDL module.
 
Method Summary
private  void _addConnectionsBetweenTaskPorts()
          Add the connections between task output ports and other tasks input ports.
private  LetTask _analyzeSlotSelection(TDLTask actor, Time modePeriodTime)
          Analyze the slot selection string.
private  void _connectModes()
          Connect partial graphs for modes.
private  void _connectToIntermediateModeSwitch(Node prev, Time actorInvocationTime, Time actorInvocationPeriod)
          Connect a node for a TDL action to the next mode switch in time.
private  void _connectToOtherTasksOutputPorts(IOPort taskInputPort)
          Connect an input port to the output port of another task that this input port reads from.
private  Node _createNode(Time invocationTime, int actionType, java.lang.Object actor)
          Create TDL action and a new node.
private  Node _createNode(Time invocationTime, int actionType, java.lang.Object actor, Node previous)
          Create a TDL action and a new node with an edge to the previous node
private  void _getActuators(Refinement refinement, Time modePeriod)
          Add actuator updates to the graph.
private  java.util.List<Node> _getForwardReachableIndependentNodes(Node node, java.util.List<Node> visited)
          Recursively compute the list of forward reachable nodes that only depend on one previous node and are scheduled for the same time as the current node.
private  java.util.ArrayList _getInvocations(java.lang.String slots, int frequency)
          Analyze the slot selection string.
private  Node _getLastNodeBeforeTime(IOPort port, Time upper)
          Return invocation of node for a port closest to a given time.
private  void _getTasks(State mode, Refinement refinement, Time modePeriod)
          Create subgraphs for all tasks, interconnect them with mode switches and other tasks.
private  void _getTransitions(State mode, Refinement refinement, Time modePeriod)
          First read transitions and build subgraphs for the transitions.
private  boolean _nextCharIsANumber(java.lang.String slotSelection, int i)
          Return true if the character at position i in the string slotSeleciton is a number.
private  void _registerModeSwitch(State state, Node transition, Node transitionNotTaken)
          Store mode switches.
private  void _registerSensorReading(Time invocationTime, IOPort sensor)
          Save that a sensor value was read at a certain point in time.
private  void _registerTaskInputPortReading(Time invocationTime, IOPort port)
          Save the times a task input port was written.
private  void _resetsTempVars()
          Reset temporary variables used to create the graph for one mode.
 void buildGraph(State startmode)
          Build the graph by iterating through all the modes of the TDL module.
 java.util.List<Node> getEventsFollowingAction(Node node)
          Returns all forward reachable nodes in the graph that are connected to the given node.
 java.util.HashMap<Node,java.util.List<TDLAction>> getNextJoinNodes(Node justExecuted, Node node, java.util.List<Node> visited)
          Recursively compute the set of nodes reachable from a given node that depend on more than one node or are scheduled to happen at a future time.
 Node getNode(java.lang.Object actor, Time lower, Time upper)
          Get a node which executes a given actor.
 Node getNode(TDLAction action)
          Get node for a given TDLAction.
 Node getNode(Time invocationTime, java.lang.Object actor)
          Return the node that is used for the execution of an actor at a certain time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_controller

private FSMActor _controller
Controller of the TDL module.


_graph

private DirectedGraph _graph
Graph containing all TDL actions.


_modeSwitches

private java.util.HashMap<State,java.util.List> _modeSwitches
store all mode switch entry and exit points for all modes in the form: mode1: modeSwitch1 : Object[](entry, exit) modeSwtich2 : Object[]entry, exit) mode2: ...


_module

private TDLModule _module
The TDL module.


_tmpConnectedTaskPorts

private java.util.HashMap _tmpConnectedTaskPorts
Store the connection between output ports of one task with input ports of another task.


_tmpModeSwitchEnds

private java.util.HashMap<Time,Node> _tmpModeSwitchEnds
Store end of mode switch subgraphs. A mode switch subgraph consists of sensors that are read and the mode switch.


_tmpModeSwitchStarts

private java.util.HashMap<Time,Node> _tmpModeSwitchStarts
Store starts of mode switch subgraphs. A mode switch subgraph consists of sensors that are read and the mode switch.


_tmpReadSensors

private java.util.HashMap<Time,java.util.List> _tmpReadSensors
Store the times sensors are read. This is used to only read a sensor once at a time. If a sensor is read before a mode switch, it should not be read again before executing tasks at the same time instant in order to preserve determinism.


_tmpReadTaskInputPorts

private java.util.HashMap<IOPort,java.util.List<Time>> _tmpReadTaskInputPorts
Store the times task input ports are read.

Constructor Detail

TDLActionsGraph

public TDLActionsGraph(TDLModule module,
                       FSMActor controller)
Create a new TDLActionsGraph for a TDL module.

Parameters:
module - The TDL module.
controller - The controller of the TDL module.
Method Detail

buildGraph

public void buildGraph(State startmode)
                throws IllegalActionException
Build the graph by iterating through all the modes of the TDL module. Create nodes for transitions, TDL tasks and actuators and connect them.

Parameters:
startmode - This is the initial mode of the TDL module.
Throws:
IllegalActionException - Thrown if TDL parameters in the module cannot be read.

getEventsFollowingAction

public java.util.List<Node> getEventsFollowingAction(Node node)
Returns all forward reachable nodes in the graph that are connected to the given node. Those forward reachable nodes do not depend on other nodes and the actions defined in the nodes are scheduled to happen at the same time as the action in the given node.

Parameters:
node - Given node.
Returns:
List of nodes that are forward reachable from the given node.

getNextJoinNodes

public java.util.HashMap<Node,java.util.List<TDLAction>> getNextJoinNodes(Node justExecuted,
                                                                          Node node,
                                                                          java.util.List<Node> visited)
Recursively compute the set of nodes reachable from a given node that depend on more than one node or are scheduled to happen at a future time. Examples for the latter are nodes describing the writing of an output port

Parameters:
justExecuted - Node that was just executed.
node - Node from which the reachable Nodes are computed.
visited - Already visited nodes, used to avoid loops.
Returns:
Set of reachable nodes taht depend on more than one input port or contain actions that should happen later than the given node.

getNode

public Node getNode(Time invocationTime,
                    java.lang.Object actor)
Return the node that is used for the execution of an actor at a certain time.

Parameters:
invocationTime - Time the actor is being invoked.
actor - Actor that is scheduled for that time.
Returns:
The node that is used for the execution of an actor at a certain time.

getNode

public Node getNode(TDLAction action)
Get node for a given TDLAction.

Parameters:
action - Given TDLAction.
Returns:
Node for the given TDLAction.

getNode

public Node getNode(java.lang.Object actor,
                    Time lower,
                    Time upper)
Get a node which executes a given actor. This output port is written in a certain time frame defined by the two parameters lower and upper.

Parameters:
actor - Actor that is executed.
lower - Lower time bound.
upper - Upper time bound.
Returns:
The node used to execute the actor.

_addConnectionsBetweenTaskPorts

private void _addConnectionsBetweenTaskPorts()
Add the connections between task output ports and other tasks input ports.


_analyzeSlotSelection

private LetTask _analyzeSlotSelection(TDLTask actor,
                                      Time modePeriodTime)
                               throws IllegalActionException
Analyze the slot selection string.

Parameters:
actor -
modePeriodTime -
Returns:
The LetTask
Throws:
IllegalActionException
TDLModeSchedulerException

_connectModes

private void _connectModes()
                    throws IllegalActionException
Connect partial graphs for modes. The connection points are the mode switch and after mode switch actions.

Throws:
IllegalActionException - If new Time cannot be created.

_connectToIntermediateModeSwitch

private void _connectToIntermediateModeSwitch(Node prev,
                                              Time actorInvocationTime,
                                              Time actorInvocationPeriod)
Connect a node for a TDL action to the next mode switch in time.

Parameters:
prev - Previous node to connect to.
actorInvocationTime - Invocation time of that actor.
actorInvocationPeriod - Invocation period of that actor.

_connectToOtherTasksOutputPorts

private void _connectToOtherTasksOutputPorts(IOPort taskInputPort)
Connect an input port to the output port of another task that this input port reads from.

Parameters:
taskInputPort -

_createNode

private Node _createNode(Time invocationTime,
                         int actionType,
                         java.lang.Object actor,
                         Node previous)
Create a TDL action and a new node with an edge to the previous node

Parameters:
invocationTime - Invocation time of the node.
actionType - Action type of the TDL action in the node.
actor - Actor of the TDL action.
previous - Previous node.
Returns:
New node.

_createNode

private Node _createNode(Time invocationTime,
                         int actionType,
                         java.lang.Object actor)
Create TDL action and a new node.

Parameters:
invocationTime - Invocation time of the node.
actionType - Action type of the TDL action in the node.
actor - Actor of the TDL action.
Returns:
New node.

_getActuators

private void _getActuators(Refinement refinement,
                           Time modePeriod)
Add actuator updates to the graph.

Parameters:
refinement - Refinement containing the actuator ports.
modePeriod - Period of the mode defined by the refinement.

_getForwardReachableIndependentNodes

private java.util.List<Node> _getForwardReachableIndependentNodes(Node node,
                                                                  java.util.List<Node> visited)
Recursively compute the list of forward reachable nodes that only depend on one previous node and are scheduled for the same time as the current node.

Parameters:
node - Node from which the reachable nodes are computed from.
visited - Already visited nodes to avoid loops.
Returns:
List of forward reachable nodes.

_getInvocations

private java.util.ArrayList _getInvocations(java.lang.String slots,
                                            int frequency)
                                     throws IllegalActionException
Analyze the slot selection string.

Parameters:
slots -
frequency -
Returns:
The list of invocations.
Throws:
IllegalActionException

_getLastNodeBeforeTime

private Node _getLastNodeBeforeTime(IOPort port,
                                    Time upper)
Return invocation of node for a port closest to a given time.

Parameters:
port -
upper -
Returns:
The node

_getTasks

private void _getTasks(State mode,
                       Refinement refinement,
                       Time modePeriod)
                throws IllegalActionException
Create subgraphs for all tasks, interconnect them with mode switches and other tasks.

Parameters:
refinement -
modePeriod -
Throws:
TDLModeSchedulerException
IllegalActionException

_getTransitions

private void _getTransitions(State mode,
                             Refinement refinement,
                             Time modePeriod)
First read transitions and build subgraphs for the transitions.

Parameters:
mode -
refinement -
modePeriod -
Throws:
IllegalActionException
TDLModeSchedulerException

_nextCharIsANumber

private boolean _nextCharIsANumber(java.lang.String slotSelection,
                                   int i)
Return true if the character at position i in the string slotSeleciton is a number.

Parameters:
slotSelection -
i -
Returns:
True if the character at position i in the string is a number.

_registerModeSwitch

private void _registerModeSwitch(State state,
                                 Node transition,
                                 Node transitionNotTaken)
Store mode switches.

Parameters:
state -
transition -
transitionNotTaken -

_registerSensorReading

private void _registerSensorReading(Time invocationTime,
                                    IOPort sensor)
Save that a sensor value was read at a certain point in time. invocationTime: sensor1, sensor2, ...

Parameters:
invocationTime - Time the sensor is read.
sensor - Sensor that is read.

_registerTaskInputPortReading

private void _registerTaskInputPortReading(Time invocationTime,
                                           IOPort port)
Save the times a task input port was written.

Parameters:
invocationTime - Time the port is read.
port - Port that is read.

_resetsTempVars

private void _resetsTempVars()
Reset temporary variables used to create the graph for one mode.