|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--Opus5.AbstractObject
|
+--Opus5.AbstractContainer
|
+--Opus5.AbstractGraph
The AbstractGraph class is the base class
from which all concrete undirected and directed graph classes are derived.
This abstract class provides default implementations
for various methods declared in the Graph
and the Digraph interfaces.
Graph,
Digraph| Inner Class Summary | |
protected static class |
AbstractGraph.Counter
A counter object. |
protected class |
AbstractGraph.GraphEdge
Represents an edge in this graph. |
protected class |
AbstractGraph.GraphVertex
Represents a vertex in this graph. |
| Field Summary | |
protected int |
numberOfEdges
The number of edges in this graph. |
protected int |
numberOfVertices
The number of vertices in this graph. |
protected Vertex[] |
vertex
The vertices. |
| Fields inherited from class Opus5.AbstractContainer |
count |
| Fields inherited from interface Opus5.Graph |
copyright |
| Constructor Summary | |
AbstractGraph(int size)
Constructs an AbstractGraph with the specified size. |
|
| Method Summary | |
void |
accept(Visitor visitor)
Accepts a visitor and makes it visit the vertices in this graph. |
protected abstract void |
addEdge(Edge edge)
Adds an edge to this graph. |
void |
addEdge(int v,
int w)
Adds an edge to this graph that connects the specified vertices. |
void |
addEdge(int v,
int w,
java.lang.Object weight)
Adds an edge to this graph that connects the specified vertices and has the specified weight. |
void |
addVertex(int v)
Adds a vertex to this graph with the specified number. |
void |
addVertex(int v,
java.lang.Object weight)
Adds a vertex to this graph with the specified number and weight. |
protected void |
addVertex(Vertex v)
Adds the specified vertex to this graph. |
void |
breadthFirstTraversal(Visitor visitor,
int start)
Causes a visitor to visit the vertices of this directed graph in breadth-first traversal order starting from a given vertex. |
void |
depthFirstTraversal(PrePostVisitor visitor,
int start)
Causes a visitor to visit the vertices of this graph in depth-first traversal order starting from a given vertex. |
protected abstract Enumeration |
getEmanatingEdges(int v)
Returns an enumeration that enumerates the edges that emanate from the specified vertex. |
Enumeration |
getEnumeration()
Returns an enumeration that enumerates the vertices in this graph. |
protected abstract Enumeration |
getIncidentEdges(int v)
Returns an enumeration that enumerates the edges incident upon the specified vertex. |
int |
getNumberOfEdges()
Returns the number of edges in this graph. |
int |
getNumberOfVertices()
Returns the number of vertices in this graph. |
Vertex |
getVertex(int v)
Returns the vertex with the specified vertex number. |
Enumeration |
getVertices()
Returns an enumeration that enumerates the vertices in this graph. |
boolean |
isConnected()
Tests whether this graph is connected. |
boolean |
isCyclic()
Tests whether this graph is cyclic. |
boolean |
isDirected()
Tests whether this graph is a directed graph. |
boolean |
isStronglyConnected()
Tests whether this graph is strongly connected. |
void |
purge()
Purges the vertices from this graph. |
void |
topologicalOrderTraversal(Visitor visitor)
Causes a visitor to visit the vertices of this graph in topological order. |
java.lang.String |
toString()
Returns a string representation of this graph. |
| Methods inherited from class Opus5.AbstractContainer |
getCount, hashCode, isEmpty, isFull |
| Methods inherited from class Opus5.AbstractObject |
compare, compareTo, equals, isEQ, isGE, isGT, isLE, isLT, isNE |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface Opus5.Graph |
getEdge, getEdges, isEdge |
| Methods inherited from interface Opus5.Container |
getCount, isEmpty, isFull |
| Methods inherited from interface Opus5.Comparable |
compare, isEQ, isGE, isGT, isLE, isLT, isNE |
| Field Detail |
protected int numberOfVertices
protected int numberOfEdges
protected Vertex[] vertex
| Constructor Detail |
public AbstractGraph(int size)
AbstractGraph with the specified size.size - The maximum number of vertices.| Method Detail |
public void purge()
purge in interface Containerprotected void addVertex(Vertex v)
v - The vertex to add.java.lang.IllegalArgumentException - If the number of the vertex is not the next number in sequence.
public final void addVertex(int v,
java.lang.Object weight)
addVertex in interface Graphv - The number of the vertex to be added.weight - The weight to be associated with this vertex.public final void addVertex(int v)
addVertex in interface Graphv - The number of the vertex to be added.public Vertex getVertex(int v)
getVertex in interface Graphv - The vertex number.public Enumeration getVertices()
getVertices in interface Graphprotected abstract Enumeration getIncidentEdges(int v)
v - The number of the specified vertex.protected abstract Enumeration getEmanatingEdges(int v)
v - The number of the specified vertex.protected abstract void addEdge(Edge edge)
edge - The edge to be added to this graph.public boolean isDirected()
Digraph interface.isDirected in interface Graph
public final void addEdge(int v,
int w,
java.lang.Object weight)
addEdge (new GraphEdge (v, w, weight));
addEdge in interface Graphv - The number of the vertex from which the edge emanates.w - The number of the vertex upon which the edge is incident.weight - The weight associated with the edge.
Implemented
public final void addEdge(int v,
int w)
addEdge (v, w, null);
addEdge in interface Graphv - The number of the vertex from which the edge emanates.w - The number of the vertex upon which the edge is incident.weight - The weight associated with the edge.
Implementedpublic int getNumberOfVertices()
getNumberOfVertices in interface Graphpublic int getNumberOfEdges()
getNumberOfEdges in interface Graphpublic void accept(Visitor visitor)
accept in interface Containeraccept in class AbstractContainervisitor - The visitor to accept.
public void depthFirstTraversal(PrePostVisitor visitor,
int start)
preVisit
and postVisit methods of the visitor
for each vertex in this graph.
The default implementation is recursive.
The default implementation never invokes
the inVisit method of the visitor.
The traversal continues as long as the isDone
method of the visitor returns false.depthFirstTraversal in interface Graphvisitor - The visitor to accept.start - The vertex at which to start the traversal.PrePostVisitor
public void breadthFirstTraversal(Visitor visitor,
int start)
visit method of the visitor
for each vertex in this graph.
The default implementation is iterative and uses a queue
to keep track of the vertices to be visited.
The traversal continues as long as the isDone
method of the visitor returns false.breadthFirstTraversal in interface Graphvisitor - The visitor to accept.start - The vertex at which to start the traversal.Visitorpublic void topologicalOrderTraversal(Visitor visitor)
visitor - The visitor to accept.Visitorpublic java.lang.String toString()
toString in class AbstractContainerpublic boolean isConnected()
isConnected in interface Graphpublic boolean isStronglyConnected()
Graph.isConnected()public boolean isCyclic()
isCyclic in interface Graphpublic Enumeration getEnumeration()
getEnumeration in interface Containerreturn getVertices ();
getVertices()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||