Interface DAGInterface<V extends Vertex,​E extends Edge<V>>

  • Type Parameters:
    V - the vertex type
    E - the edge type
    All Superinterfaces:
    java.io.Serializable
    All Known Implementing Classes:
    DAG, IRDAG

    public interface DAGInterface<V extends Vertex,​E extends Edge<V>>
    extends java.io.Serializable
    Methods for querying a directed-acyclic graph (DAG). Implementations of the methods must not modify the topology of the DAG.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  DAGInterface.TraversalOrder
      Indicates the traversal order of this DAG.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      com.fasterxml.jackson.databind.node.ObjectNode asJsonNode()  
      void dfsDo​(V vertex, java.util.function.Consumer<V> vertexConsumer, DAGInterface.TraversalOrder traversalOrder, java.util.Set<V> visited)
      A recursive helper function for dfsTraverse(Consumer, TraversalOrder).
      void dfsTraverse​(java.util.function.Consumer<V> function, DAGInterface.TraversalOrder traversalOrder)
      Traverses the DAG by DFS, applying the given function.
      java.util.List<V> filterVertices​(java.util.function.Predicate<V> condition)
      Filters the vertices according to the given condition.
      java.util.List<V> getAncestors​(java.lang.String vertexId)
      Retrieves the ancestors of a vertex.
      LoopVertex getAssignedLoopVertexOf​(V v)
      Retrieves the wrapping LoopVertex of the vertex.
      java.util.List<V> getChildren​(java.lang.String vertexId)
      Retrieves the children vertices of the given vertex.
      java.util.List<V> getDescendants​(java.lang.String vertexId)
      Retrieves the descendants of a vertex.
      E getEdgeBetween​(java.lang.String srcVertexId, java.lang.String dstVertexId)
      Retrieves the edge between two vertices.
      E getEdgeById​(java.lang.String id)
      Retrieves the edge given its ID.
      java.util.List<E> getEdges()
      Retrieves the edges of this DAG.
      java.util.List<E> getIncomingEdgesOf​(java.lang.String vertexId)
      Retrieves the incoming edges of the given vertex.
      java.util.List<E> getIncomingEdgesOf​(V v)
      Retrieves the incoming edges of the given vertex.
      java.lang.Integer getLoopStackDepthOf​(V v)
      Retrieves the stack depth of the given vertex.
      java.util.List<E> getOutgoingEdgesOf​(java.lang.String vertexId)
      Retrieves the outgoing edges of the given vertex.
      java.util.List<E> getOutgoingEdgesOf​(V v)
      Retrieves the outgoing edges of the given vertex.
      java.util.List<V> getParents​(java.lang.String vertexId)
      Retrieves the parent vertices of the given vertex.
      java.util.List<V> getRootVertices()
      Retrieves the root vertices of this DAG.
      java.util.List<V> getTopologicalSort()
      Gets the DAG's vertices in topologically sorted order.
      V getVertexById​(java.lang.String id)
      Retrieves the vertex given its ID.
      java.util.List<V> getVertices()
      Retrieves the vertices of this DAG.
      java.lang.Boolean isCompositeVertex​(V v)
      Checks whether the given vertex is assigned with a wrapping LoopVertex.
      java.lang.Boolean pathExistsBetween​(V v1, V v2)
      Function checks whether there is a path between two vertices.
      void storeJSON​(java.lang.String directory, java.lang.String name, java.lang.String description)
      Stores JSON representation of this DAG into a file.
      void topologicalDo​(java.util.function.Consumer<V> function)
      Applies the function to each node in the DAG in a topological order.
    • Method Detail

      • getVertexById

        V getVertexById​(java.lang.String id)
        Retrieves the vertex given its ID.
        Parameters:
        id - of the vertex to retrieve.
        Returns:
        the vertex.
      • getEdgeById

        E getEdgeById​(java.lang.String id)
        Retrieves the edge given its ID.
        Parameters:
        id - of the edge to retrieve.
        Returns:
        the edge.
      • getVertices

        java.util.List<V> getVertices()
        Retrieves the vertices of this DAG.
        Returns:
        the list of vertices. Note that the result is never null, ensured by DAGBuilder.
      • getEdges

        java.util.List<E> getEdges()
        Retrieves the edges of this DAG.
        Returns:
        the list of edges.
      • getRootVertices

        java.util.List<V> getRootVertices()
        Retrieves the root vertices of this DAG.
        Returns:
        the list of root vertices.
      • getIncomingEdgesOf

        java.util.List<E> getIncomingEdgesOf​(V v)
        Retrieves the incoming edges of the given vertex.
        Parameters:
        v - the subject vertex.
        Returns:
        the list of incoming edges to the vertex. Note that the result is never null, ensured by DAGBuilder.
      • getIncomingEdgesOf

        java.util.List<E> getIncomingEdgesOf​(java.lang.String vertexId)
        Retrieves the incoming edges of the given vertex.
        Parameters:
        vertexId - the ID of the subject vertex.
        Returns:
        the list of incoming edges to the vertex. Note that the result is never null, ensured by DAGBuilder.
      • getOutgoingEdgesOf

        java.util.List<E> getOutgoingEdgesOf​(V v)
        Retrieves the outgoing edges of the given vertex.
        Parameters:
        v - the subject vertex.
        Returns:
        the list of outgoing edges to the vertex. Note that the result is never null, ensured by DAGBuilder.
      • getOutgoingEdgesOf

        java.util.List<E> getOutgoingEdgesOf​(java.lang.String vertexId)
        Retrieves the outgoing edges of the given vertex.
        Parameters:
        vertexId - the ID of the subject vertex.
        Returns:
        the list of outgoing edges to the vertex. Note that the result is never null, ensured by DAGBuilder.
      • getParents

        java.util.List<V> getParents​(java.lang.String vertexId)
        Retrieves the parent vertices of the given vertex.
        Parameters:
        vertexId - the ID of the subject vertex.
        Returns:
        the list of parent vertices.
      • getChildren

        java.util.List<V> getChildren​(java.lang.String vertexId)
        Retrieves the children vertices of the given vertex.
        Parameters:
        vertexId - the ID of the subject vertex.
        Returns:
        the list of children vertices.
      • getEdgeBetween

        E getEdgeBetween​(java.lang.String srcVertexId,
                         java.lang.String dstVertexId)
        Retrieves the edge between two vertices.
        Parameters:
        srcVertexId - the ID of the source vertex.
        dstVertexId - the ID of the destination vertex.
        Returns:
        the edge if exists.
      • getTopologicalSort

        java.util.List<V> getTopologicalSort()
        Gets the DAG's vertices in topologically sorted order. This function brings consistent results.
        Returns:
        the sorted list of vertices in topological order.
      • getAncestors

        java.util.List<V> getAncestors​(java.lang.String vertexId)
        Retrieves the ancestors of a vertex.
        Parameters:
        vertexId - to find the ancestors for.
        Returns:
        the list of ancestors.
      • getDescendants

        java.util.List<V> getDescendants​(java.lang.String vertexId)
        Retrieves the descendants of a vertex.
        Parameters:
        vertexId - to find the descendants for.
        Returns:
        the list of descendants.
      • filterVertices

        java.util.List<V> filterVertices​(java.util.function.Predicate<V> condition)
        Filters the vertices according to the given condition.
        Parameters:
        condition - that must be satisfied to be included in the filtered list.
        Returns:
        the list of vertices that meet the condition.
      • topologicalDo

        void topologicalDo​(java.util.function.Consumer<V> function)
        Applies the function to each node in the DAG in a topological order. This function brings consistent results.
        Parameters:
        function - to apply.
      • dfsTraverse

        void dfsTraverse​(java.util.function.Consumer<V> function,
                         DAGInterface.TraversalOrder traversalOrder)
        Traverses the DAG by DFS, applying the given function.
        Parameters:
        function - to apply.
        traversalOrder - which the DFS should be conducted.
      • dfsDo

        void dfsDo​(V vertex,
                   java.util.function.Consumer<V> vertexConsumer,
                   DAGInterface.TraversalOrder traversalOrder,
                   java.util.Set<V> visited)
        A recursive helper function for dfsTraverse(Consumer, TraversalOrder).
        Parameters:
        vertex - the root vertex of the remaining DAG.
        vertexConsumer - the function to apply.
        traversalOrder - which the DFS should be conducted.
        visited - the set of nodes visited.
      • pathExistsBetween

        java.lang.Boolean pathExistsBetween​(V v1,
                                            V v2)
        Function checks whether there is a path between two vertices.
        Parameters:
        v1 - First vertex to check.
        v2 - Second vertex to check.
        Returns:
        Whether or not there is a path between two vertices.
      • isCompositeVertex

        java.lang.Boolean isCompositeVertex​(V v)
        Checks whether the given vertex is assigned with a wrapping LoopVertex.
        Parameters:
        v - Vertex to check.
        Returns:
        whether or not it is wrapped by a LoopVertex
      • getLoopStackDepthOf

        java.lang.Integer getLoopStackDepthOf​(V v)
        Retrieves the stack depth of the given vertex.
        Parameters:
        v - Vertex to check.
        Returns:
        The depth of the stack of LoopVertices for the vertex.
      • getAssignedLoopVertexOf

        LoopVertex getAssignedLoopVertexOf​(V v)
        Retrieves the wrapping LoopVertex of the vertex.
        Parameters:
        v - Vertex to check.
        Returns:
        The wrapping LoopVertex.
      • asJsonNode

        com.fasterxml.jackson.databind.node.ObjectNode asJsonNode()
        Returns:
        JsonNode for this DAG.
      • storeJSON

        void storeJSON​(java.lang.String directory,
                       java.lang.String name,
                       java.lang.String description)
        Stores JSON representation of this DAG into a file.
        Parameters:
        directory - the directory which JSON representation is saved to
        name - name of this DAG
        description - description of this DAG