ptolemy.actor
Class GraphReader

java.lang.Object
  extended by ptolemy.actor.GraphReader

public class GraphReader
extends java.lang.Object

This class provides methods for converting Ptolemy II models into generic graph representations. Portions of this code are based on examples from [1].

References
[1] J. Davis et al., Heterogeneous concurrent modeling and design in Java, Technical report, Electronics Research Laboratory, University of California at Berkeley, March 2001.

Since:
Ptolemy II 2.0
Version:
$Id: GraphReader.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Shuvra S. Bhattacharyya, Chia-Jui Hsu
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Field Summary
private  java.util.HashMap _actorMap
           
private static boolean _debug
           
 
Constructor Summary
GraphReader()
          Construct a new graph reader.
 
Method Summary
protected  java.lang.Object _computeEdgeWeight(IOPort sourcePort, IOPort sinkPort)
          Determine the weight to be assigned to the weighted graph edge that represents a given connection in a Ptolemy II model.
protected  java.lang.Object _computeNodeWeight(Actor actor)
          Determine the weight to be assigned to the weighted graph node that represents a given actor.
protected  Graph _initializeGraph(CompositeActor compositeActor)
          Instantiate and initialize a graph just prior to filling it in from a given Ptolemy II model.
protected  void _processNewEdge(Graph graph, Edge edge, IOPort sourcePort, IOPort sinkPort)
          Process a new edge corresponding to a given connection in a given graph.
protected  void _processNewNode(Graph graph, Node node, Actor actor)
          Process a new node corresponding to a given actor in a given graph.
protected  void _transformTopology(Graph graph)
          Perform post-processing on the entire graph to complete the conversion.
 Graph convert(CompositeActor compositeActor)
          Convert the model represented by a CompositeActor into a directed, weighted graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_debug

private static final boolean _debug
See Also:
Constant Field Values

_actorMap

private java.util.HashMap _actorMap
Constructor Detail

GraphReader

public GraphReader()
Construct a new graph reader.

Method Detail

convert

public Graph convert(CompositeActor compositeActor)
Convert the model represented by a CompositeActor into a directed, weighted graph. Each node of the weighted graph will have as its weight the Ptolemy II AtomicActor that the node represents, and each edge will have as its weight the input port associated with the connection that the edge represents. These conventions for assigning node and edge weights can be changed in specialized graph reader classes by overriding the _computeNodeWeight(Actor) and _computeEdgeWeight(IOPort sourcePort, IOPort sinkPort) methods. This method will convert low level CompositeActor as a node.

Parameters:
compositeActor - The composite actor to convert.
Returns:
the directed, weighted graph.
Throws:
java.lang.RuntimeException - If the deep entity list of the composite actor contains an entry that is not an AtomicActor.

_computeEdgeWeight

protected java.lang.Object _computeEdgeWeight(IOPort sourcePort,
                                              IOPort sinkPort)
Determine the weight to be assigned to the weighted graph edge that represents a given connection in a Ptolemy II model. This method returns the input port as the edge weight. This method should be overridden by derived classes that have different edge weighting conventions.

Parameters:
sourcePort - the output port of the connection associated with the edge.
sinkPort - the input port of the connection associated with the edge
Returns:
the weight of the edge.

_computeNodeWeight

protected java.lang.Object _computeNodeWeight(Actor actor)
Determine the weight to be assigned to the weighted graph node that represents a given actor. This method returns the actor itself as the weight. This method should be overridden by derived classes that have different node weighting conventions.

Parameters:
actor - the actor whose node weight is to be determined.
Returns:
the weight of the node.

_initializeGraph

protected Graph _initializeGraph(CompositeActor compositeActor)
Instantiate and initialize a graph just prior to filling it in from a given Ptolemy II model. This is a pre-processing step to the conversion process that can be specialized based on the type of graph that is being read (e.g., the method can be overridden to allocate a specialized Graph object). In this base class, we simply instantiate an empty Graph and return it.

Parameters:
compositeActor - the Ptolemy II model that will be converted.
Returns:
the empty graph that is to hold the converted model.

_processNewEdge

protected void _processNewEdge(Graph graph,
                               Edge edge,
                               IOPort sourcePort,
                               IOPort sinkPort)
Process a new edge corresponding to a given connection in a given graph. This method should be overridden to implement specialized conversion aspects that operate at the level of individual edges.

Parameters:
graph - The graph that contains the new edge.
edge - The new edge.
sourcePort - The source port of the connection in the model.
sinkPort - The sink port of the connection.

_processNewNode

protected void _processNewNode(Graph graph,
                               Node node,
                               Actor actor)
Process a new node corresponding to a given actor in a given graph. This method should be overridden to implement specialized conversion aspects that operate at the level of individual nodes.

Parameters:
graph - The graph that contains the new node.
node - The new node.
actor - The actor that corresponds to the new node.

_transformTopology

protected void _transformTopology(Graph graph)
Perform post-processing on the entire graph to complete the conversion. This method should be overridden by derived classes to implement specialized conversion aspects that operate at a global level (i.e., beyond the level of individual nodes and edges).

Parameters:
graph - the graph.