|
© 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 Graph
label
- Label of the vertex; should be non-null.public abstract void addEdge(Object v1, Object v2, Object label)
addEdge
in interface Graph
vtx1
- 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 Graph
label
- The label of the vertex within the graph.public abstract Object removeEdge(Object vLabel1, Object vLabel2)
removeEdge
in interface Graph
vLabel1
- First (or source, if directed) vertex.vLabel2
- Second (or destination, if directed) vertex.public Object get(Object label)
get
in interface Graph
label
- The label of the vertex sought.public Edge getEdge(Object label1, Object label2)
getEdge
in interface Graph
label1
- The first (or source, if directed) vertex.label2
- The second (or destination, if directed) vertex.public boolean contains(Object label)
contains
in interface Graph
contains
in class AbstractStructure
label
- The label of the vertex sought.public boolean containsEdge(Object vLabel1, Object vLabel2)
containsEdge
in interface Graph
vLabel1
- First (or source, if directed) vertex.vLabel2
- Second (or destination, if directed) vertex.public boolean visit(Object label)
visit
in interface Graph
label
- Label of vertex to be visited.public boolean visitEdge(Edge e)
visitEdge
in interface Graph
e
- Edge object that is part of graph.public boolean isVisited(Object label)
isVisited
in interface Graph
label
- Label of vertex.public boolean isVisitedEdge(Edge e)
isVisitedEdge
in interface Graph
e
- Edge of graph to be considered.public void reset()
reset
in interface Graph
public int size()
size
in interface Graph
public int degree(Object label)
degree
in interface Graph
label
- Label associated with vertex.public abstract int edgeCount()
edgeCount
in interface Graph
public Iterator iterator()
iterator
in interface Graph
public Iterator neighbors(Object label)
neighbors
in interface Graph
label
- Label of the vertex.public abstract Iterator edges()
edges
in interface Graph
public void clear()
clear
in interface Graph
public boolean isEmpty()
isEmpty
in interface Graph
isEmpty
in class AbstractStructure
public 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 |