Package edu.uci.ics.jung.graph
Interface Graph<V,E>
-
- All Superinterfaces:
Hypergraph<V,E>
- All Known Subinterfaces:
DirectedGraph<V,E>,Forest<V,E>,KPartiteGraph<V,E>,Tree<V,E>,UndirectedGraph<V,E>
- All Known Implementing Classes:
GraphDecorator,ObservableGraph
public interface Graph<V,E> extends Hypergraph<V,E>
A graph consisting of a set of vertices of typeVset and a set of edges of typeE. Edges of this graph type have exactly two endpoints; whether these endpoints must be distinct depends on the implementation.This interface permits, but does not enforce, any of the following common variations of graphs:
- directed and undirected edges
- vertices and edges with attributes (for example, weighted edges)
- vertices and edges of different types (for example, bipartite or multimodal graphs)
- parallel edges (multiple edges which connect a single set of vertices)
- representations as matrices or as adjacency lists or adjacency maps
Definitions (with respect to a given vertex
v):-
incoming edge of
v: an edge that can be traversed from a neighbor ofvto reachvoutgoing edge ofv: an edge that can be traversed fromvto reach some neighbor ofvpredecessor ofv: a vertex at the other end of an incoming edge ofvsuccessor ofv: a vertex at the other end of an outgoing edge ofv
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanaddEdge(E e, V v1, V v2)Adds edgeeto this graph such that it connects vertexv1tov2.booleanaddEdge(E e, V v1, V v2, EdgeType edgeType)Adds edgeeto this graph such that it connects vertexv1tov2.VgetDest(E directed_edge)Ifdirected_edgeis a directed edge in this graph, returns the destination; otherwise returnsnull.Pair<V>getEndpoints(E edge)Returns the endpoints ofedgeas aPair.java.util.Collection<E>getInEdges(V vertex)Returns aCollectionview of the incoming edges incident tovertexin this graph.VgetOpposite(V vertex, E edge)Returns the vertex at the other end ofedgefromvertex.java.util.Collection<E>getOutEdges(V vertex)Returns aCollectionview of the outgoing edges incident tovertexin this graph.intgetPredecessorCount(V vertex)Returns the number of predecessors thatvertexhas in 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.intgetSuccessorCount(V vertex)Returns the number of successors thatvertexhas in this graph.java.util.Collection<V>getSuccessors(V vertex)Returns aCollectionview of the successors ofvertexin this graph.intinDegree(V vertex)Returns the number of incoming edges incident tovertex.booleanisDest(V vertex, E edge)Returnstrueifvertexis the destination ofedge.booleanisPredecessor(V v1, V v2)Returnstrueifv1is a predecessor ofv2in this graph.booleanisSource(V vertex, E edge)Returnstrueifvertexis the source ofedge.booleanisSuccessor(V v1, V v2)Returnstrueifv1is a successor ofv2in this graph.intoutDegree(V vertex)Returns the number of outgoing edges incident tovertex.-
Methods inherited from interface edu.uci.ics.jung.graph.Hypergraph
addEdge, addEdge, addVertex, containsEdge, containsVertex, degree, findEdge, findEdgeSet, getDefaultEdgeType, getEdgeCount, getEdgeCount, getEdges, getEdges, getEdgeType, getIncidentCount, getIncidentEdges, getIncidentVertices, getNeighborCount, getNeighbors, getVertexCount, getVertices, isIncident, isNeighbor, removeEdge, removeVertex
-
-
-
-
Method Detail
-
getInEdges
java.util.Collection<E> getInEdges(V vertex)
Returns aCollectionview of the incoming edges incident tovertexin this graph.- Specified by:
getInEdgesin interfaceHypergraph<V,E>- 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.- Specified by:
getOutEdgesin interfaceHypergraph<V,E>- Parameters:
vertex- the vertex whose outgoing edges are to be returned- Returns:
- a
Collectionview of the outgoing edges incident tovertexin this graph
-
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.- Specified by:
getPredecessorsin interfaceHypergraph<V,E>- 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.- Specified by:
getSuccessorsin interfaceHypergraph<V,E>- Parameters:
vertex- the vertex whose predecessors are to be returned- Returns:
- a
Collectionview of the successors ofvertexin this graph
-
inDegree
int inDegree(V vertex)
Returns the number of incoming edges incident tovertex. Equivalent togetInEdges(vertex).size().- Specified by:
inDegreein interfaceHypergraph<V,E>- 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().- Specified by:
outDegreein interfaceHypergraph<V,E>- Parameters:
vertex- the vertex whose outdegree is to be calculated- Returns:
- the number of outgoing edges incident to
vertex
-
isPredecessor
boolean isPredecessor(V v1, V v2)
Returnstrueifv1is a predecessor ofv2in this graph. Equivalent tov1.getPredecessors().contains(v2).- Parameters:
v1- the first vertex to be queriedv2- the second vertex to be queried- Returns:
trueifv1is a predecessor ofv2, and false otherwise.
-
isSuccessor
boolean isSuccessor(V v1, V v2)
Returnstrueifv1is a successor ofv2in this graph. Equivalent tov1.getSuccessors().contains(v2).- Parameters:
v1- the first vertex to be queriedv2- the second vertex to be queried- Returns:
trueifv1is a successor ofv2, and false otherwise.
-
getPredecessorCount
int getPredecessorCount(V vertex)
Returns the number of predecessors thatvertexhas in this graph. Equivalent tovertex.getPredecessors().size().- Parameters:
vertex- the vertex whose predecessor count is to be returned- Returns:
- the number of predecessors that
vertexhas in this graph
-
getSuccessorCount
int getSuccessorCount(V vertex)
Returns the number of successors thatvertexhas in this graph. Equivalent tovertex.getSuccessors().size().- Parameters:
vertex- the vertex whose successor count is to be returned- Returns:
- the number of successors that
vertexhas in this graph
-
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.- Specified by:
getSourcein interfaceHypergraph<V,E>- 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.- Specified by:
getDestin interfaceHypergraph<V,E>- Parameters:
directed_edge-- Returns:
- the destination of
directed_edgeif it is a directed edge in this graph, ornullotherwise
-
isSource
boolean isSource(V vertex, E edge)
Returnstrueifvertexis the source ofedge. Equivalent togetSource(edge).equals(vertex).- Parameters:
vertex- the vertex to be queriededge- the edge to be queried- Returns:
trueiffvertexis the source ofedge
-
isDest
boolean isDest(V vertex, E edge)
Returnstrueifvertexis the destination ofedge. Equivalent togetDest(edge).equals(vertex).- Parameters:
vertex- the vertex to be queriededge- the edge to be queried- Returns:
trueiffvertexis the destination ofedge
-
addEdge
boolean addEdge(E e, V v1, V v2)
Adds edgeeto this graph such that it connects vertexv1tov2. Equivalent toaddEdge(e, new Pair. If this graph does not contain(v1, v2)) v1,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.- Parameters:
e- the edge to be addedv1- the first vertex to be connectedv2- the second vertex to be connected- Returns:
trueif the add is successful,falseotherwise- See Also:
Hypergraph.addEdge(Object, Collection),addEdge(Object, Object, Object, EdgeType)
-
addEdge
boolean addEdge(E e, V v1, V v2, EdgeType edgeType)
Adds edgeeto this graph such that it connects vertexv1tov2. Equivalent toaddEdge(e, new Pair. If this graph does not contain(v1, v2)) v1,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.- Parameters:
e- 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- Returns:
trueif the add is successful,falseotherwise- See Also:
Hypergraph.addEdge(Object, Collection),addEdge(Object, Object, Object)
-
getEndpoints
Pair<V> getEndpoints(E edge)
Returns the endpoints ofedgeas aPair.- Parameters:
edge- the edge whose endpoints are to be returned- Returns:
- the endpoints (incident vertices) of
edge
-
getOpposite
V getOpposite(V vertex, E edge)
Returns the vertex at the other end ofedgefromvertex. (That is, returns the vertex incident toedgewhich is notvertex.)- Parameters:
vertex- the vertex to be queriededge- the edge to be queried- Returns:
- the vertex at the other end of
edgefromvertex
-
-