Class UndirectedGraphImpl<V,​E>

    • Constructor Detail

      • UndirectedGraphImpl

        public UndirectedGraphImpl()
    • Method Detail

      • removeVertex

        public V removeVertex​(int v)
        Description copied from interface: UndirectedGraph
        Remove the specified vertex and notify the UndirectedGraphListeners. This method throws a PowsyblException if the vertex doesn't exist or if an edge is connected to this vertex.
        Specified by:
        removeVertex in interface UndirectedGraph<V,​E>
        Parameters:
        v - the vertex index to remove.
        Returns:
        the value attached to the vertex.
      • getVertexCount

        public int getVertexCount()
        Description copied from interface: UndirectedGraph
        Return the number of non-null vertices. As the contiguity of vertices is not mandatory, the number of vertices can be less than the highest vertex index.
        Specified by:
        getVertexCount in interface UndirectedGraph<V,​E>
        Returns:
        the number of vertices.
      • addEdge

        public int addEdge​(int v1,
                           int v2,
                           E obj)
        Description copied from interface: UndirectedGraph
        Create an edge between the two specified vertices and notify the UndirectedGraphListeners. This method throws a PowsyblException if one of the vertices doesn't exist.
        Specified by:
        addEdge in interface UndirectedGraph<V,​E>
        Parameters:
        v1 - the first end of the edge.
        v2 - the second end of the edge.
        obj - the value attached to the edge.
        Returns:
        the index of the new edge.
      • getVertices

        public int[] getVertices()
        Description copied from interface: UndirectedGraph
        Return the indices of the vertices.
        Specified by:
        getVertices in interface UndirectedGraph<V,​E>
        Returns:
        the indices of the vertices.
      • getEdges

        public int[] getEdges()
        Description copied from interface: UndirectedGraph
        Return the indices of the edges.
        Specified by:
        getEdges in interface UndirectedGraph<V,​E>
        Returns:
        the indices of the edges.
      • getVertexCapacity

        public int getVertexCapacity()
        Description copied from interface: UndirectedGraph
        Return the maximum number of vertices that this graph can contain. The vertex indices are in the range [0, getVertexCapacity[ As the contiguity of the vertices is not mandatory, do not use this method to iterate over the vertices. Use UndirectedGraph.getVertices() instead. To get the number of vertices in this graph, use UndirectedGraph.getVertexCount().
        Specified by:
        getVertexCapacity in interface UndirectedGraph<V,​E>
        Returns:
        the maximum number of vertices contained in this graph.
      • getVertexObject

        public V getVertexObject​(int v)
        Description copied from interface: UndirectedGraph
        Return the value attached to the specified vertex. This method throws a PowsyblException if the vertex doesn't exist.
        Specified by:
        getVertexObject in interface UndirectedGraph<V,​E>
        Parameters:
        v - the vertex index
        Returns:
        the value attached to the specified vertex.
      • setVertexObject

        public void setVertexObject​(int v,
                                    V obj)
        Description copied from interface: UndirectedGraph
        Set the value attached to the specified vertex. This method throws a PowsyblException if the vertex doesn't exist.
        Specified by:
        setVertexObject in interface UndirectedGraph<V,​E>
        Parameters:
        v - the vertex index.
        obj - the value to attach to the vertex.
      • getEdgeVertex1

        public int getEdgeVertex1​(int e)
        Description copied from interface: UndirectedGraph
        Return the index of the first vertex that the specified edge is connected to. This method throws a PowsyblException if the edge doesn't exist.
        Specified by:
        getEdgeVertex1 in interface UndirectedGraph<V,​E>
        Parameters:
        e - the edge index.
        Returns:
        the index of the first vertex that the specified edge is connected to.
      • getEdgeVertex2

        public int getEdgeVertex2​(int e)
        Description copied from interface: UndirectedGraph
        Return the index of the second vertex that the specified edge is connected to. This method throws a PowsyblException if the edge doesn't exist.
        Specified by:
        getEdgeVertex2 in interface UndirectedGraph<V,​E>
        Parameters:
        e - the edge index.
        Returns:
        the index of the second vertex that the specified edge is connected to.
      • getEdgeObject

        public E getEdgeObject​(int e)
        Description copied from interface: UndirectedGraph
        Return the value attached to the specified edge.
        Specified by:
        getEdgeObject in interface UndirectedGraph<V,​E>
        Parameters:
        e - the index of an edge.
        Returns:
        the value attached to the specified edge.
      • getEdgeObjects

        public List<E> getEdgeObjects​(int v1,
                                      int v2)
        Description copied from interface: UndirectedGraph
        Return a List containing the values attached to the edges between the vertices v1 and v2.
        Specified by:
        getEdgeObjects in interface UndirectedGraph<V,​E>
        Returns:
        a List containing the values attached to the edges between the vertices v1 and v2.
      • traverse

        public void traverse​(int v,
                             Traverser traverser,
                             boolean[] encountered)
        Description copied from interface: UndirectedGraph
        Traverse the entire graph, starting at the specified vertex v. This method relies on a Traverser instance to know if the traverse of the graph should continue or stop. This method throws a PowsyblException if the encountered table size is less than the maximum vertex index. At the end of the method, the encountered array contains true for all the traversed vertices, false otherwise.
        Specified by:
        traverse in interface UndirectedGraph<V,​E>
        Parameters:
        v - the vertex index where the traverse has to start.
        traverser - the Traverser instance to use to know if the traverse should continue or stop.
        encountered - the list of traversed vertices.
      • findAllPaths

        public List<gnu.trove.list.array.TIntArrayList> findAllPaths​(int from,
                                                                     Function<V,​Boolean> pathComplete,
                                                                     Function<E,​Boolean> pathCancelled)
        Find all paths from the specified vertex. This method relies on two functions to stop the traverse when the target vertex is found or when an edge must not be traversed.. This method allocates a List of TIntArrayList to store the paths, a BitSet to store the encountered vertices and calls findAllPaths(int, Function, Function, TIntArrayList, BitSet, List).
        Specified by:
        findAllPaths in interface UndirectedGraph<V,​E>
        Parameters:
        from - the vertex index where the traverse has to start.
        pathComplete - a function that returns true when the target vertex is found.
        pathCancelled - a function that returns true when the edge must not be traversed.
        Returns:
        a list that contains the index of the traversed edges.
      • print

        public void print​(PrintStream out,
                          Function<V,​String> vertexToString,
                          Function<E,​String> edgeToString)
        Description copied from interface: UndirectedGraph
        Prints the entire graph to the specified PrintStream. The printing relies on the two specified functions to render the values attached to a vertex or an edge.
        Specified by:
        print in interface UndirectedGraph<V,​E>
        Parameters:
        out - the output stream.
        vertexToString - the function to use to render the values of vertices.
        edgeToString - the function to use to render the values of edges.