Package edu.uci.ics.jung.graph
Class AbstractGraph<V,E>
java.lang.Object
edu.uci.ics.jung.graph.AbstractGraph<V,E>
- All Implemented Interfaces:
Graph<V,,E> Hypergraph<V,,E> Serializable
- Direct Known Subclasses:
AbstractTypedGraph,SparseGraph,SparseMultigraph
Abstract implementation of the
Graph interface.
Designed to simplify implementation of new graph classes.- Author:
- Joshua O'Madadhain
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAddsedgeto this graph with the specifiedendpoints, with the default edge type.abstract booleanAddsedgeto this graph with the specifiedendpointsandEdgeType.booleanaddEdge(E edge, Collection<? extends V> vertices) Addsedgeto this graph.booleanaddEdge(E edge, Collection<? extends V> vertices, EdgeType edgeType) Addsedgeto this graph with typeedge_type.booleanAdds edgeeto this graph such that it connects vertexv1tov2.booleanAdds edgeeto this graph such that it connects vertexv1tov2.intReturns 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.intgetIncidentCount(E edge) Returns the number of vertices that are incident toedge.getIncidentVertices(E edge) Returns the collection of vertices in this graph which are connected toedge.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).getOpposite(V vertex, E edge) Returns the vertex at the other end ofedgefromvertex.intgetPredecessorCount(V vertex) Returns the number of predecessors thatvertexhas in this graph.intgetSuccessorCount(V vertex) Returns the number of successors thatvertexhas in this graph.getValidatedEndpoints(E edge, Pair<? extends V> endpoints) intReturns 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.booleanisPredecessor(V v1, V v2) Returnstrueifv1is a predecessor ofv2in this graph.booleanisSuccessor(V v1, V v2) Returnstrueifv1is a successor ofv2in this graph.intReturns the number of outgoing edges incident tovertex.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface edu.uci.ics.jung.graph.Graph
getDest, getEndpoints, getInEdges, getOutEdges, getPredecessors, getSource, getSuccessors, isDest, isSourceMethods inherited from interface edu.uci.ics.jung.graph.Hypergraph
addVertex, containsEdge, containsVertex, getDefaultEdgeType, getEdgeCount, getEdgeCount, getEdges, getEdges, getEdgeType, getIncidentEdges, getNeighbors, getVertexCount, getVertices, removeEdge, removeVertex
-
Constructor Details
-
AbstractGraph
public AbstractGraph()
-
-
Method Details
-
addEdge
Description copied from interface:HypergraphAddsedgeto this graph. Fails under the following circumstances:edgeis already an element of the graph- either
edgeorverticesisnull verticeshas 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
- Specified by:
addEdgein interfaceHypergraph<V,E> - Parameters:
edge- the edge to addvertices- the vertices to which the edge will be connected- Returns:
trueif the add is successful, andfalseotherwise
-
addEdge
Description copied from interface:HypergraphAddsedgeto this graph with typeedge_type. Fails under the following circumstances:edgeis already an element of the graph- either
edgeorverticesisnull verticeshas 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
- Specified by:
addEdgein interfaceHypergraph<V,E> - Parameters:
edge- edge to add to this graphvertices- vertices which are to be connected by this edgeedgeType- type of edge to add- Returns:
trueif the add is successful, andfalseotherwise
-
addEdge
Description copied from interface:GraphAdds edgeeto this graph such that it connects vertexv1tov2. Equivalent toaddEdge(e, new Pair(v1, v2)). If this graph does not containv1,v2, or both, implementations may choose to either silently add the vertices to the graph or throw anIllegalArgumentException. If this graph assigns edge types to its edges, the edge type ofewill be the default for this graph. SeeHypergraph.addEdge()for a listing of possible reasons for failure. -
addEdge
Description copied from interface:GraphAdds edgeeto this graph such that it connects vertexv1tov2. Equivalent toaddEdge(e, new Pair(v1, v2)). If this graph does not containv1,v2, or both, implementations may choose to either silently add the vertices to the graph or throw anIllegalArgumentException. IfedgeTypeis not legal for this graph, this method will throwIllegalArgumentException. SeeHypergraph.addEdge()for a listing of possible reasons for failure. -
addEdge
Addsedgeto this graph with the specifiedendpoints, with the default edge type.- Parameters:
edge- the edge to be addedendpoints- the endpoints to be connected to this edge- Returns:
trueiff the graph was modified as a result of this call
-
addEdge
Addsedgeto this graph with the specifiedendpointsandEdgeType.- Parameters:
edge- the edge to be addedendpoints- the endpoints to be connected to this edgeedgeType- the type of edge to add- Returns:
- true iff the graph was modified as a result of this call
-
getValidatedEndpoints
-
inDegree
Description copied from interface:GraphReturns the number of incoming edges incident tovertex. Equivalent togetInEdges(vertex).size(). -
outDegree
Description copied from interface:GraphReturns the number of outgoing edges incident tovertex. Equivalent togetOutEdges(vertex).size(). -
isPredecessor
Description copied from interface:GraphReturnstrueifv1is a predecessor ofv2in this graph. Equivalent tov1.getPredecessors().contains(v2).- Specified by:
isPredecessorin interfaceGraph<V,E> - Parameters:
v1- the first vertex to be queriedv2- the second vertex to be queried- Returns:
trueifv1is a predecessor ofv2, and false otherwise.
-
isSuccessor
Description copied from interface:GraphReturnstrueifv1is a successor ofv2in this graph. Equivalent tov1.getSuccessors().contains(v2).- Specified by:
isSuccessorin interfaceGraph<V,E> - Parameters:
v1- the first vertex to be queriedv2- the second vertex to be queried- Returns:
trueifv1is a successor ofv2, and false otherwise.
-
getPredecessorCount
Description copied from interface:GraphReturns the number of predecessors thatvertexhas in this graph. Equivalent tovertex.getPredecessors().size().- Specified by:
getPredecessorCountin interfaceGraph<V,E> - Parameters:
vertex- the vertex whose predecessor count is to be returned- Returns:
- the number of predecessors that
vertexhas in this graph
-
getSuccessorCount
Description copied from interface:GraphReturns the number of successors thatvertexhas in this graph. Equivalent tovertex.getSuccessors().size().- Specified by:
getSuccessorCountin interfaceGraph<V,E> - Parameters:
vertex- the vertex whose successor count is to be returned- Returns:
- the number of successors that
vertexhas in this graph
-
isNeighbor
Description copied from interface:HypergraphReturnstrueifv1andv2share an incident edge. Equivalent togetNeighbors(v1).contains(v2).- Specified by:
isNeighborin interfaceHypergraph<V,E> - Parameters:
v1- the first vertex to testv2- the second vertex to test- Returns:
trueifv1andv2share an incident edge
-
isIncident
Description copied from interface:HypergraphReturnstrueifvertexandedgeare incident to each other. Equivalent togetIncidentEdges(vertex).contains(edge)and togetIncidentVertices(edge).contains(vertex).- Specified by:
isIncidentin interfaceHypergraph<V,E> - Parameters:
vertex- vertex to testedge- edge to test- Returns:
trueifvertexandedgeare incident to each other
-
getNeighborCount
Description copied from interface:HypergraphReturns 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:
getNeighborCountin interfaceHypergraph<V,E> - Parameters:
vertex- the vertex whose neighbor count is to be returned- Returns:
- the number of neighboring vertices
-
degree
Description copied from interface:HypergraphReturns 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:
degreein interfaceHypergraph<V,E> - Parameters:
vertex- the vertex whose degree is to be returned- Returns:
- the degree of this node
- See Also:
-
getIncidentCount
Description copied from interface:HypergraphReturns 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:
getIncidentCountin interfaceHypergraph<V,E> - Parameters:
edge- the edge whose incident vertex count is to be returned- Returns:
- the number of vertices that are incident to
edge.
-
getOpposite
Description copied from interface:GraphReturns the vertex at the other end ofedgefromvertex. (That is, returns the vertex incident toedgewhich is notvertex.)- Specified by:
getOppositein interfaceGraph<V,E> - Parameters:
vertex- the vertex to be queriededge- the edge to be queried- Returns:
- the vertex at the other end of
edgefromvertex
-
findEdge
Description copied from interface:HypergraphReturns 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 tov1- either
v1orv2are not present in this graph
Note: 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.)- Specified by:
findEdgein interfaceHypergraph<V,E> - Parameters:
v1- the first endpoint of the returned edgev2- the second endpoint of the returned edge- Returns:
- an edge that connects
v1tov2, ornullif no such edge exists (or either vertex is not present) - See Also:
-
findEdgeSet
Description copied from interface:HypergraphReturns 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.)- Specified by:
findEdgeSetin interfaceHypergraph<V,E> - 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
v1tov2, ornullif either vertex is not present - See Also:
-
getIncidentVertices
Description copied from interface:HypergraphReturns 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:
getIncidentVerticesin interfaceHypergraph<V,E> - Parameters:
edge- the edge whose incident vertices are to be returned- Returns:
- the collection of vertices which are connected to
edge, ornullifedgeis not present
-
toString
-