Class UndirectedSparseMultigraph<V,E>

java.lang.Object
edu.uci.ics.jung.graph.AbstractGraph<V,E>
edu.uci.ics.jung.graph.AbstractTypedGraph<V,E>
edu.uci.ics.jung.graph.UndirectedSparseMultigraph<V,E>
All Implemented Interfaces:
Graph<V,E>, Hypergraph<V,E>, MultiGraph<V,E>, UndirectedGraph<V,E>, Serializable
Direct Known Subclasses:
UndirectedOrderedSparseMultigraph

public class UndirectedSparseMultigraph<V,E> extends AbstractTypedGraph<V,E> implements UndirectedGraph<V,E>, MultiGraph<V,E>
An implementation of UndirectedGraph that is suitable for sparse graphs and permits parallel edges.
See Also:
  • Field Details

  • Constructor Details

    • UndirectedSparseMultigraph

      public UndirectedSparseMultigraph()
      Creates a new instance.
  • Method Details

    • getFactory

      public static <V, E> com.google.common.base.Supplier<UndirectedGraph<V,E>> getFactory()
      Type Parameters:
      V - the vertex type for the graph Supplier
      E - the edge type for the graph Supplier
      Returns:
      a Supplier that creates an instance of this graph type.
    • getEdges

      public Collection<E> getEdges()
      Description copied from interface: Hypergraph
      Returns a view of all edges in this graph. In general, this obeys the Collection contract, and therefore makes no guarantees about the ordering of the vertices within the set.
      Specified by:
      getEdges in interface Hypergraph<V,E>
      Returns:
      a Collection view of all edges in this graph
    • getVertices

      public Collection<V> getVertices()
      Description copied from interface: Hypergraph
      Returns a view of all vertices in this graph. In general, this obeys the Collection contract, and therefore makes no guarantees about the ordering of the vertices within the set.
      Specified by:
      getVertices in interface Hypergraph<V,E>
      Returns:
      a Collection view of all vertices in this graph
    • containsVertex

      public boolean containsVertex(V vertex)
      Description copied from interface: Hypergraph
      Returns true if this graph's vertex collection contains vertex. Equivalent to getVertices().contains(vertex).
      Specified by:
      containsVertex in interface Hypergraph<V,E>
      Parameters:
      vertex - the vertex whose presence is being queried
      Returns:
      true iff this graph contains a vertex vertex
    • containsEdge

      public boolean containsEdge(E edge)
      Description copied from interface: Hypergraph
      Returns true if this graph's edge collection contains edge. Equivalent to getEdges().contains(edge).
      Specified by:
      containsEdge in interface Hypergraph<V,E>
      Parameters:
      edge - the edge whose presence is being queried
      Returns:
      true iff this graph contains an edge edge
    • getIncident_internal

      protected Collection<E> getIncident_internal(V vertex)
    • addVertex

      public boolean addVertex(V vertex)
      Description copied from interface: Hypergraph
      Adds vertex to this graph. Fails if vertex is null or already in the graph.
      Specified by:
      addVertex in interface Hypergraph<V,E>
      Parameters:
      vertex - the vertex to add
      Returns:
      true if the add is successful, and false otherwise
    • removeVertex

      public boolean removeVertex(V vertex)
      Description copied from interface: Hypergraph
      Removes vertex from this graph. As a side effect, removes any edges e incident to vertex if the removal of vertex would cause e to be incident to an illegal number of vertices. (Thus, for example, incident hyperedges are not removed, but incident edges--which must be connected to a vertex at both endpoints--are removed.)

      Fails under the following circumstances:

      • vertex is not an element of this graph
      • vertex is null
      Specified by:
      removeVertex in interface Hypergraph<V,E>
      Parameters:
      vertex - the vertex to remove
      Returns:
      true if the removal is successful, false otherwise
    • addEdge

      public boolean addEdge(E edge, V v1, V v2, EdgeType edgeType)
      Description copied from interface: Graph
      Adds edge e to this graph such that it connects vertex v1 to v2. Equivalent to addEdge(e, new Pair(v1, v2)). If this graph does not contain v1, v2, or both, implementations may choose to either silently add the vertices to the graph or throw an IllegalArgumentException. If edgeType is not legal for this graph, this method will throw IllegalArgumentException. See Hypergraph.addEdge() for a listing of possible reasons for failure.
      Specified by:
      addEdge in interface Graph<V,E>
      Overrides:
      addEdge in class AbstractGraph<V,E>
      Parameters:
      edge - the edge to be added
      v1 - the first vertex to be connected
      v2 - the second vertex to be connected
      edgeType - the type to be assigned to the edge
      Returns:
      true if the add is successful, false otherwise
      See Also:
    • addEdge

      public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edge_type)
      Description copied from class: AbstractGraph
      Adds edge to this graph with the specified endpoints and EdgeType.
      Specified by:
      addEdge in class AbstractGraph<V,E>
      Parameters:
      edge - the edge to be added
      endpoints - the endpoints to be connected to this edge
      edge_type - the type of edge to add
      Returns:
      true iff the graph was modified as a result of this call
    • removeEdge

      public boolean removeEdge(E edge)
      Description copied from interface: Hypergraph
      Removes edge from this graph. Fails if edge is null, or is otherwise not an element of this graph.
      Specified by:
      removeEdge in interface Hypergraph<V,E>
      Parameters:
      edge - the edge to remove
      Returns:
      true if the removal is successful, false otherwise
    • getInEdges

      public Collection<E> getInEdges(V vertex)
      Description copied from interface: Graph
      Returns a Collection view of the incoming edges incident to vertex in this graph.
      Specified by:
      getInEdges in interface Graph<V,E>
      Specified by:
      getInEdges in interface Hypergraph<V,E>
      Parameters:
      vertex - the vertex whose incoming edges are to be returned
      Returns:
      a Collection view of the incoming edges incident to vertex in this graph
    • getOutEdges

      public Collection<E> getOutEdges(V vertex)
      Description copied from interface: Graph
      Returns a Collection view of the outgoing edges incident to vertex in this graph.
      Specified by:
      getOutEdges in interface Graph<V,E>
      Specified by:
      getOutEdges in interface Hypergraph<V,E>
      Parameters:
      vertex - the vertex whose outgoing edges are to be returned
      Returns:
      a Collection view of the outgoing edges incident to vertex in this graph
    • getPredecessors

      public Collection<V> getPredecessors(V vertex)
      Description copied from interface: Graph
      Returns a Collection view of the predecessors of vertex in this graph. A predecessor of vertex is defined as a vertex v which is connected to vertex by an edge e, where e is an outgoing edge of v and an incoming edge of vertex.
      Specified by:
      getPredecessors in interface Graph<V,E>
      Specified by:
      getPredecessors in interface Hypergraph<V,E>
      Parameters:
      vertex - the vertex whose predecessors are to be returned
      Returns:
      a Collection view of the predecessors of vertex in this graph
    • getSuccessors

      public Collection<V> getSuccessors(V vertex)
      Description copied from interface: Graph
      Returns a Collection view of the successors of vertex in this graph. A successor of vertex is defined as a vertex v which is connected to vertex by an edge e, where e is an incoming edge of v and an outgoing edge of vertex.
      Specified by:
      getSuccessors in interface Graph<V,E>
      Specified by:
      getSuccessors in interface Hypergraph<V,E>
      Parameters:
      vertex - the vertex whose predecessors are to be returned
      Returns:
      a Collection view of the successors of vertex in this graph
    • getNeighbors

      public Collection<V> getNeighbors(V vertex)
      Description copied from interface: Hypergraph
      Returns the collection of vertices which are connected to vertex via any edges in this graph. If vertex is connected to itself with a self-loop, then it will be included in the collection returned.
      Specified by:
      getNeighbors in interface Hypergraph<V,E>
      Parameters:
      vertex - the vertex whose neighbors are to be returned
      Returns:
      the collection of vertices which are connected to vertex, or null if vertex is not present
    • getIncidentEdges

      public Collection<E> getIncidentEdges(V vertex)
      Description copied from interface: Hypergraph
      Returns the collection of edges in this graph which are connected to vertex.
      Specified by:
      getIncidentEdges in interface Hypergraph<V,E>
      Parameters:
      vertex - the vertex whose incident edges are to be returned
      Returns:
      the collection of edges which are connected to vertex, or null if vertex is not present
    • findEdge

      public E findEdge(V v1, V v2)
      Description copied from interface: Hypergraph
      Returns an edge that connects this vertex to v. If this edge is not uniquely defined (that is, if the graph contains more than one edge connecting v1 to v2), any of these edges may be returned. findEdgeSet(v1, v2) may be used to return all such edges. Returns null if either of the following is true:
      • v2 is not connected to v1
      • either v1 or v2 are not present in this graph

      Note: for purposes of this method, v1 is only considered to be connected to v2 via a given directed edge e if v1 == e.getSource() && v2 == e.getDest() evaluates to true. (v1 and v2 are connected by an undirected edge u if u is incident to both v1 and v2.)

      Specified by:
      findEdge in interface Hypergraph<V,E>
      Overrides:
      findEdge in class AbstractGraph<V,E>
      Parameters:
      v1 - the first endpoint of the returned edge
      v2 - the second endpoint of the returned edge
      Returns:
      an edge that connects v1 to v2, or null if no such edge exists (or either vertex is not present)
      See Also:
    • getEndpoints

      public Pair<V> getEndpoints(E edge)
      Description copied from interface: Graph
      Returns the endpoints of edge as a Pair.
      Specified by:
      getEndpoints in interface Graph<V,E>
      Parameters:
      edge - the edge whose endpoints are to be returned
      Returns:
      the endpoints (incident vertices) of edge
    • getDest

      public V getDest(E directed_edge)
      Description copied from interface: Graph
      If directed_edge is a directed edge in this graph, returns the destination; otherwise returns null. The destination of a directed edge d is defined to be the vertex incident to d for which d is an incoming edge. directed_edge is guaranteed to be a directed edge if its EdgeType is DIRECTED.
      Specified by:
      getDest in interface Graph<V,E>
      Specified by:
      getDest in interface Hypergraph<V,E>
      Parameters:
      directed_edge - the edge whose destination is to be returned
      Returns:
      the destination of directed_edge if it is a directed edge in this graph, or null otherwise
    • getSource

      public V getSource(E directed_edge)
      Description copied from interface: Graph
      If directed_edge is a directed edge in this graph, returns the source; otherwise returns null. The source of a directed edge d is defined to be the vertex for which d is an outgoing edge. directed_edge is guaranteed to be a directed edge if its EdgeType is DIRECTED.
      Specified by:
      getSource in interface Graph<V,E>
      Specified by:
      getSource in interface Hypergraph<V,E>
      Parameters:
      directed_edge - the edge whose source is to be returned
      Returns:
      the source of directed_edge if it is a directed edge in this graph, or null otherwise
    • isDest

      public boolean isDest(V vertex, E edge)
      Description copied from interface: Graph
      Returns true if vertex is the destination of edge. Equivalent to getDest(edge).equals(vertex).
      Specified by:
      isDest in interface Graph<V,E>
      Parameters:
      vertex - the vertex to be queried
      edge - the edge to be queried
      Returns:
      true iff vertex is the destination of edge
    • isSource

      public boolean isSource(V vertex, E edge)
      Description copied from interface: Graph
      Returns true if vertex is the source of edge. Equivalent to getSource(edge).equals(vertex).
      Specified by:
      isSource in interface Graph<V,E>
      Parameters:
      vertex - the vertex to be queried
      edge - the edge to be queried
      Returns:
      true iff vertex is the source of edge
    • getEdgeCount

      public int getEdgeCount()
      Description copied from interface: Hypergraph
      Returns the number of edges in this graph.
      Specified by:
      getEdgeCount in interface Hypergraph<V,E>
      Returns:
      the number of edges in this graph
    • getVertexCount

      public int getVertexCount()
      Description copied from interface: Hypergraph
      Returns the number of vertices in this graph.
      Specified by:
      getVertexCount in interface Hypergraph<V,E>
      Returns:
      the number of vertices in this graph