|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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>
public class UndirectedSparseMultigraph<V,E>
An implementation of UndirectedGraph
that is suitable for
sparse graphs and permits parallel edges.
Field Summary | |
---|---|
protected Map<E,Pair<V>> |
edges
|
protected Map<V,Set<E>> |
vertices
|
Fields inherited from class edu.uci.ics.jung.graph.AbstractTypedGraph |
---|
edge_type |
Constructor Summary | |
---|---|
UndirectedSparseMultigraph()
Creates a new instance. |
Method Summary | ||
---|---|---|
boolean |
addEdge(E edge,
Pair<? extends V> endpoints,
EdgeType edge_type)
Adds edge to this graph with the specified endpoints
and EdgeType . |
|
boolean |
addEdge(E edge,
V v1,
V v2,
EdgeType edgeType)
Adds edge e to this graph such that it connects
vertex v1 to v2 . |
|
boolean |
addVertex(V vertex)
Adds vertex to this graph. |
|
boolean |
containsEdge(E 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 . |
|
E |
findEdge(V v1,
V v2)
Returns an edge that connects this vertex to v . |
|
V |
getDest(E directed_edge)
If directed_edge is a directed edge in this graph, returns the destination;
otherwise returns null . |
|
int |
getEdgeCount()
Returns the number of edges in this graph. |
|
Collection<E> |
getEdges()
Returns a view of all edges in this graph. |
|
Pair<V> |
getEndpoints(E edge)
Returns the endpoints of edge as a Pair . |
|
static
|
getFactory()
Returns a Factory that creates an instance of this graph type. |
|
protected Collection<E> |
getIncident_internal(V vertex)
|
|
Collection<E> |
getIncidentEdges(V vertex)
Returns the collection of edges in this graph which are connected to vertex . |
|
Collection<E> |
getInEdges(V vertex)
Returns a Collection view of the incoming edges incident to vertex
in this graph. |
|
Collection<V> |
getNeighbors(V vertex)
Returns the collection of vertices which are connected to vertex
via any edges in this graph. |
|
Collection<E> |
getOutEdges(V vertex)
Returns a Collection view of the outgoing edges incident to vertex
in this graph. |
|
Collection<V> |
getPredecessors(V vertex)
Returns a Collection view of the predecessors of vertex
in this graph. |
|
V |
getSource(E directed_edge)
If directed_edge is a directed edge in this graph, returns the source;
otherwise returns null . |
|
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. |
|
Collection<V> |
getVertices()
Returns a view of all vertices in this graph. |
|
boolean |
isDest(V vertex,
E edge)
Returns true if vertex is the destination of edge . |
|
boolean |
isSource(V vertex,
E edge)
Returns true if vertex is the source of edge . |
|
boolean |
removeEdge(E edge)
Removes edge from this graph. |
|
boolean |
removeVertex(V vertex)
Removes vertex from this graph. |
Methods inherited from class edu.uci.ics.jung.graph.AbstractTypedGraph |
---|
getDefaultEdgeType, getEdgeCount, getEdges, getEdgeType, hasEqualEdgeType, validateEdgeType |
Methods inherited from class edu.uci.ics.jung.graph.AbstractGraph |
---|
addEdge, addEdge, addEdge, addEdge, degree, findEdgeSet, getIncidentCount, getIncidentVertices, getNeighborCount, getOpposite, getPredecessorCount, getSuccessorCount, getValidatedEndpoints, inDegree, isIncident, isNeighbor, isPredecessor, isSuccessor, outDegree, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface edu.uci.ics.jung.graph.Graph |
---|
addEdge, getOpposite, getPredecessorCount, getSuccessorCount, inDegree, isPredecessor, isSuccessor, outDegree |
Methods inherited from interface edu.uci.ics.jung.graph.Hypergraph |
---|
addEdge, addEdge, degree, findEdgeSet, getDefaultEdgeType, getEdgeCount, getEdges, getEdgeType, getIncidentCount, getIncidentVertices, getNeighborCount, isIncident, isNeighbor |
Field Detail |
---|
protected Map<V,Set<E>> vertices
protected Map<E,Pair<V>> edges
Constructor Detail |
---|
public UndirectedSparseMultigraph()
Method Detail |
---|
public static <V,E> org.apache.commons.collections15.Factory<UndirectedGraph<V,E>> getFactory()
Factory
that creates an instance of this graph type.
V
- the vertex type for the graph factoryE
- the edge type for the graph factorypublic Collection<E> getEdges()
Hypergraph
Collection
contract, and therefore makes no guarantees
about the ordering of the vertices within the set.
getEdges
in interface Hypergraph<V,E>
Collection
view of all edges in this graphpublic Collection<V> getVertices()
Hypergraph
Collection
contract, and therefore makes no guarantees
about the ordering of the vertices within the set.
getVertices
in interface Hypergraph<V,E>
Collection
view of all vertices in this graphpublic boolean containsVertex(V vertex)
Hypergraph
vertex
.
Equivalent to getVertices().contains(vertex)
.
containsVertex
in interface Hypergraph<V,E>
vertex
- the vertex whose presence is being queried
vertex
public boolean containsEdge(E edge)
Hypergraph
edge
.
Equivalent to getEdges().contains(edge)
.
containsEdge
in interface Hypergraph<V,E>
edge
- the edge whose presence is being queried
edge
protected Collection<E> getIncident_internal(V vertex)
public boolean addVertex(V vertex)
Hypergraph
vertex
to this graph.
Fails if vertex
is null or already in the graph.
addVertex
in interface Hypergraph<V,E>
vertex
- the vertex to add
true
if the add is successful, and false
otherwisepublic boolean removeVertex(V vertex)
Hypergraph
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
removeVertex
in interface Hypergraph<V,E>
vertex
- the vertex to remove
true
if the removal is successful, false
otherwisepublic boolean addEdge(E edge, V v1, V v2, EdgeType edgeType)
Graph
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.
addEdge
in interface Graph<V,E>
addEdge
in class AbstractGraph<V,E>
edge
- the edge to be addedv1
- the first vertex to be connectedv2
- the second vertex to be connectededgeType
- the type to be assigned to the edge
true
if the add is successful, false
otherwiseHypergraph.addEdge(Object, Collection)
,
Graph.addEdge(Object, Object, Object)
public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edge_type)
AbstractGraph
edge
to this graph with the specified endpoints
and EdgeType
.
addEdge
in class AbstractGraph<V,E>
true iff the graph was modified as a result of this callpublic boolean removeEdge(E edge)
Hypergraph
edge
from this graph.
Fails if edge
is null, or is otherwise not an element of this graph.
removeEdge
in interface Hypergraph<V,E>
edge
- the edge to remove
true
if the removal is successful, false
otherwisepublic Collection<E> getInEdges(V vertex)
Graph
Collection
view of the incoming edges incident to vertex
in this graph.
getInEdges
in interface Graph<V,E>
getInEdges
in interface Hypergraph<V,E>
vertex
- the vertex whose incoming edges are to be returned
Collection
view of the incoming edges incident
to vertex
in this graphpublic Collection<E> getOutEdges(V vertex)
Graph
Collection
view of the outgoing edges incident to vertex
in this graph.
getOutEdges
in interface Graph<V,E>
getOutEdges
in interface Hypergraph<V,E>
vertex
- the vertex whose outgoing edges are to be returned
Collection
view of the outgoing edges incident
to vertex
in this graphpublic Collection<V> getPredecessors(V vertex)
Graph
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
.
getPredecessors
in interface Graph<V,E>
getPredecessors
in interface Hypergraph<V,E>
vertex
- the vertex whose predecessors are to be returned
Collection
view of the predecessors of
vertex
in this graphpublic Collection<V> getSuccessors(V vertex)
Graph
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
.
getSuccessors
in interface Graph<V,E>
getSuccessors
in interface Hypergraph<V,E>
vertex
- the vertex whose predecessors are to be returned
Collection
view of the successors of
vertex
in this graphpublic Collection<V> getNeighbors(V vertex)
Hypergraph
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.
getNeighbors
in interface Hypergraph<V,E>
vertex
- the vertex whose neighbors are to be returned
vertex
,
or null
if vertex
is not presentpublic Collection<E> getIncidentEdges(V vertex)
Hypergraph
vertex
.
getIncidentEdges
in interface Hypergraph<V,E>
vertex
- the vertex whose incident edges are to be returned
vertex
,
or null
if vertex
is not presentpublic E findEdge(V v1, V v2)
Hypergraph
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
.)
findEdge
in interface Hypergraph<V,E>
findEdge
in class AbstractGraph<V,E>
v1
to v2
,
or null
if no such edge exists (or either vertex is not present)Hypergraph.findEdgeSet(Object, Object)
public Pair<V> getEndpoints(E edge)
Graph
edge
as a Pair
.
getEndpoints
in interface Graph<V,E>
edge
- the edge whose endpoints are to be returned
edge
public V getDest(E directed_edge)
Graph
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
.
getDest
in interface Graph<V,E>
getDest
in interface Hypergraph<V,E>
directed_edge
if it is a directed edge in this graph, or null
otherwisepublic V getSource(E directed_edge)
Graph
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
.
getSource
in interface Graph<V,E>
getSource
in interface Hypergraph<V,E>
directed_edge
if it is a directed edge in this graph, or null
otherwisepublic boolean isDest(V vertex, E edge)
Graph
true
if vertex
is the destination of edge
.
Equivalent to getDest(edge).equals(vertex)
.
isDest
in interface Graph<V,E>
vertex
- the vertex to be queriededge
- the edge to be queried
true
iff vertex
is the destination of edge
public boolean isSource(V vertex, E edge)
Graph
true
if vertex
is the source of edge
.
Equivalent to getSource(edge).equals(vertex)
.
isSource
in interface Graph<V,E>
vertex
- the vertex to be queriededge
- the edge to be queried
true
iff vertex
is the source of edge
public int getEdgeCount()
Hypergraph
getEdgeCount
in interface Hypergraph<V,E>
public int getVertexCount()
Hypergraph
getVertexCount
in interface Hypergraph<V,E>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |