Class 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)
    • 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.
    • 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 graph
        NameDuplicationException - If thrown while adding a node, making Bijective, removing feedback, setting the structure, inserting permutations or laying out the graph
      • 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.
      • 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 description
        suffix - 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.
      • _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.