public class SetHypergraph<V,H> extends java.lang.Object implements Hypergraph<V,H>, MultiGraph<V,H>, java.io.Serializable
Hypergraph that is suitable for sparse graphs and
permits parallel edges.| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<H,java.util.Set<V>> |
edges |
protected java.util.Map<V,java.util.Set<H>> |
vertices |
| Constructor and Description |
|---|
SetHypergraph()
Creates a
SetHypergraph and initializes the internal data structures. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addEdgeWithVertices(H hyperedge,
java.util.Collection<? extends V> to_attach)
Adds
hyperedge to this graph and connects them to the vertex collection to_attach. |
boolean |
addEdgeWithVertices(H hyperedge,
java.util.Collection<? extends V> to_attach,
EdgeType edge_type)
Adds
edge to this graph with type edge_type. |
boolean |
addVertex(V vertex)
Adds
vertex to this graph. |
boolean |
containsEdge(H edge)
Returns true if this graph's edge collection contains
edge. |
boolean |
containsVertex(V vertex)
Returns true if this graph's vertex collection contains
vertex. |
int |
degree(V vertex)
Returns the number of edges incident to
vertex. |
H |
findEdge(V v1,
V v2)
Returns an edge that connects this vertex to
v. |
java.util.Collection<H> |
findEdgeSet(V v1,
V v2)
Returns all edges that connects this vertex to
v. |
EdgeType |
getDefaultEdgeType()
Returns the default edge type for this graph.
|
V |
getDest(H directed_edge)
If
directedEdge is a directed edge in this graph, returns the destination, otherwise returns null. |
int |
getEdgeCount()
Returns the number of edges in this graph.
|
int |
getEdgeCount(EdgeType edge_type)
Returns the number of edges of type
edge_type in this graph. |
java.util.Collection<H> |
getEdges(EdgeType edge_type)
Returns the collection of edges in this graph which are of type
edge_type. |
java.util.Collection<H> |
getEdgesView()
Returns a view of all edges in this graph.
|
EdgeType |
getEdgeType(H edge)
Returns the edge type of
edge in this graph. |
static <V,H> Factory<Hypergraph<V,H>> |
getFactory()
Returns a
Factory which creates instances of this class. |
int |
getIncidentCount(H edge)
Returns the number of vertices that are incident to
edge. |
java.util.Collection<H> |
getIncidentEdges(V vertex)
Returns the collection of edges in this graph which are connected to
vertex. |
java.util.Collection<V> |
getIncidentVertices(H edge)
Returns the collection of vertices in this graph which are connected to
edge. |
java.util.Collection<H> |
getInEdges(V vertex)
Returns a
Collection view of the incoming edges incident to vertex in this graph. |
int |
getNeighborCount(V vertex)
Returns the number of vertices that are adjacent to
vertex (that is, the number of vertices that are incident
to edges in vertex's incident edge set). |
java.util.Collection<V> |
getNeighbors(V vertex)
Returns the collection of vertices which are connected to
vertex via any edges in this graph. |
java.util.Collection<H> |
getOutEdges(V vertex)
Returns a
Collection view of the outgoing edges incident to vertex in this graph. |
java.util.Collection<V> |
getPredecessors(V vertex)
Returns a
Collection view of the predecessors of vertex in this graph. |
V |
getSource(H directed_edge)
If
directedEdge is a directed edge in this graph, returns the source, otherwise returns null. |
java.util.Collection<V> |
getSuccessors(V vertex)
Returns a
Collection view of the successors of vertex in this graph. |
int |
getVertexCount()
Returns the number of vertices in this graph.
|
java.util.Collection<V> |
getVerticesView()
Returns a view of all vertices in this graph.
|
int |
inDegree(V vertex)
Returns the number of incoming edges incident to
vertex. |
boolean |
isIncident(V vertex,
H edge)
Returns
true if vertex and edge
are incident to each other. |
boolean |
isNeighbor(V v1,
V v2)
Returns
true if v1 and v2 share an incident edge. |
int |
outDegree(V vertex)
Returns the number of outgoing edges incident to
vertex. |
boolean |
removeEdge(H hyperedge)
Removes
edge from this graph. |
boolean |
removeVertex(V vertex)
Removes
vertex from this graph. |
public SetHypergraph()
SetHypergraph and initializes the internal data structures.public static <V,H> Factory<Hypergraph<V,H>> getFactory()
Factory which creates instances of this class.V - vertex type of the hypergraph to be createdH - edge type of the hypergraph to be createdFactory which creates instances of this classpublic boolean addEdgeWithVertices(H hyperedge, java.util.Collection<? extends V> to_attach)
hyperedge to this graph and connects them to the vertex collection to_attach.
Any vertices in to_attach that appear more than once will only appear once in the
incident vertex collection for hyperedge, that is, duplicates will be ignored.addEdgeWithVertices in interface Hypergraph<V,H>hyperedge - the edgeto_attach - the verticestrue if the add is successful, and false otherwiseHypergraph.addEdgeWithVertices(Object, Collection)public boolean addEdgeWithVertices(H hyperedge, java.util.Collection<? extends V> to_attach, EdgeType edge_type)
Hypergraphedge to this graph with type edge_type. Fails under the following circumstances:
edge is already an element of the graphedge or vertices is nullvertices 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 edgesedgeType is not legal for this graphaddEdgeWithVertices in interface Hypergraph<V,H>hyperedge - the edgeto_attach - the verticesedge_type - the edge typetrue if the add is successful, and false otherwiseHypergraph.addEdgeWithVertices(Object, Collection, EdgeType)public EdgeType getEdgeType(H edge)
Hypergraphedge in this graph.getEdgeType in interface Hypergraph<V,H>EdgeType of edge, or null if edge has no defined typeHypergraph.getEdgeType(Object)public boolean containsVertex(V vertex)
Hypergraphvertex. Equivalent to
getVertices().contains(vertex).containsVertex in interface Hypergraph<V,H>vertex - the vertex whose presence is being queriedvertexpublic boolean containsEdge(H edge)
Hypergraphedge.
Equivalent to getEdges().contains(edge).containsEdge in interface Hypergraph<V,H>edge - the edge whose presence is being queriededgepublic java.util.Collection<H> getEdgesView()
HypergraphCollection contract, and therefore
makes no guarantees about the ordering of the vertices within the set.getEdgesView in interface Hypergraph<V,H>Collection view of all edges in this graphpublic java.util.Collection<V> getVerticesView()
HypergraphCollection contract, and therefore makes no guarantees
about the ordering of the vertices within the set.getVerticesView in interface Hypergraph<V,H>Collection view of all vertices in this graphpublic int getEdgeCount()
HypergraphgetEdgeCount in interface Hypergraph<V,H>public int getVertexCount()
HypergraphgetVertexCount in interface Hypergraph<V,H>public java.util.Collection<V> getNeighbors(V vertex)
Hypergraphvertex 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.getNeighbors in interface Hypergraph<V,H>vertex - the vertex whose neighbors are to be returnedvertex,
or null if vertex is not presentpublic java.util.Collection<H> getIncidentEdges(V vertex)
Hypergraphvertex.getIncidentEdges in interface Hypergraph<V,H>vertex - the vertex whose incident edges are to be returnedvertex,
or null if vertex is not presentpublic java.util.Collection<V> getIncidentVertices(H edge)
Hypergraphedge.
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.getIncidentVertices in interface Hypergraph<V,H>edge - the edge whose incident vertices are to be returnededge,
or null if edge is not presentpublic H findEdge(V v1, V v2)
Hypergraphv. 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 v1v1 or v2 are not present in this graphv1 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.)findEdge in interface Hypergraph<V,H>v1 - the first vertexv2 - the second vertexv1 to v2, or null if no such edge exists (or either
vertex is not present)Hypergraph.findEdgeSet(Object, Object)public java.util.Collection<H> findEdgeSet(V v1, V v2)
Hypergraphv. 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 v2 is not connected to v1. Returns an empty collection if 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 d if
v1 == d.getSource() && v2 == d.getDest() evaluates to true.
(v1 and v2 are connected by an undirected edge u if
u is incident to both v1 and v2.)findEdgeSet in interface Hypergraph<V,H>v1 - the first vertexv2 - the second vertexv1 to v2,
or null if either vertex is not presentHypergraph.findEdge(Object, Object)public boolean addVertex(V vertex)
Hypergraphvertex to this graph. Fails if vertex is null or already in the graph.addVertex in interface Hypergraph<V,H>vertex - the vertex to addtrue if the add is successful, and false otherwisepublic boolean removeVertex(V vertex)
Hypergraphvertex 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 graphvertex is nullremoveVertex in interface Hypergraph<V,H>vertex - the vertex to removetrue if the removal is successful, false otherwisepublic boolean removeEdge(H hyperedge)
Hypergraphedge from this graph.
Fails if edge is null, or is otherwise not an element of this graph.removeEdge in interface Hypergraph<V,H>hyperedge - the edge to removetrue if the removal is successful, false otherwisepublic boolean isNeighbor(V v1, V v2)
Hypergraphtrue if v1 and v2 share an incident edge.
Equivalent to getNeighbors(v1).contains(v2).isNeighbor in interface Hypergraph<V,H>v1 - the first vertex to testv2 - the second vertex to testtrue if v1 and v2 share an incident edgepublic boolean isIncident(V vertex, H edge)
Hypergraphtrue if vertex and edge
are incident to each other.
Equivalent to getIncidentEdges(vertex).contains(edge) and to
getIncidentVertices(edge).contains(vertex).isIncident in interface Hypergraph<V,H>vertex - the vertexedge - the edgetrue if vertex and edge
are incident to each otherpublic int degree(V vertex)
Hypergraphvertex.
Special cases of interest:
getNeighborCount)getIncidentEdges(vertex).size().degree in interface Hypergraph<V,H>vertex - the vertex whose degree is to be returnedHypergraph.getNeighborCount(Object)public int getNeighborCount(V vertex)
Hypergraphvertex (that is, the number of vertices that are incident
to edges in vertex's incident edge set).
Equivalent to getNeighbors(vertex).size().getNeighborCount in interface Hypergraph<V,H>vertex - the vertex whose neighbor count is to be returnedpublic int getIncidentCount(H edge)
Hypergraphedge. 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().getIncidentCount in interface Hypergraph<V,H>edge - the edge whose incident vertex count is to be returnededge.public int getEdgeCount(EdgeType edge_type)
Hypergraphedge_type in this graph.getEdgeCount in interface Hypergraph<V,H>edge_type - the type of edge for which the count is to be returnededge_type in this graphpublic java.util.Collection<H> getEdges(EdgeType edge_type)
Hypergraphedge_type.getEdges in interface Hypergraph<V,H>edge_type - the type of edges to be returnededge_type, or
null if the graph does not accept edges of this typeEdgeTypepublic EdgeType getDefaultEdgeType()
HypergraphgetDefaultEdgeType in interface Hypergraph<V,H>public java.util.Collection<H> getInEdges(V vertex)
HypergraphCollection view of the incoming edges incident to vertex in this graph.getInEdges in interface Hypergraph<V,H>vertex - the vertex whose incoming edges are to be returnedCollection view of the incoming edges incident
to vertex in this graphpublic java.util.Collection<H> getOutEdges(V vertex)
HypergraphCollection view of the outgoing edges incident to vertex in this graph.getOutEdges in interface Hypergraph<V,H>vertex - the vertex whose outgoing edges are to be returnedCollection view of the outgoing edges incident
to vertex in this graphpublic int inDegree(V vertex)
Hypergraphvertex. Equivalent to getInEdges(vertex).size().inDegree in interface Hypergraph<V,H>vertex - the vertex whose indegree is to be calculatedvertexpublic int outDegree(V vertex)
Hypergraphvertex.
Equivalent to getOutEdges(vertex).size().outDegree in interface Hypergraph<V,H>vertex - the vertex whose outdegree is to be calculatedvertexpublic V getDest(H directed_edge)
HypergraphdirectedEdge 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.
directedEdge is guaranteed to be a directed edge if
its EdgeType is DIRECTED.getDest in interface Hypergraph<V,H>directed_edge - the edgedirected_edge if it is a directed edge in this graph, or null otherwisepublic V getSource(H directed_edge)
HypergraphdirectedEdge 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.
directedEdge is guaranteed to be a directed edge if its EdgeType is DIRECTED.getSource in interface Hypergraph<V,H>directed_edge - the edgedirected_edge if it is a directed edge in this graph, or null otherwisepublic java.util.Collection<V> getPredecessors(V vertex)
HypergraphCollection 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.getPredecessors in interface Hypergraph<V,H>vertex - the vertex whose predecessors are to be returnedCollection view of the predecessors of
vertex in this graphpublic java.util.Collection<V> getSuccessors(V vertex)
HypergraphCollection 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.getSuccessors in interface Hypergraph<V,H>vertex - the vertex whose predecessors are to be returnedCollection view of the successors of
vertex in this graphCopyright © 2021, 2022 Herve Girod. All Rights Reserved. Documentation and source under the BSD 3-Clause licence