|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmapss.dif.ptolemy.DIFGraphExporter
public class DIFGraphExporter
This class provides methods for exporting Ptolemy models to DIF.
Ptolemy doesn't allow two actors with the same name, so we don't use hash code in naming.
DIFGraphExporter converts every AtomicActor (ptolemy.actor.AtomicActor) as a node in DIF and converts every CompositeActor (ptolemy.actor.CompositeActor) as a hierarchy in DIF.
For each relation with multiple destinations, DIFGraphExporter will create a special "fork" node for it. The fork node has computation attribute "dif.fork". If a relation with multiple sources, it is illegal for SDF and will cause an exception.
The DIFNodeWeight of node representing AtomicActor or CompositeActor is set to that AtomicActor or CompositeActor. The DIFNodeWeight of forkNode is set to the relation represented by that forkNode.
DIFGraphExporter records actor class information as "computation" attribute. All parameters of an actor are recorded as node attributes with type "parameter". For every IOPort of a ptolemy atomic actor with relation connected to it, DIFGraphExporter will record this IOPort as node attribute with type "input" or "output" and the attribute reference is set to the corresponding Edge or Port in DIF. If the IOPort is multiport, then multiple edges or ports connected to it are recorded as a LinkedList.
DIFGraphExporter do not allowed IOPort (ptolemy.actor.IOPort) of
CompositeActor to be multiport. If encounter this situation,
DIFGraphExporter throws an exception. For each IOPort (is not multiport)
of a CompositeActor, DIFGraphExporter will create the corresponding
Port Port
.
If setFullName(boolean)
to true, the name of each DIFHierarchy is set
to the full name of the corresponding CompositeActor.
For example: if the full name of a ptolemy
CompositeActor h3 is "h1.h2.h3", then the name of the DIFHierarchy
representing that CompositeActor is "h1_h2_h3". If all CompositeAcotrs in
all levels have different names, then its ok to setFullName(boolean)
to false. In this case, the name will be "h3". Note that when writing to dif
specification, DIFHierarchy.getName() is used as graph name instead of
DIFGraph.getName(). The default settings is false.
Usage:
DIFGraphExporter exporter = new DIFGraphExporter(CompositeActor object); DIFHierarcy hierarchy = exporter.convert(); String difSpecificaiton = exporter.toDIF(); exporter.write(fileName);
DIFGraphImporter
,
DIFGraph
,
Hierarchy
Constructor Summary | |
---|---|
DIFGraphExporter(ptolemy.actor.CompositeActor compositeActor)
Constructor. |
|
DIFGraphExporter(java.lang.String fileName)
Constructor. |
Method Summary | |
---|---|
protected java.lang.Object |
_computeEdgeWeight(ptolemy.actor.IOPort sourcePort,
ptolemy.actor.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(java.lang.Object actor)
Determine the weight to be assigned to the weighted graph node that represents a given actor. |
protected void |
_connectEdgeToPort(ptolemy.actor.IOPort ioPort,
mocgraph.Edge edge)
Connect the Port in dif subhierarchy corresponding to Ptolemy IOPort ioPortto an associated outside Edge edge. |
protected void |
_constructSingleInput(ptolemy.actor.IOPort inputPort,
DIFHierarchy hierarchy,
DIFGraph graph)
Construct an input Port in a DIF hierarchy. |
protected void |
_constructSingleOutput(ptolemy.actor.IOPort outputPort,
DIFHierarchy hierarchy,
DIFGraph graph)
Construct an output Port in DIF hierarchy. |
protected void |
_convertAtomicActor(ptolemy.actor.AtomicActor actor,
DIFHierarchy hierarchy,
DIFGraph graph)
Convert an actor (ptolemy.actor.AtomicActor) in Ptolemy II to a node (mocgraph.Node) in DIFGraph. |
protected void |
_convertCompositeActor(ptolemy.actor.CompositeActor actor,
DIFHierarchy hierarchy,
DIFGraph graph)
Convery an composite actor (ptolemy.actor.CompositeActor) in Ptolemy II as a super node (mocgraph.Node) in DIFGraph. |
protected void |
_createComposite(ptolemy.actor.CompositeActor compositeActor,
DIFHierarchy hierarchy,
DIFGraph graph)
This method will create a DIFHierarchy and DIFGraph to represent a CompositeActor. |
protected java.lang.String |
_formatName(java.lang.String name)
If the name conflicts with identifier convention Conventions.labelConvention(java.lang.String) , enclose the
name with '$'. |
protected java.lang.String |
_getName(java.lang.Object object,
boolean fullName)
Get object's name and add perfix if . |
protected void |
_initializeExporter()
Initialize DIFGraphReader |
protected mocgraph.Graph |
_initializeGraph(ptolemy.actor.CompositeActor compositeActor)
Initialize the exporter. |
protected void |
_putEdges(ptolemy.actor.CompositeActor compositeActor,
DIFGraph graph)
This method will put edges between nodes inside the graph and also connect an edge to a port if this edge is connected to a super node. |
protected void |
_putInterfaces(ptolemy.actor.CompositeActor compositeActor,
DIFHierarchy hierarchy,
DIFGraph graph)
This method will put input and output interfaces of compositeActor. |
protected ptolemy.actor.CompositeActor |
_readFile(java.lang.String fileName)
Convert a MoML (.xml) file that contains a Ptolemy II specification into a composite actor representation). |
protected void |
_relatePortToPort(ptolemy.actor.IOPort insidePort,
Port port)
Realte the outside DIF Port port to an inside DIF Port corresponding to a Ptolemy IOPort insidePort |
protected void |
_setGraphAttributes(ptolemy.actor.CompositeActor compositeActor,
DIFGraph graph)
Convert every Parameter in compositeActor to DIFAttribute in DIFGraph graph. |
protected void |
_setNodeAttributes(DIFGraph graph,
mocgraph.Node node,
ptolemy.kernel.util.NamedObj actor)
get Parameters of an actor, save parameters as Node Attributes in DIFGraph. |
protected void |
_setPortAttribute(mocgraph.Edge edge,
ptolemy.actor.IOPort ioPort,
DIFGraph graph)
Set node attributre for IOPort of a ptolemy atomic actor in DIF. |
protected void |
_setPortAttribute(Port port,
ptolemy.actor.IOPort ioPort,
DIFGraph graph)
Set node attributre for IOPort of a ptolemy atomic actor. |
DIFHierarchy |
convert()
Convert the CompositeActor object associated with this DIFGraphExporter into DIFHierarchy . |
void |
setFullName(boolean status)
If set to true, the hierarchy name is the full name of the ptolemy composite actor. |
java.lang.String |
toDIF()
Output the DIF specification of the converted DIFHierarchy. |
void |
write(java.lang.String fileName)
Creates a DIF file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DIFGraphExporter(ptolemy.actor.CompositeActor compositeActor)
compositeActor
- The ptolemy.actor.CompositeActor object
associated with this DIFGraphExporter.public DIFGraphExporter(java.lang.String fileName)
fileName
- The ptoelmy .xml file.Method Detail |
---|
public DIFHierarchy convert()
DIFHierarchy
.
public java.lang.String toDIF() throws DIFLanguageException
DIFLanguageException
public void setFullName(boolean status)
convert()
or write(String)
.
The default is false.
status
- public void write(java.lang.String fileName) throws java.io.IOException, DIFLanguageException
fileName
- A file name string. A ".dif" extension will
automatically be appended.
java.io.IOException
- If the file cannot be written.
DIFLanguageException
protected java.lang.Object _computeEdgeWeight(ptolemy.actor.IOPort sourcePort, ptolemy.actor.IOPort sinkPort)
sourcePort
- the output port of the connection associated with
the edge.sinkPort
- the input port of the connection associated with the
edge
protected java.lang.Object _computeNodeWeight(java.lang.Object actor)
actor
- the actor whose node weight is to be determined.
protected void _connectEdgeToPort(ptolemy.actor.IOPort ioPort, mocgraph.Edge edge)
ioPort
- edge
- protected void _constructSingleInput(ptolemy.actor.IOPort inputPort, DIFHierarchy hierarchy, DIFGraph graph)
inputPort
- An IOPort in ptolemy which is converted to Port in
DIF by this method.hierarchy
- A DIFHierarchy which contains the converted Port.graph
- The graph corresponding to the hierarchy.protected void _constructSingleOutput(ptolemy.actor.IOPort outputPort, DIFHierarchy hierarchy, DIFGraph graph)
outputPort
- An IOPort in ptolemy which is converted to Port in
DIF by this method.hierarchy
- A DIFHierarchy which contains the converted Port.graph
- The graph corresponding to the hierarchy.protected void _convertAtomicActor(ptolemy.actor.AtomicActor actor, DIFHierarchy hierarchy, DIFGraph graph)
actor
- the AtomicActor which will be put as a node in
DIFGraph.hierarchy
- The DIFHierarchy contains parameter graph. This
hierarchy is on the upper level of this actor.graph
- The DIFGraph in which actor should put.protected void _convertCompositeActor(ptolemy.actor.CompositeActor actor, DIFHierarchy hierarchy, DIFGraph graph)
actor
- The CompositeActor which will be put as a super node in
DIFGraph.hierarchy
- The DIFHierarchy contains graph. This
hierarchy is on the upper level of actor.graph
- The DIFGraph in which actor should put.protected void _createComposite(ptolemy.actor.CompositeActor compositeActor, DIFHierarchy hierarchy, DIFGraph graph)
compositeActor
- The CompositeActor need to be further refine
by DIFHierarchy and DIFGraph.hierarchy
- The DIFHierarchy to represent this CompositeActor.graph
- The DIFGraph to represent this CompositeActor.protected java.lang.String _formatName(java.lang.String name)
Conventions.labelConvention(java.lang.String)
, enclose the
name with '$'.
If the name conflicts with DIF keywords, enclose the
name with '$'.
name
- The name need to be formatted.
protected java.lang.String _getName(java.lang.Object object, boolean fullName)
object
- fullName
- Flag to indicate using full name or not.
protected mocgraph.Graph _initializeGraph(ptolemy.actor.CompositeActor compositeActor)
compositeActor
- the Ptolemy II model that will be converted.
protected void _initializeExporter()
protected void _putEdges(ptolemy.actor.CompositeActor compositeActor, DIFGraph graph)
compositeActor
- The CompositeActor represented by parameter
graph.graph
- The DIFGraph in which edges are put.protected void _putInterfaces(ptolemy.actor.CompositeActor compositeActor, DIFHierarchy hierarchy, DIFGraph graph)
compositeActor
- The CompositeActor.hierarchy
- The DIFHierarchy represents the compositeActor.graph
- The DIFGraph in of the DIFHierarchy.protected ptolemy.actor.CompositeActor _readFile(java.lang.String fileName)
fileName
- The name of the MoML file.
protected void _relatePortToPort(ptolemy.actor.IOPort insidePort, Port port)
insidePort
- port
- protected void _setGraphAttributes(ptolemy.actor.CompositeActor compositeActor, DIFGraph graph)
compositeActor
- graph
- The DIFGraph represents compositeActor.protected void _setNodeAttributes(DIFGraph graph, mocgraph.Node node, ptolemy.kernel.util.NamedObj actor)
graph
- node
- actor
- that is represented by node.protected void _setPortAttribute(Port port, ptolemy.actor.IOPort ioPort, DIFGraph graph)
port
- The outside connected port of a Port that represents
ioport.ioPort
- graph
- protected void _setPortAttribute(mocgraph.Edge edge, ptolemy.actor.IOPort ioPort, DIFGraph graph)
edge
- The outside connected edge of a Port that represents
ioport.ioPort
- graph
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |