edu.uci.ics.jung.graph
Class AbstractGraph<V,E>

java.lang.Object
  extended by edu.uci.ics.jung.graph.AbstractGraph<V,E>
All Implemented Interfaces:
Graph<V,E>, Hypergraph<V,E>
Direct Known Subclasses:
AbstractTypedGraph, SparseGraph, SparseMultigraph

public abstract class AbstractGraph<V,E>
extends Object
implements Graph<V,E>

Abstract implementation of the Graph interface. Designed to simplify implementation of new graph classes.

Author:
Joshua O'Madadhain

Constructor Summary
AbstractGraph()
           
 
Method Summary
 boolean addEdge(E edge, Collection<? extends V> vertices)
          Adds edge to this graph.
 boolean addEdge(E edge, Collection<? extends V> vertices, EdgeType edgeType)
          Adds edge to this graph with type edge_type.
 boolean addEdge(E edge, Pair<? extends V> endpoints)
          Adds edge to this graph with the specified endpoints, with the default edge type.
abstract  boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType)
          Adds edge to this graph with the specified endpoints and EdgeType.
 boolean addEdge(E e, V v1, V v2)
          Adds edge e to this graph such that it connects vertex v1 to v2.
 boolean addEdge(E e, V v1, V v2, EdgeType edge_type)
          Adds edge e to this graph such that it connects vertex v1 to v2.
 int degree(V vertex)
          Returns the number of edges incident to vertex.
 E findEdge(V v1, V v2)
          Returns an edge that connects this vertex to v.
 Collection<E> findEdgeSet(V v1, V v2)
          Returns all edges that connects this vertex to v.
 int getIncidentCount(E edge)
          Returns the number of vertices that are incident to edge.
 Collection<V> getIncidentVertices(E edge)
          Returns the collection of vertices in this graph which are connected to edge.
 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).
 V getOpposite(V vertex, E edge)
          Returns the vertex at the other end of edge from vertex.
 int getPredecessorCount(V vertex)
          Returns the number of predecessors that vertex has in this graph.
 int getSuccessorCount(V vertex)
          Returns the number of successors that vertex has in this graph.
protected  Pair<V> getValidatedEndpoints(E edge, Pair<? extends V> endpoints)
           
 int inDegree(V vertex)
          Returns the number of incoming edges incident to vertex.
 boolean isIncident(V vertex, E 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.
 boolean isPredecessor(V v1, V v2)
          Returns true if v1 is a predecessor of v2 in this graph.
 boolean isSuccessor(V v1, V v2)
          Returns true if v1 is a successor of v2 in this graph.
 int outDegree(V vertex)
          Returns the number of outgoing edges incident to vertex.
 String 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
getDest, getEndpoints, getInEdges, getOutEdges, getPredecessors, getSource, getSuccessors, isDest, isSource
 
Methods 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 Detail

AbstractGraph

public AbstractGraph()
Method Detail

addEdge

public boolean addEdge(E edge,
                       Collection<? extends V> vertices)
Description copied from interface: Hypergraph
Adds edge to this graph. Fails under the following circumstances:

Specified by:
addEdge in interface Hypergraph<V,E>
Returns:
true if the add is successful, and false otherwise

addEdge

public boolean addEdge(E edge,
                       Collection<? extends V> vertices,
                       EdgeType edgeType)
Description copied from interface: Hypergraph
Adds edge to this graph with type edge_type. Fails under the following circumstances:

Specified by:
addEdge in interface Hypergraph<V,E>
Returns:
true if the add is successful, and false otherwise

addEdge

public boolean addEdge(E e,
                       V v1,
                       V v2)
Description copied from interface: Graph
Adds edge 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 this graph assigns edge types to its edges, the edge type of e will be the default for this graph. See Hypergraph.addEdge() for a listing of possible reasons for failure.

Specified by:
addEdge in interface Graph<V,E>
Parameters:
e - the edge to be added
v1 - the first vertex to be connected
v2 - the second vertex to be connected
Returns:
true if the add is successful, false otherwise
See Also:
Hypergraph.addEdge(Object, Collection), Graph.addEdge(Object, Object, Object, EdgeType)

addEdge

public boolean addEdge(E e,
                       V v1,
                       V v2,
                       EdgeType edge_type)
Description copied from interface: Graph
Adds edge 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.

Specified by:
addEdge in interface Graph<V,E>
Parameters:
e - the edge to be added
v1 - the first vertex to be connected
v2 - the second vertex to be connected
edge_type - the type to be assigned to the edge
Returns:
true if the add is successful, false otherwise
See Also:
Hypergraph.addEdge(Object, Collection), Graph.addEdge(Object, Object, Object)

addEdge

public boolean addEdge(E edge,
                       Pair<? extends V> endpoints)
Adds edge to this graph with the specified endpoints, with the default edge type.

Returns:
true iff the graph was modified as a result of this call

addEdge

public abstract boolean addEdge(E edge,
                                Pair<? extends V> endpoints,
                                EdgeType edgeType)
Adds edge to this graph with the specified endpoints and EdgeType.

Returns:
true iff the graph was modified as a result of this call

getValidatedEndpoints

protected Pair<V> getValidatedEndpoints(E edge,
                                        Pair<? extends V> endpoints)

inDegree

public int inDegree(V vertex)
Description copied from interface: Graph
Returns the number of incoming edges incident to vertex. Equivalent to getInEdges(vertex).size().

Specified by:
inDegree in interface Graph<V,E>
Specified by:
inDegree in interface Hypergraph<V,E>
Parameters:
vertex - the vertex whose indegree is to be calculated
Returns:
the number of incoming edges incident to vertex

outDegree

public int outDegree(V vertex)
Description copied from interface: Graph
Returns the number of outgoing edges incident to vertex. Equivalent to getOutEdges(vertex).size().

Specified by:
outDegree in interface Graph<V,E>
Specified by:
outDegree in interface Hypergraph<V,E>
Parameters:
vertex - the vertex whose outdegree is to be calculated
Returns:
the number of outgoing edges incident to vertex

isPredecessor

public boolean isPredecessor(V v1,
                             V v2)
Description copied from interface: Graph
Returns true if v1 is a predecessor of v2 in this graph. Equivalent to v1.getPredecessors().contains(v2).

Specified by:
isPredecessor in interface Graph<V,E>
Parameters:
v1 - the first vertex to be queried
v2 - the second vertex to be queried
Returns:
true if v1 is a predecessor of v2, and false otherwise.

isSuccessor

public boolean isSuccessor(V v1,
                           V v2)
Description copied from interface: Graph
Returns true if v1 is a successor of v2 in this graph. Equivalent to v1.getSuccessors().contains(v2).

Specified by:
isSuccessor in interface Graph<V,E>
Parameters:
v1 - the first vertex to be queried
v2 - the second vertex to be queried
Returns:
true if v1 is a successor of v2, and false otherwise.

getPredecessorCount

public int getPredecessorCount(V vertex)
Description copied from interface: Graph
Returns the number of predecessors that vertex has in this graph. Equivalent to vertex.getPredecessors().size().

Specified by:
getPredecessorCount in interface Graph<V,E>
Parameters:
vertex - the vertex whose predecessor count is to be returned
Returns:
the number of predecessors that vertex has in this graph

getSuccessorCount

public int getSuccessorCount(V vertex)
Description copied from interface: Graph
Returns the number of successors that vertex has in this graph. Equivalent to vertex.getSuccessors().size().

Specified by:
getSuccessorCount in interface Graph<V,E>
Parameters:
vertex - the vertex whose successor count is to be returned
Returns:
the number of successors that vertex has in this graph

isNeighbor

public boolean isNeighbor(V v1,
                          V v2)
Description copied from interface: Hypergraph
Returns true if v1 and v2 share an incident edge. Equivalent to getNeighbors(v1).contains(v2).

Specified by:
isNeighbor in interface Hypergraph<V,E>
Parameters:
v1 - the first vertex to test
v2 - the second vertex to test
Returns:
true if v1 and v2 share an incident edge

isIncident

public boolean isIncident(V vertex,
                          E edge)
Description copied from interface: Hypergraph
Returns true if vertex and edge are incident to each other. Equivalent to getIncidentEdges(vertex).contains(edge) and to getIncidentVertices(edge).contains(vertex).

Specified by:
isIncident in interface Hypergraph<V,E>
Returns:
true if vertex and edge are incident to each other

getNeighborCount

public int getNeighborCount(V vertex)
Description copied from interface: Hypergraph
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).

Equivalent to getNeighbors(vertex).size().

Specified by:
getNeighborCount in interface Hypergraph<V,E>
Parameters:
vertex - the vertex whose neighbor count is to be returned
Returns:
the number of neighboring vertices

degree

public int degree(V vertex)
Description copied from interface: Hypergraph
Returns the number of edges incident to vertex. Special cases of interest:

Equivalent to getIncidentEdges(vertex).size().

Specified by:
degree in interface Hypergraph<V,E>
Parameters:
vertex - the vertex whose degree is to be returned
Returns:
the degree of this node
See Also:
Hypergraph.getNeighborCount(Object)

getIncidentCount

public int getIncidentCount(E edge)
Description copied from interface: Hypergraph
Returns the number of vertices that are incident to edge. 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 interface Hypergraph<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

public V getOpposite(V vertex,
                     E edge)
Description copied from interface: Graph
Returns the vertex at the other end of edge from vertex. (That is, returns the vertex incident to edge which is not vertex.)

Specified by:
getOpposite in interface Graph<V,E>
Parameters:
vertex - the vertex to be queried
edge - the edge to be queried
Returns:
the vertex at the other end of edge from vertex

findEdge

public E findEdge(V v1,
                  V v2)
Description copied from interface: Hypergraph
Returns an edge that connects this vertex to 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:

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.)

Specified by:
findEdge in interface Hypergraph<V,E>
Returns:
an edge that connects v1 to v2, or null if no such edge exists (or either vertex is not present)
See Also:
Hypergraph.findEdgeSet(Object, Object)

findEdgeSet

public Collection<E> findEdgeSet(V v1,
                                 V v2)
Description copied from interface: Hypergraph
Returns all edges that connects this vertex to 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 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.)

Specified by:
findEdgeSet in interface Hypergraph<V,E>
Returns:
a collection containing all edges that connect v1 to v2, or null if either vertex is not present
See Also:
Hypergraph.findEdge(Object, Object)

getIncidentVertices

public Collection<V> getIncidentVertices(E edge)
Description copied from interface: Hypergraph
Returns the collection of vertices in this graph which are connected to edge. 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 interface Hypergraph<V,E>
Parameters:
edge - the edge whose incident vertices are to be returned
Returns:
the collection of vertices which are connected to edge, or null if edge is not present

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009. All Rights Reserved.