Interface Hypergraph<V,E>
-
- All Known Subinterfaces:
DirectedGraph<V,E>,Forest<V,E>,Graph<V,E>,KPartiteGraph<V,E>,Tree<V,E>,UndirectedGraph<V,E>
- All Known Implementing Classes:
GraphDecorator,ObservableGraph
public interface Hypergraph<V,E>A hypergraph, consisting of a set of vertices of typeVand a set of hyperedges of typeEwhich connect the vertices. This is the base interface for all JUNG graph types.This interface permits, but does not enforce, any of the following common variations of graphs:
-
hyperedges (edges which connect a set of vertices of any size)
edges (these have have exactly two endpoints, which may or may not be distinct)
self-loops (edges which connect exactly one vertex)
- directed and undirected edges
- vertices and edges with attributes (for example, weighted edges)
- vertices and edges with different constraints or properties (for example, bipartite or multimodal graphs)
- parallel edges (multiple edges which connect a single set of vertices)
- internal representations as matrices or as adjacency lists or adjacency maps
Notes:
-
The collections returned by
Hypergraphinstances should be treated in general as if read-only. While they are not contractually guaranteed (or required) to be immutable, this interface does not define the outcome if they are mutated. Mutations should be done via{add,remove}{Edge,Vertex}, or in the constructor.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanaddEdge(E edge, java.util.Collection<? extends V> vertices)Addsedgeto this graph.booleanaddEdge(E edge, java.util.Collection<? extends V> vertices, EdgeType edge_type)Addsedgeto this graph with typeedge_type.booleanaddVertex(V vertex)Addsvertexto this graph.booleancontainsEdge(E edge)Returns true if this graph's edge collection containsedge.booleancontainsVertex(V vertex)Returns true if this graph's vertex collection containsvertex.intdegree(V vertex)Returns the number of edges incident tovertex.EfindEdge(V v1, V v2)Returns an edge that connects this vertex tov.java.util.Collection<E>findEdgeSet(V v1, V v2)Returns all edges that connects this vertex tov.EdgeTypegetDefaultEdgeType()Returns the default edge type for this graph.VgetDest(E directed_edge)Ifdirected_edgeis a directed edge in this graph, returns the destination; otherwise returnsnull.intgetEdgeCount()Returns the number of edges in this graph.intgetEdgeCount(EdgeType edge_type)Returns the number of edges of typeedge_typein this graph.java.util.Collection<E>getEdges()Returns a view of all edges in this graph.java.util.Collection<E>getEdges(EdgeType edge_type)Returns the collection of edges in this graph which are of typeedge_type.EdgeTypegetEdgeType(E edge)Returns the edge type ofedgein this graph.intgetIncidentCount(E edge)Returns the number of vertices that are incident toedge.java.util.Collection<E>getIncidentEdges(V vertex)Returns the collection of edges in this graph which are connected tovertex.java.util.Collection<V>getIncidentVertices(E edge)Returns the collection of vertices in this graph which are connected toedge.java.util.Collection<E>getInEdges(V vertex)Returns aCollectionview of the incoming edges incident tovertexin this graph.intgetNeighborCount(V vertex)Returns the number of vertices that are adjacent tovertex(that is, the number of vertices that are incident to edges invertex's incident edge set).java.util.Collection<V>getNeighbors(V vertex)Returns the collection of vertices which are connected tovertexvia any edges in this graph.java.util.Collection<E>getOutEdges(V vertex)Returns aCollectionview of the outgoing edges incident tovertexin this graph.java.util.Collection<V>getPredecessors(V vertex)Returns aCollectionview of the predecessors ofvertexin this graph.VgetSource(E directed_edge)Ifdirected_edgeis a directed edge in this graph, returns the source; otherwise returnsnull.java.util.Collection<V>getSuccessors(V vertex)Returns aCollectionview of the successors ofvertexin this graph.intgetVertexCount()Returns the number of vertices in this graph.java.util.Collection<V>getVertices()Returns a view of all vertices in this graph.intinDegree(V vertex)Returns the number of incoming edges incident tovertex.booleanisIncident(V vertex, E edge)Returnstrueifvertexandedgeare incident to each other.booleanisNeighbor(V v1, V v2)Returnstrueifv1andv2share an incident edge.intoutDegree(V vertex)Returns the number of outgoing edges incident tovertex.booleanremoveEdge(E edge)Removesedgefrom this graph.booleanremoveVertex(V vertex)Removesvertexfrom this graph.
-
-
-
Method Detail
-
getEdges
java.util.Collection<E> getEdges()
Returns a view of all edges in this graph. In general, this obeys theCollectioncontract, and therefore makes no guarantees about the ordering of the vertices within the set.- Returns:
- a
Collectionview of all edges in this graph
-
getVertices
java.util.Collection<V> getVertices()
Returns a view of all vertices in this graph. In general, this obeys theCollectioncontract, and therefore makes no guarantees about the ordering of the vertices within the set.- Returns:
- a
Collectionview of all vertices in this graph
-
containsVertex
boolean containsVertex(V vertex)
Returns true if this graph's vertex collection containsvertex. Equivalent togetVertices().contains(vertex).- Parameters:
vertex- the vertex whose presence is being queried- Returns:
- true iff this graph contains a vertex
vertex
-
containsEdge
boolean containsEdge(E edge)
Returns true if this graph's edge collection containsedge. Equivalent togetEdges().contains(edge).- Parameters:
edge- the edge whose presence is being queried- Returns:
- true iff this graph contains an edge
edge
-
getEdgeCount
int getEdgeCount()
Returns the number of edges in this graph.- Returns:
- the number of edges in this graph
-
getVertexCount
int getVertexCount()
Returns the number of vertices in this graph.- Returns:
- the number of vertices in this graph
-
getNeighbors
java.util.Collection<V> getNeighbors(V vertex)
Returns the collection of vertices which are connected tovertexvia any edges in this graph. Ifvertexis connected to itself with a self-loop, then it will be included in the collection returned.- Parameters:
vertex- the vertex whose neighbors are to be returned- Returns:
- the collection of vertices which are connected to
vertex, ornullifvertexis not present
-
getIncidentEdges
java.util.Collection<E> getIncidentEdges(V vertex)
Returns the collection of edges in this graph which are connected tovertex.- Parameters:
vertex- the vertex whose incident edges are to be returned- Returns:
- the collection of edges which are connected to
vertex, ornullifvertexis not present
-
getIncidentVertices
java.util.Collection<V> getIncidentVertices(E edge)
Returns the collection of vertices in this graph which are connected toedge. Note that for some graph types there are guarantees about the size of this collection (i.e., some graphs contain edges that have exactly two endpoints, which may or may not be distinct). Implementations for those graph types may provide alternate methods that provide more convenient access to the vertices.- Parameters:
edge- the edge whose incident vertices are to be returned- Returns:
- the collection of vertices which are connected to
edge, ornullifedgeis not present
-
findEdge
E findEdge(V v1, V v2)
Returns an edge that connects this vertex tov. If this edge is not uniquely defined (that is, if the graph contains more than one edge connectingv1tov2), 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:v2is not connected tov1eitherv1orv2are not present in this graphNote: for purposes of this method,
v1is only considered to be connected tov2via a given directed edgeeifv1 == e.getSource() && v2 == e.getDest()evaluates totrue. (v1andv2are connected by an undirected edgeuifuis incident to bothv1andv2.)- Returns:
- an edge that connects
v1tov2, ornullif no such edge exists (or either vertex is not present) - See Also:
findEdgeSet(Object, Object)
-
findEdgeSet
java.util.Collection<E> findEdgeSet(V v1, V v2)
Returns all edges that connects this vertex tov. If this edge is not uniquely defined (that is, if the graph contains more than one edge connectingv1tov2), any of these edges may be returned.findEdgeSet(v1, v2)may be used to return all such edges. Returns null ifv2is not connected tov1.
Returns an empty collection if eitherv1orv2are not present in this graph.Note: for purposes of this method,
v1is only considered to be connected tov2via a given directed edgedifv1 == d.getSource() && v2 == d.getDest()evaluates totrue. (v1andv2are connected by an undirected edgeuifuis incident to bothv1andv2.)- Returns:
- a collection containing all edges that connect
v1tov2, ornullif either vertex is not present - See Also:
findEdge(Object, Object)
-
addVertex
boolean addVertex(V vertex)
Addsvertexto this graph. Fails ifvertexis null or already in the graph.- Parameters:
vertex- the vertex to add- Returns:
trueif the add is successful, andfalseotherwise- Throws:
java.lang.IllegalArgumentException- ifvertexisnull
-
addEdge
boolean addEdge(E edge, java.util.Collection<? extends V> vertices)
Addsedgeto this graph. Fails under the following circumstances:edgeis already an element of the graph eitheredgeorverticesisnullverticeshas the wrong number of vertices for the graph typeverticesare already connected by another edge in this graph, and this graph does not accept parallel edges- Parameters:
edge-vertices-- Returns:
trueif the add is successful, andfalseotherwise- Throws:
java.lang.IllegalArgumentException- ifedgeorverticesis null, or if a different vertex set in this graph is already connected byedge, or ifverticesare not a legal vertex set foredge
-
addEdge
boolean addEdge(E edge, java.util.Collection<? extends V> vertices, EdgeType edge_type)
Addsedgeto this graph with typeedge_type. Fails under the following circumstances:edgeis already an element of the graph eitheredgeorverticesisnullverticeshas the wrong number of vertices for the graph typeverticesare already connected by another edge in this graph, and this graph does not accept parallel edgesedge_typeis not legal for this graph- Parameters:
edge-vertices-- Returns:
trueif the add is successful, andfalseotherwise- Throws:
java.lang.IllegalArgumentException- ifedgeorverticesis null, or if a different vertex set in this graph is already connected byedge, or ifverticesare not a legal vertex set foredge
-
removeVertex
boolean removeVertex(V vertex)
Removesvertexfrom this graph. As a side effect, removes any edgeseincident tovertexif the removal ofvertexwould causeeto 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:
vertexis not an element of this graphvertexisnull- Parameters:
vertex- the vertex to remove- Returns:
trueif the removal is successful,falseotherwise
-
removeEdge
boolean removeEdge(E edge)
Removesedgefrom this graph. Fails ifedgeis null, or is otherwise not an element of this graph.- Parameters:
edge- the edge to remove- Returns:
trueif the removal is successful,falseotherwise
-
isNeighbor
boolean isNeighbor(V v1, V v2)
Returnstrueifv1andv2share an incident edge. Equivalent togetNeighbors(v1).contains(v2).- Parameters:
v1- the first vertex to testv2- the second vertex to test- Returns:
trueifv1andv2share an incident edge
-
isIncident
boolean isIncident(V vertex, E edge)
Returnstrueifvertexandedgeare incident to each other. Equivalent togetIncidentEdges(vertex).contains(edge)and togetIncidentVertices(edge).contains(vertex).- Parameters:
vertex-edge-- Returns:
trueifvertexandedgeare incident to each other
-
degree
int degree(V vertex)
Returns the number of edges incident tovertex. Special cases of interest:-
Incident self-loops are counted once.
- If there is only one edge that connects this vertex to
each of its neighbors (and vice versa), then the value returned
will also be equal to the number of neighbors that this vertex has
(that is, the output of
getNeighborCount). - If the graph is directed, then the value returned will be the sum of this vertex's indegree (the number of edges whose destination is this vertex) and its outdegree (the number of edges whose source is this vertex), minus the number of incident self-loops (to avoid double-counting).
Equivalent to
getIncidentEdges(vertex).size().- Parameters:
vertex- the vertex whose degree is to be returned- Returns:
- the degree of this node
- See Also:
getNeighborCount(Object)
- If there is only one edge that connects this vertex to
each of its neighbors (and vice versa), then the value returned
will also be equal to the number of neighbors that this vertex has
(that is, the output of
-
getNeighborCount
int getNeighborCount(V vertex)
Returns the number of vertices that are adjacent tovertex(that is, the number of vertices that are incident to edges invertex's incident edge set).Equivalent to
getNeighbors(vertex).size().- Parameters:
vertex- the vertex whose neighbor count is to be returned- Returns:
- the number of neighboring vertices
-
getIncidentCount
int getIncidentCount(E edge)
Returns the number of vertices that are incident toedge. For hyperedges, this can be any nonnegative integer; for edges this must be 2 (or 1 if self-loops are permitted).Equivalent to
getIncidentVertices(edge).size().- Parameters:
edge- the edge whose incident vertex count is to be returned- Returns:
- the number of vertices that are incident to
edge.
-
getEdgeType
EdgeType getEdgeType(E edge)
Returns the edge type ofedgein this graph.- Parameters:
edge-- Returns:
- the
EdgeTypeofedge, ornullifedgehas no defined type
-
getDefaultEdgeType
EdgeType getDefaultEdgeType()
Returns the default edge type for this graph.- Returns:
- the default edge type for this graph
-
getEdges
java.util.Collection<E> getEdges(EdgeType edge_type)
Returns the collection of edges in this graph which are of typeedge_type.- Parameters:
edge_type- the type of edges to be returned- Returns:
- the collection of edges which are of type
edge_type, ornullif the graph does not accept edges of this type - See Also:
EdgeType
-
getEdgeCount
int getEdgeCount(EdgeType edge_type)
Returns the number of edges of typeedge_typein this graph.- Parameters:
edge_type- the type of edge for which the count is to be returned- Returns:
- the number of edges of type
edge_typein this graph
-
getInEdges
java.util.Collection<E> getInEdges(V vertex)
Returns aCollectionview of the incoming edges incident tovertexin this graph.- Parameters:
vertex- the vertex whose incoming edges are to be returned- Returns:
- a
Collectionview of the incoming edges incident tovertexin this graph
-
getOutEdges
java.util.Collection<E> getOutEdges(V vertex)
Returns aCollectionview of the outgoing edges incident tovertexin this graph.- Parameters:
vertex- the vertex whose outgoing edges are to be returned- Returns:
- a
Collectionview of the outgoing edges incident tovertexin this graph
-
inDegree
int inDegree(V vertex)
Returns the number of incoming edges incident tovertex. Equivalent togetInEdges(vertex).size().- Parameters:
vertex- the vertex whose indegree is to be calculated- Returns:
- the number of incoming edges incident to
vertex
-
outDegree
int outDegree(V vertex)
Returns the number of outgoing edges incident tovertex. Equivalent togetOutEdges(vertex).size().- Parameters:
vertex- the vertex whose outdegree is to be calculated- Returns:
- the number of outgoing edges incident to
vertex
-
getSource
V getSource(E directed_edge)
Ifdirected_edgeis a directed edge in this graph, returns the source; otherwise returnsnull. The source of a directed edgedis defined to be the vertex for whichdis an outgoing edge.directed_edgeis guaranteed to be a directed edge if itsEdgeTypeisDIRECTED.- Parameters:
directed_edge-- Returns:
- the source of
directed_edgeif it is a directed edge in this graph, ornullotherwise
-
getDest
V getDest(E directed_edge)
Ifdirected_edgeis a directed edge in this graph, returns the destination; otherwise returnsnull. The destination of a directed edgedis defined to be the vertex incident todfor whichdis an incoming edge.directed_edgeis guaranteed to be a directed edge if itsEdgeTypeisDIRECTED.- Parameters:
directed_edge-- Returns:
- the destination of
directed_edgeif it is a directed edge in this graph, ornullotherwise
-
getPredecessors
java.util.Collection<V> getPredecessors(V vertex)
Returns aCollectionview of the predecessors ofvertexin this graph. A predecessor ofvertexis defined as a vertexvwhich is connected tovertexby an edgee, whereeis an outgoing edge ofvand an incoming edge ofvertex.- Parameters:
vertex- the vertex whose predecessors are to be returned- Returns:
- a
Collectionview of the predecessors ofvertexin this graph
-
getSuccessors
java.util.Collection<V> getSuccessors(V vertex)
Returns aCollectionview of the successors ofvertexin this graph. A successor ofvertexis defined as a vertexvwhich is connected tovertexby an edgee, whereeis an incoming edge ofvand an outgoing edge ofvertex.- Parameters:
vertex- the vertex whose predecessors are to be returned- Returns:
- a
Collectionview of the successors ofvertexin this graph
-
-