org._3pq.jgrapht.graph

Class AsUndirectedGraph

Implemented Interfaces:
Serializable, Graph, Serializable, UndirectedGraph

public class AsUndirectedGraph
extends GraphDelegator
implements Serializable, UndirectedGraph

An undirected view of the backing directed graph specified in the constructor. This graph allows modules to apply algorithms designed for undirected graphs to a directed graph by simply ignoring edge direction. If the backing directed graph is an oriented graph, then the view will be a simple graph; otherwise, it will be a multigraph. Query operations on this graph "read through" to the backing graph. Attempts to add edges will result in an UnsupportedOperationException, but vertex addition/removal and edge removal are all supported (and immediately reflected in the backing graph).

Note that edges returned by this graph's accessors are really just the edges of the underlying directed graph. Since there is no interface distinction between directed and undirected edges, this detail should be irrelevant to algorithms.

This graph does not pass the hashCode and equals operations through to the backing graph, but relies on Object's equals and hashCode methods. This graph will be serializable if the backing graph is serializable.

Author:
John V. Sichi
Since:
Aug 14, 2003

Constructor Summary

AsUndirectedGraph(DirectedGraph g)
Constructor for AsUndirectedGraph.

Method Summary

boolean
addAllEdges(Collection edges)
Edge
addEdge(Object sourceVertex, Object targetVertex)
boolean
addEdge(Edge e)
int
degreeOf(Object vertex)
List
getAllEdges(Object sourceVertex, Object targetVertex)
Edge
getEdge(Object sourceVertex, Object targetVertex)
int
inDegreeOf(Object vertex)
List
incomingEdgesOf(Object vertex)
int
outDegreeOf(Object vertex)
List
outgoingEdgesOf(Object vertex)
String
toString()

Methods inherited from class org._3pq.jgrapht.graph.GraphDelegator

addEdge, addEdge, addVertex, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, inDegreeOf, incomingEdgesOf, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, toString, vertexSet

Methods inherited from class org._3pq.jgrapht.graph.AbstractGraph

addAllEdges, addAllVertices, assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets

Constructor Details

AsUndirectedGraph

public AsUndirectedGraph(DirectedGraph g)
Constructor for AsUndirectedGraph.
Parameters:
g - the backing directed graph over which an undirected view is to be created.

Method Details

addAllEdges

public boolean addAllEdges(Collection edges)
Specified by:
addAllEdges in interface Graph
Overrides:
addAllEdges in interface AbstractGraph

addEdge

public Edge addEdge(Object sourceVertex,
                    Object targetVertex)
Specified by:
addEdge in interface Graph
Overrides:
addEdge in interface GraphDelegator

addEdge

public boolean addEdge(Edge e)
Specified by:
addEdge in interface Graph
Overrides:
addEdge in interface GraphDelegator

degreeOf

public int degreeOf(Object vertex)
Specified by:
degreeOf in interface UndirectedGraph
Overrides:
degreeOf in interface GraphDelegator

getAllEdges

public List getAllEdges(Object sourceVertex,
                        Object targetVertex)
Specified by:
getAllEdges in interface Graph
Overrides:
getAllEdges in interface GraphDelegator

getEdge

public Edge getEdge(Object sourceVertex,
                    Object targetVertex)
Specified by:
getEdge in interface Graph
Overrides:
getEdge in interface GraphDelegator

inDegreeOf

public int inDegreeOf(Object vertex)
Overrides:
inDegreeOf in interface GraphDelegator

incomingEdgesOf

public List incomingEdgesOf(Object vertex)
Overrides:
incomingEdgesOf in interface GraphDelegator

outDegreeOf

public int outDegreeOf(Object vertex)
Overrides:
outDegreeOf in interface GraphDelegator

outgoingEdgesOf

public List outgoingEdgesOf(Object vertex)
Overrides:
outgoingEdgesOf in interface GraphDelegator

toString

public String toString()
Overrides:
toString in interface GraphDelegator