Package edu.uci.ics.jung.graph
Class SetHypergraph<V,H>
java.lang.Object
edu.uci.ics.jung.graph.SetHypergraph<V,H>
- All Implemented Interfaces:
Hypergraph<V,
,H> MultiGraph<V,
,H> Serializable
public class SetHypergraph<V,H>
extends Object
implements Hypergraph<V,H>, MultiGraph<V,H>, Serializable
An implementation of
Hypergraph
that is suitable for sparse graphs and
permits parallel edges.- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates aSetHypergraph
and initializes the internal data structures. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addEdge
(H hyperedge, Collection<? extends V> to_attach) Addshyperedge
to this graph and connects them to the vertex collectionto_attach
.boolean
addEdge
(H hyperedge, Collection<? extends V> to_attach, EdgeType edge_type) Addsedge
to this graph with typeedge_type
.boolean
Addsvertex
to this graph.boolean
containsEdge
(H edge) Returns true if this graph's edge collection containsedge
.boolean
containsVertex
(V vertex) Returns true if this graph's vertex collection containsvertex
.int
Returns the number of edges incident tovertex
.Returns an edge that connects this vertex tov
.findEdgeSet
(V v1, V v2) Returns all edges that connects this vertex tov
.Returns the default edge type for this graph.Ifdirected_edge
is a directed edge in this graph, returns the destination; otherwise returnsnull
.int
Returns the number of edges in this graph.int
getEdgeCount
(EdgeType edge_type) Returns the number of edges of typeedge_type
in this graph.getEdges()
Returns a view of all edges in this graph.Returns the collection of edges in this graph which are of typeedge_type
.getEdgeType
(H edge) Returns the edge type ofedge
in this graph.static <V,
H> com.google.common.base.Supplier <Hypergraph<V, H>> Returns aFactory
which creates instances of this class.int
getIncidentCount
(H edge) Returns the number of vertices that are incident toedge
.getIncidentEdges
(V vertex) Returns the collection of edges in this graph which are connected tovertex
.getIncidentVertices
(H edge) Returns the collection of vertices in this graph which are connected toedge
.getInEdges
(V vertex) Returns aCollection
view of the incoming edges incident tovertex
in this graph.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).getNeighbors
(V vertex) Returns the collection of vertices which are connected tovertex
via any edges in this graph.getOutEdges
(V vertex) Returns aCollection
view of the outgoing edges incident tovertex
in this graph.getPredecessors
(V vertex) Returns aCollection
view of the predecessors ofvertex
in this graph.Ifdirected_edge
is a directed edge in this graph, returns the source; otherwise returnsnull
.getSuccessors
(V vertex) Returns aCollection
view of the successors ofvertex
in this graph.int
Returns the number of vertices in this graph.Returns a view of all vertices in this graph.int
Returns the number of incoming edges incident tovertex
.boolean
isIncident
(V vertex, H edge) Returnstrue
ifvertex
andedge
are incident to each other.boolean
isNeighbor
(V v1, V v2) Returnstrue
ifv1
andv2
share an incident edge.int
Returns the number of outgoing edges incident tovertex
.boolean
removeEdge
(H hyperedge) Removesedge
from this graph.boolean
removeVertex
(V vertex) Removesvertex
from this graph.
-
Field Details
-
vertices
-
edges
-
-
Constructor Details
-
SetHypergraph
public SetHypergraph()Creates aSetHypergraph
and initializes the internal data structures.
-
-
Method Details
-
getFactory
Returns aFactory
which creates instances of this class.- Type Parameters:
V
- vertex type of the hypergraph to be createdH
- edge type of the hypergraph to be created- Returns:
- a
Factory
which creates instances of this class
-
addEdge
Addshyperedge
to this graph and connects them to the vertex collectionto_attach
. Any vertices into_attach
that appear more than once will only appear once in the incident vertex collection forhyperedge
, that is, duplicates will be ignored.- Specified by:
addEdge
in interfaceHypergraph<V,
H> - Parameters:
hyperedge
- the edge to addto_attach
- the vertices to which the edge will be connected- Returns:
true
if the add is successful, andfalse
otherwise- See Also:
-
addEdge
Description copied from interface:Hypergraph
Addsedge
to this graph with typeedge_type
. Fails under the following circumstances:edge
is already an element of the graph- either
edge
orvertices
isnull
vertices
has the wrong number of vertices for the graph typevertices
are already connected by another edge in this graph, and this graph does not accept parallel edgesedge_type
is not legal for this graph
- Specified by:
addEdge
in interfaceHypergraph<V,
H> - Parameters:
hyperedge
- edge to add to this graphto_attach
- vertices which are to be connected by this edgeedge_type
- type of edge to add- Returns:
true
if the add is successful, andfalse
otherwise- See Also:
-
getEdgeType
Description copied from interface:Hypergraph
Returns the edge type ofedge
in this graph.- Specified by:
getEdgeType
in interfaceHypergraph<V,
H> - Parameters:
edge
- the edge whose type is to be returned- Returns:
- the
EdgeType
ofedge
, ornull
ifedge
has no defined type - See Also:
-
containsVertex
Description copied from interface:Hypergraph
Returns true if this graph's vertex collection containsvertex
. Equivalent togetVertices().contains(vertex)
.- Specified by:
containsVertex
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex whose presence is being queried- Returns:
- true iff this graph contains a vertex
vertex
-
containsEdge
Description copied from interface:Hypergraph
Returns true if this graph's edge collection containsedge
. Equivalent togetEdges().contains(edge)
.- Specified by:
containsEdge
in interfaceHypergraph<V,
H> - Parameters:
edge
- the edge whose presence is being queried- Returns:
- true iff this graph contains an edge
edge
-
getEdges
Description copied from interface:Hypergraph
Returns a view of all edges in this graph. In general, this obeys theCollection
contract, and therefore makes no guarantees about the ordering of the vertices within the set.- Specified by:
getEdges
in interfaceHypergraph<V,
H> - Returns:
- a
Collection
view of all edges in this graph
-
getVertices
Description copied from interface:Hypergraph
Returns a view of all vertices in this graph. In general, this obeys theCollection
contract, and therefore makes no guarantees about the ordering of the vertices within the set.- Specified by:
getVertices
in interfaceHypergraph<V,
H> - Returns:
- a
Collection
view of all vertices in this graph
-
getEdgeCount
public int getEdgeCount()Description copied from interface:Hypergraph
Returns the number of edges in this graph.- Specified by:
getEdgeCount
in interfaceHypergraph<V,
H> - 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 interfaceHypergraph<V,
H> - Returns:
- the number of vertices in this graph
-
getNeighbors
Description copied from interface:Hypergraph
Returns the collection of vertices which are connected tovertex
via any edges in this graph. Ifvertex
is connected to itself with a self-loop, then it will be included in the collection returned.- Specified by:
getNeighbors
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex whose neighbors are to be returned- Returns:
- the collection of vertices which are connected to
vertex
, ornull
ifvertex
is not present
-
getIncidentEdges
Description copied from interface:Hypergraph
Returns the collection of edges in this graph which are connected tovertex
.- Specified by:
getIncidentEdges
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex whose incident edges are to be returned- Returns:
- the collection of edges which are connected to
vertex
, ornull
ifvertex
is not present
-
getIncidentVertices
Description copied from interface:Hypergraph
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.- Specified by:
getIncidentVertices
in interfaceHypergraph<V,
H> - Parameters:
edge
- the edge whose incident vertices are to be returned- Returns:
- the collection of vertices which are connected to
edge
, ornull
ifedge
is not present
-
findEdge
Description copied from interface:Hypergraph
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 connectingv1
tov2
), 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 tov1
- either
v1
orv2
are not present in this graph
Note: for purposes of this method,
v1
is only considered to be connected tov2
via a given directed edgee
ifv1 == e.getSource() && v2 == e.getDest()
evaluates totrue
. (v1
andv2
are connected by an undirected edgeu
ifu
is incident to bothv1
andv2
.)- Specified by:
findEdge
in interfaceHypergraph<V,
H> - Parameters:
v1
- the first endpoint of the returned edgev2
- the second endpoint of the returned edge- Returns:
- an edge that connects
v1
tov2
, ornull
if no such edge exists (or either vertex is not present) - See Also:
-
findEdgeSet
Description copied from interface:Hypergraph
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 connectingv1
tov2
), any of these edges may be returned.findEdgeSet(v1, v2)
may be used to return all such edges. Returns null ifv2
is not connected tov1
.
Returns an empty collection if eitherv1
orv2
are not present in this graph.Note: for purposes of this method,
v1
is only considered to be connected tov2
via a given directed edged
ifv1 == d.getSource() && v2 == d.getDest()
evaluates totrue
. (v1
andv2
are connected by an undirected edgeu
ifu
is incident to bothv1
andv2
.)- Specified by:
findEdgeSet
in interfaceHypergraph<V,
H> - Parameters:
v1
- the first endpoint of the returned edge setv2
- the second endpoint of the returned edge set- Returns:
- a collection containing all edges that connect
v1
tov2
, ornull
if either vertex is not present - See Also:
-
addVertex
Description copied from interface:Hypergraph
Addsvertex
to this graph. Fails ifvertex
is null or already in the graph.- Specified by:
addVertex
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex to add- Returns:
true
if the add is successful, andfalse
otherwise
-
removeVertex
Description copied from interface:Hypergraph
Removesvertex
from this graph. As a side effect, removes any edgese
incident tovertex
if the removal ofvertex
would causee
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 graphvertex
isnull
- Specified by:
removeVertex
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex to remove- Returns:
true
if the removal is successful,false
otherwise
-
removeEdge
Description copied from interface:Hypergraph
Removesedge
from this graph. Fails ifedge
is null, or is otherwise not an element of this graph.- Specified by:
removeEdge
in interfaceHypergraph<V,
H> - Parameters:
hyperedge
- the edge to remove- Returns:
true
if the removal is successful,false
otherwise
-
isNeighbor
Description copied from interface:Hypergraph
Returnstrue
ifv1
andv2
share an incident edge. Equivalent togetNeighbors(v1).contains(v2)
.- Specified by:
isNeighbor
in interfaceHypergraph<V,
H> - Parameters:
v1
- the first vertex to testv2
- the second vertex to test- Returns:
true
ifv1
andv2
share an incident edge
-
isIncident
Description copied from interface:Hypergraph
Returnstrue
ifvertex
andedge
are incident to each other. Equivalent togetIncidentEdges(vertex).contains(edge)
and togetIncidentVertices(edge).contains(vertex)
.- Specified by:
isIncident
in interfaceHypergraph<V,
H> - Parameters:
vertex
- vertex to testedge
- edge to test- Returns:
true
ifvertex
andedge
are incident to each other
-
degree
Description copied from interface:Hypergraph
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()
.- Specified by:
degree
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex whose degree is to be returned- Returns:
- the degree of this node
- See Also:
-
getNeighborCount
Description copied from interface:Hypergraph
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()
.- Specified by:
getNeighborCount
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex whose neighbor count is to be returned- Returns:
- the number of neighboring vertices
-
getIncidentCount
Description copied from interface:Hypergraph
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()
.- Specified by:
getIncidentCount
in interfaceHypergraph<V,
H> - Parameters:
edge
- the edge whose incident vertex count is to be returned- Returns:
- the number of vertices that are incident to
edge
.
-
getEdgeCount
Description copied from interface:Hypergraph
Returns the number of edges of typeedge_type
in this graph.- Specified by:
getEdgeCount
in interfaceHypergraph<V,
H> - Parameters:
edge_type
- the type of edge for which the count is to be returned- Returns:
- the number of edges of type
edge_type
in this graph
-
getEdges
Description copied from interface:Hypergraph
Returns the collection of edges in this graph which are of typeedge_type
.- Specified by:
getEdges
in interfaceHypergraph<V,
H> - Parameters:
edge_type
- the type of edges to be returned- Returns:
- the collection of edges which are of type
edge_type
, ornull
if the graph does not accept edges of this type - See Also:
-
getDefaultEdgeType
Description copied from interface:Hypergraph
Returns the default edge type for this graph.- Specified by:
getDefaultEdgeType
in interfaceHypergraph<V,
H> - Returns:
- the default edge type for this graph
-
getInEdges
Description copied from interface:Hypergraph
Returns aCollection
view of the incoming edges incident tovertex
in this graph.- Specified by:
getInEdges
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex whose incoming edges are to be returned- Returns:
- a
Collection
view of the incoming edges incident tovertex
in this graph
-
getOutEdges
Description copied from interface:Hypergraph
Returns aCollection
view of the outgoing edges incident tovertex
in this graph.- Specified by:
getOutEdges
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex whose outgoing edges are to be returned- Returns:
- a
Collection
view of the outgoing edges incident tovertex
in this graph
-
inDegree
Description copied from interface:Hypergraph
Returns the number of incoming edges incident tovertex
. Equivalent togetInEdges(vertex).size()
.- Specified by:
inDegree
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex whose indegree is to be calculated- Returns:
- the number of incoming edges incident to
vertex
-
outDegree
Description copied from interface:Hypergraph
Returns the number of outgoing edges incident tovertex
. Equivalent togetOutEdges(vertex).size()
.- Specified by:
outDegree
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex whose outdegree is to be calculated- Returns:
- the number of outgoing edges incident to
vertex
-
getDest
Description copied from interface:Hypergraph
Ifdirected_edge
is a directed edge in this graph, returns the destination; otherwise returnsnull
. The destination of a directed edged
is defined to be the vertex incident tod
for whichd
is an incoming edge.directed_edge
is guaranteed to be a directed edge if itsEdgeType
isDIRECTED
.- Specified by:
getDest
in interfaceHypergraph<V,
H> - 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, ornull
otherwise
-
getSource
Description copied from interface:Hypergraph
Ifdirected_edge
is a directed edge in this graph, returns the source; otherwise returnsnull
. The source of a directed edged
is defined to be the vertex for whichd
is an outgoing edge.directed_edge
is guaranteed to be a directed edge if itsEdgeType
isDIRECTED
.- Specified by:
getSource
in interfaceHypergraph<V,
H> - 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, ornull
otherwise
-
getPredecessors
Description copied from interface:Hypergraph
Returns aCollection
view of the predecessors ofvertex
in this graph. A predecessor ofvertex
is defined as a vertexv
which is connected tovertex
by an edgee
, wheree
is an outgoing edge ofv
and an incoming edge ofvertex
.- Specified by:
getPredecessors
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex whose predecessors are to be returned- Returns:
- a
Collection
view of the predecessors ofvertex
in this graph
-
getSuccessors
Description copied from interface:Hypergraph
Returns aCollection
view of the successors ofvertex
in this graph. A successor ofvertex
is defined as a vertexv
which is connected tovertex
by an edgee
, wheree
is an incoming edge ofv
and an outgoing edge ofvertex
.- Specified by:
getSuccessors
in interfaceHypergraph<V,
H> - Parameters:
vertex
- the vertex whose predecessors are to be returned- Returns:
- a
Collection
view of the successors ofvertex
in this graph
-