Class Graph<T>

  • Type Parameters:
    T - the type of values in each graph node

    public class Graph<T>
    extends Object
    This class implements a very simple directed graph.
    Author:
    mhschroe
    • Constructor Detail

      • Graph

        public Graph()
    • Method Detail

      • addNode

        public void addNode​(T node,
                            T... neighbours)
      • addSingleNode

        protected void addSingleNode​(T node)
      • addSingleEdge

        protected void addSingleEdge​(T start,
                                     T end)
      • getNodes

        public Set<T> getNodes()
      • addEdges

        public void addEdges​(T node,
                             T... neighbours)
        Simple name-wrapper for addNode(Object, Object...), as the code for adding a node or adding edges is identical.
        Parameters:
        node - the node
        neighbours - its children
      • getEdgesFor

        public Set<T> getEdgesFor​(T node)
      • removeNode

        public void removeNode​(T node)
      • removeEdge

        public void removeEdge​(T start,
                               T end)
      • getNumNodes

        public int getNumNodes()
      • getLeaves

        public Set<T> getLeaves​(Set<T> ignored)
        This function returns terminal leaf nodes. That is, it returns all those nodes that do not have any outgoing edges.
        Parameters:
        ignored - a set of nodes to ignore for the purpose of identifying leaves. That means those nodes will not be returned, even if they are leaves and nodes that only have edges to them are considered leaves.
        Returns:
        a set of leaf nodes.
      • getMinimalOutboundEdgeNodes

        public Set<T> getMinimalOutboundEdgeNodes​(Set<T> ignored)
        This function returns all those nodes that have the current minimum of outbound edges.
        Parameters:
        ignored - a set of nodes to ignore for the purpose of counting edges.
        Returns:
        a set of nodes with minimal number of outbound edges. Will not contain any node from ignored.
      • getMinimalInboundEdgeNodes

        public Set<T> getMinimalInboundEdgeNodes​(Set<T> ignored)
        This function returns all those nodes that have the current minimum number of inbound edges.
        Parameters:
        ignored - a set of nodes to ignore for the purpose of counting edges.
        Returns:
        a set of nodes with minimal number of inbound edges. Will not contain any node from ignored.
      • getSpanningTree

        public Graph<T> getSpanningTree()