|
© 1998-2002 McGraw-Hill | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--structure.AbstractStructure
|
+--structure.GraphMatrix
Implementation of graph using adjacency matrices. User must commit to maximum size of graph (in vertices); it may be smaller. Edges are stored in matrix. Not suitable for large graphs. Class is abstract: you must use GraphMatrixDirected or GraphMatrixUndirected to construct particular instances of graphs. Typical usage:
Graph g = new GraphMatrixUndirected();
g.add("harry");
g.add("sally");
g.addEdge("harry","sally","unfriendly");
...
GraphMatrixDirected,
GraphMatrixUndirected,
GraphList| Field Summary | |
protected Edge[][] |
data
The edge data. |
protected Map |
dict
Translation between vertex labels and vertex structures. |
protected boolean |
directed
Whether or not graph is directed. |
protected List |
freeList
List of free vertex indices within graph. |
protected int |
size
Number of vertices in graph. |
| Constructor Summary | |
protected |
GraphMatrix(int size,
boolean dir)
Constructor of directed/undirected GraphMatrix. |
| Method Summary | |
void |
add(Object label)
Add a vertex to the graph. |
abstract void |
addEdge(Object v1,
Object v2,
Object label)
Add an edge between two vertices within the graph. |
void |
clear()
Remove all vertices (and thus, edges) of the graph. |
boolean |
contains(Object label)
Test for vertex membership. |
boolean |
containsEdge(Object vLabel1,
Object vLabel2)
Test for edge membership. |
int |
degree(Object label)
Determine out degree of vertex. |
abstract int |
edgeCount()
Determine the number of edges in graph. |
abstract Iterator |
edges()
Construct an traversal over all edges. |
Object |
get(Object label)
Get reference to actual label of vertex. |
Edge |
getEdge(Object label1,
Object label2)
Get reference to actual edge. |
boolean |
isDirected()
Determine if graph is directed. |
boolean |
isEmpty()
Determine if graph is empty. |
boolean |
isVisited(Object label)
Return visited flag of vertex. |
boolean |
isVisitedEdge(Edge e)
Return visited flag of edge. |
Iterator |
iterator()
Construct vertex traversal. |
Iterator |
neighbors(Object label)
Construct an adjacent vertex traversal. |
Object |
remove(Object label)
Remove a vertex from the graph. |
abstract Object |
removeEdge(Object vLabel1,
Object vLabel2)
Remove possible edge between vertices labeled vLabel1 and vLabel2. |
void |
reset()
Clear visited flags of edges and vertices. |
int |
size()
Determine number of vertices within graph. |
boolean |
visit(Object label)
Test and set visited flag of vertex. |
boolean |
visitEdge(Edge e)
Test and set visited flag of edge. |
| Methods inherited from class structure.AbstractStructure |
elements, hashCode, values |
| Methods inherited from class java.lang.Object |
|
| Methods inherited from interface structure.Structure |
elements, values |
| Field Detail |
protected int size
protected Edge[][] data
protected Map dict
protected List freeList
protected boolean directed
| Constructor Detail |
protected GraphMatrix(int size,
boolean dir)
size - Maximum size of graph.dir - True if graph is to be directed.| Method Detail |
public void add(Object label)
add in interface Graphlabel - Label of the vertex; should be non-null.
public abstract void addEdge(Object v1,
Object v2,
Object label)
addEdge in interface Graphvtx1 - First (or source, if directed) vertex.vtx2 - Second (or destination, if directed) vertex.label - Label associated with the edge.public Object remove(Object label)
remove in interface Graphlabel - The label of the vertex within the graph.
public abstract Object removeEdge(Object vLabel1,
Object vLabel2)
removeEdge in interface GraphvLabel1 - First (or source, if directed) vertex.vLabel2 - Second (or destination, if directed) vertex.public Object get(Object label)
get in interface Graphlabel - The label of the vertex sought.
public Edge getEdge(Object label1,
Object label2)
getEdge in interface Graphlabel1 - The first (or source, if directed) vertex.label2 - The second (or destination, if directed) vertex.public boolean contains(Object label)
contains in interface Graphcontains in class AbstractStructurelabel - The label of the vertex sought.
public boolean containsEdge(Object vLabel1,
Object vLabel2)
containsEdge in interface GraphvLabel1 - First (or source, if directed) vertex.vLabel2 - Second (or destination, if directed) vertex.public boolean visit(Object label)
visit in interface Graphlabel - Label of vertex to be visited.public boolean visitEdge(Edge e)
visitEdge in interface Graphe - Edge object that is part of graph.public boolean isVisited(Object label)
isVisited in interface Graphlabel - Label of vertex.public boolean isVisitedEdge(Edge e)
isVisitedEdge in interface Graphe - Edge of graph to be considered.public void reset()
reset in interface Graphpublic int size()
size in interface Graphpublic int degree(Object label)
degree in interface Graphlabel - Label associated with vertex.public abstract int edgeCount()
edgeCount in interface Graphpublic Iterator iterator()
iterator in interface Graphpublic Iterator neighbors(Object label)
neighbors in interface Graphlabel - Label of the vertex.public abstract Iterator edges()
edges in interface Graphpublic void clear()
clear in interface Graphpublic boolean isEmpty()
isEmpty in interface GraphisEmpty in class AbstractStructurepublic boolean isDirected()
isDirected in interface Graph
|
© 1998-2002 McGraw-Hill | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||