Package ptolemy.cg.lib.syntactic
Class SyntacticGraph
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity
-
- ptolemy.kernel.CompositeEntity
-
- ptolemy.cg.lib.syntactic.SyntacticGraph
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class SyntacticGraph extends CompositeEntity
Represent ptolemy networks with Syntactic Graphs. Syntactic Graphs represent ptolemy networks in a manner that can be translated to a syntactical representation. In this representative graph, representative nodes can be organized as parallel compositions of nodes in series with feedback drawn around the entire graph.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Chris Shaver
- Pt.AcceptedRating:
- red
- Pt.ProposedRating:
- red (shaver)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
-
-
Field Summary
-
Fields inherited from class ptolemy.kernel.CompositeEntity
_levelCrossingLinks
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
-
Constructor Summary
Constructors Constructor Description SyntacticGraph()
Create new instance of SyntacticGraph with no container.SyntacticGraph(CompositeEntity container, java.lang.String name)
Construct an instance of SyntacticGraph in a given container.SyntacticGraph(Workspace workspace)
Create new instance of SyntacticGraph in a given workspace.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_addExteriorNode(SyntacticNode node)
Add node that represents an exterior port.protected void
_addRepresentativeNode(SyntacticNode node)
Add representative SyntacticNode to graph and associated maps.protected void
_clearMarked()
Clear all the visited flags in the nodes.protected void
_clearVisited()
Clear all the visited flags in the nodes.protected java.lang.Integer
_getInputChannel(Port oport, int ochan, Port iport)
Get the input channel connected to in a given port from a given output port and channel.protected java.util.LinkedList<SyntacticNode>
_getInputs()
Get list of input ports for model.protected java.lang.Integer
_getOutputChannel(Port oport, Port iport, int ichan)
Get the output channel connected to in a given port from a given input port and channel.protected java.util.LinkedList<SyntacticNode>
_getOutputs()
Get list of output ports for model.protected java.util.Collection<SyntacticNode>
_getRootSet()
Get the set of initial nodes as a Collection.protected void
_makeConnection(SyntacticPort out, SyntacticPort in)
Make connection between SyntacticPorts in Syntactic Nodes.protected void
_removeConnection(SyntacticPort port)
Remove connection from SyntacticPorts in Syntactic Nodes.java.lang.String
addLabelFromNode(SyntacticNode node)
Add a unique label to given node or return its current label.void
addNode(SyntacticNode node)
Add a SyntacticNode to the Graph.void
addNode(Entity entity)
Add entity to the syntactic graph wrapping with syntactic node.void
addNode2(Entity entity)
Add entity to the syntactic graph wrapping with syntactic node.boolean
build(CompositeEntity model)
Build the syntactic graph from the given model.java.lang.String
description(java.lang.String prefix, java.lang.String suffix)
Print description of Syntactic Graph.java.lang.String
generateCode()
Generate code for model represented by graph.java.lang.String
getLabelFromNode(SyntacticNode node)
Get the label associated with a give node.SyntacticNode
getNodeFromLabel(java.lang.String label)
Get the node associated with a given label or null.void
insertPermutations()
Insert permutation objects between columns.boolean
isBijective()
Determine whether the graph has been made completely bijective.boolean
isFeedbackRemoved()
Determine whether feedback has been removed.void
layoutGraph()
Layout graph for display in columns.void
makeBijective()
Make SyntacticGraph bijective by adding pure nodes.void
removeFeedback()
Remove feedback from graph and draw connections out to periphery.static java.lang.String
stringJoin(java.util.List<java.lang.String> stringList, java.lang.String infix)
Join a list of strings with a given infix.void
structure()
Structure the graph into columns.-
Methods inherited from class ptolemy.kernel.CompositeEntity
_addEntity, _addRelation, _adjustDeferrals, _containedDecorators, _deepOpaqueEntityList, _description, _exportMoMLContents, _finishedAddEntity, _removeEntity, _removeRelation, _validateSettables, allAtomicEntityList, allowLevelCrossingConnect, classDefinitionList, clone, connect, connect, containedObjectsIterator, deepCompositeEntityList, deepEntityList, deepGetEntities, deepNamedObjList, deepOpaqueEntityList, deepRelationSet, entityList, entityList, exportLinks, exportMoML, getAttribute, getEntities, getEntity, getPort, getRelation, getRelations, isAtomic, isOpaque, lazyAllAtomicEntityList, lazyAllCompositeEntityList, lazyAllCompositeTransparentAndOpaqueEntityList, lazyClassDefinitionList, lazyDeepEntityList, lazyEntityList, lazyRelationList, newRelation, numberOfEntities, numberOfRelations, numEntities, numRelations, relationList, removeAllEntities, removeAllRelations, setClassDefinition, setContainer, statistics, uniqueName
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, newPort, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _removePort, connectedPortList, connectedPorts, connectionsChanged, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getDisplayName, getFullName, getName, getName
-
-
-
-
Constructor Detail
-
SyntacticGraph
public SyntacticGraph()
Create new instance of SyntacticGraph with no container.
-
SyntacticGraph
public SyntacticGraph(Workspace workspace)
Create new instance of SyntacticGraph in a given workspace.- Parameters:
workspace
- Workspace in which to create the syntactic graph.
-
SyntacticGraph
public SyntacticGraph(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct an instance of SyntacticGraph in a given container.- Parameters:
container
- The container entity.name
- The name of the entity.- Throws:
IllegalActionException
- If the entity cannot be contained by the proposed container.NameDuplicationException
- If the name coincides with an entity already in the container.
-
-
Method Detail
-
build
public boolean build(CompositeEntity model) throws IllegalActionException, NameDuplicationException
Build the syntactic graph from the given model. Model is constructed by going through the total set of steps necessary to establish a representative graph:-- add entities to graph, -- make graph bijective, -- remove feedback loops, -- order graph topologically, -- insert permutation operators, -- add layout information to display generated graph.
- Parameters:
model
- Model to represent with graph.- Returns:
- whether graph was successively produced.
- Throws:
IllegalActionException
- If thrown while adding a node, making Bijective, removing feedback, setting the structure, inserting permutations or laying out the graphNameDuplicationException
- If thrown while adding a node, making Bijective, removing feedback, setting the structure, inserting permutations or laying out the graph
-
addNode2
public void addNode2(Entity entity) throws IllegalActionException, NameDuplicationException
Add entity to the syntactic graph wrapping with syntactic node. Beginning of an alternative. Not currently used.- Parameters:
entity
- Entity to add to the graph.- Throws:
IllegalActionException
- If thrown while creating a new SyntacticNode or adding an entity.NameDuplicationException
- If thrown while creating a new SyntacticNode or adding an entity.
-
addNode
public void addNode(Entity entity) throws IllegalActionException, NameDuplicationException
Add entity to the syntactic graph wrapping with syntactic node.- Parameters:
entity
- Entity to add to the graph.- Throws:
IllegalActionException
- If thrown while creating a new SyntacticNode or adding an entity.NameDuplicationException
- If thrown while creating a new SyntacticNode or adding an entity.
-
addNode
public void addNode(SyntacticNode node) throws IllegalActionException, NameDuplicationException
Add a SyntacticNode to the Graph. Nodes are either purely syntactic nodes or nodes that represent Entities.- Parameters:
node
- Node to add to the Graph.- Throws:
IllegalActionException
- on attempts to add nodes after certain transformations are done to the graph.NameDuplicationException
- if duplicate names are used.
-
makeBijective
public void makeBijective() throws IllegalActionException, NameDuplicationException
Make SyntacticGraph bijective by adding pure nodes. Pure nodes are added to mediate multiply connected nodes.- Throws:
IllegalActionException
- If thrown while creating a SyntacticNode, setting a Mediator, removing a connection or adding a connection.NameDuplicationException
- If thrown while creating a SyntacticNode, setting a Mediator, removing a connection or adding a connection.
-
removeFeedback
public void removeFeedback() throws IllegalActionException, NameDuplicationException
Remove feedback from graph and draw connections out to periphery. This can only be done when the graph is bijective, though this might still work with more constraints given a multiply connected graph.- Throws:
IllegalActionException
- If thrown while creating a new node or setting the feedback.NameDuplicationException
- If thrown while creating a new node or setting the feedback.
-
structure
public void structure() throws IllegalActionException, NameDuplicationException
Structure the graph into columns. This transformation imposes a partial order on the acyclic graph.- Throws:
IllegalActionException
- If thrown while setting the identity or removing or making the connection.NameDuplicationException
- If thrown while setting the identity or removing or making the connection.
-
insertPermutations
public void insertPermutations() throws IllegalActionException, NameDuplicationException
Insert permutation objects between columns.- Throws:
IllegalActionException
- If thrown while creating a node, setting the permutation, or removing or making connections.NameDuplicationException
- If thrown while creating a node.
-
layoutGraph
public void layoutGraph() throws IllegalActionException, NameDuplicationException
Layout graph for display in columns.- Throws:
IllegalActionException
- If thrown while setting the location.NameDuplicationException
- If thrown while setting the location.
-
generateCode
public java.lang.String generateCode()
Generate code for model represented by graph.- Returns:
- code generated from syntactic graph.
-
isFeedbackRemoved
public boolean isFeedbackRemoved()
Determine whether feedback has been removed. Feedback is transformed into named pairs of initial and terminal syntactic nodes.- Returns:
- Whether feedback has been removed.
-
isBijective
public boolean isBijective()
Determine whether the graph has been made completely bijective. Multiple relations are either removed in the nodes by repeating multivalent ports as series of single ports, or removed in the graph by representing splits and merges as purely syntactic nodes.- Returns:
- Whether graph has been made bijective.
-
description
public java.lang.String description(java.lang.String prefix, java.lang.String suffix)
Print description of Syntactic Graph.- Parameters:
prefix
- Line prefix for embedding descriptionsuffix
- Line suffix for embedding description- Returns:
- Description of Syntactic Graph.
-
getNodeFromLabel
public SyntacticNode getNodeFromLabel(java.lang.String label)
Get the node associated with a given label or null.- Parameters:
label
- The label given for a node.- Returns:
- The node associated with the given label or null.
-
getLabelFromNode
public java.lang.String getLabelFromNode(SyntacticNode node)
Get the label associated with a give node.- Parameters:
node
- The node give for a label.- Returns:
- The label associated with the given node or null.
-
addLabelFromNode
public java.lang.String addLabelFromNode(SyntacticNode node)
Add a unique label to given node or return its current label.- Parameters:
node
- The node to give a label to.- Returns:
- the label given to the node or already attached to it.
-
stringJoin
public static java.lang.String stringJoin(java.util.List<java.lang.String> stringList, java.lang.String infix)
Join a list of strings with a given infix.- Parameters:
stringList
- List of strings.infix
- Infix to join strings with.- Returns:
- String containing joined strings.
-
_addRepresentativeNode
protected void _addRepresentativeNode(SyntacticNode node)
Add representative SyntacticNode to graph and associated maps. If the node is not representative the node will not be added to the map between entities and nodes.- Parameters:
node
- The representative node to add.
-
_addExteriorNode
protected void _addExteriorNode(SyntacticNode node)
Add node that represents an exterior port. If the node is does not have an exterior port it will not be added to the map between ports and nodes.- Parameters:
node
- The representative node to add.
-
_makeConnection
protected void _makeConnection(SyntacticPort out, SyntacticPort in) throws IllegalActionException
Make connection between SyntacticPorts in Syntactic Nodes.- Parameters:
out
- The output port to connect.in
- The input port to connect.- Throws:
IllegalActionException
- If thrown while connecting.
-
_removeConnection
protected void _removeConnection(SyntacticPort port) throws IllegalActionException
Remove connection from SyntacticPorts in Syntactic Nodes.- Parameters:
port
- The port to disconnect.- Throws:
IllegalActionException
- If thrown while unlinking.
-
_getInputChannel
protected java.lang.Integer _getInputChannel(Port oport, int ochan, Port iport) throws IllegalActionException
Get the input channel connected to in a given port from a given output port and channel. If no connection is found null is returned.- Parameters:
oport
- The output port sending on ochan.ochan
- The output channel for port oport.iport
- The input port whose channel is to be determined.- Returns:
- input channel on iport or null.
- Throws:
IllegalActionException
- If thrown while getting the receivers.
-
_getOutputChannel
protected java.lang.Integer _getOutputChannel(Port oport, Port iport, int ichan) throws IllegalActionException
Get the output channel connected to in a given port from a given input port and channel. If no connection is found null is returned.- Parameters:
oport
- The output port sending on ochan.iport
- The input port whose channel is to be determined.ichan
- The input channel for port iport.- Returns:
- output channel on oport or null.
- Throws:
IllegalActionException
- If thrown while getting the remote receivers.
-
_getRootSet
protected java.util.Collection<SyntacticNode> _getRootSet()
Get the set of initial nodes as a Collection.- Returns:
- A Collection containing the initial nodes in the graph.
-
_clearVisited
protected void _clearVisited()
Clear all the visited flags in the nodes. This is used for visiting algorithms.
-
_clearMarked
protected void _clearMarked()
Clear all the visited flags in the nodes. This is used for visiting algorithms.
-
_getInputs
protected java.util.LinkedList<SyntacticNode> _getInputs()
Get list of input ports for model.- Returns:
- List of input ports.
-
_getOutputs
protected java.util.LinkedList<SyntacticNode> _getOutputs()
Get list of output ports for model.- Returns:
- List of output ports.
-
-