All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tw.edu.ncnu.im.cnclab.JGAP.Graph

java.lang.Object
   |
   +----tw.edu.ncnu.im.cnclab.JGAP.Graph

public class Graph
extends Object
implements Serializable, Cloneable
The Graph class implements data structure of graphs.

The implementation of the graph supports both adjacency matrix and adjacency list. Use enumerations as adjacency list; for loop as adjacency matrix.

Node stands for identity of vertex.

Version:
0.4 Jul 8, 1999
Author:
Ding-Yi Chen
See Also:
Enumeration, Vertex, Edge

Variable Index

 o canvasSize
The best fit canvas size of the graph
 o description
The description of the graph.
 o directed
Whether the graph is directed.
 o edgeList
The ListArray that store edges
 o IN_ADJACENCY
This constant value indicates that the getting adjacency edges as in adjacency edges.
 o MAX_VERTICES
The maximum number of vertices capacity;
 o modified
Indicate if the graph has been modified.
 o NUL
Indicate null item
 o OUT_ADJACENCY
This constant value indicates that the getting adjacency edges as out adjacency edges.
 o serialNo
The serial number of the graph.
 o showFlow
Whether the flow of the graph show at screen.
 o vertexDiameter
The diameter of a vertex;
 o vertexList
The ListArray that store vertices
 o vertexSerialNo
The serial number of the vertex.
 o vertexSpace
The space between each two vertices

Constructor Index

 o Graph()
Construct a directed graph.
 o Graph(boolean)
Construct a graph.
 o Graph(boolean, Dimension)
Construct a graph.

Method Index

 o addEdge(Edge)
Add a clone of specified edge into this graph.
 o addEdge(int, int, double, double)
Add an edge into this graph.
 o addEdge(int, int, double, double, Color)
Add an edge into this graph.
 o addVertex(int, int)
Add vertex at specified coordinate.
 o addVertex(int, int, Color)
Add vertex at specified coordinate.
 o addVertex(Vertex)
Add a clone of specified vertex into this graph.
 o allEdgesElements()
Returns an enumeration of the all edges of this graph.
 o clean()
Reset all special attribute the graph.
 o cleanAllEdges()
Clean all special attribute of Edge.
 o cleanAllVertices()
Clean all special attribute of Vertices.
 o clear()
Remove all vertices and edges.
 o clear(boolean)
Remove all vertices and edges.
 o clone()
Returns a deep-copied clone of this Graph.
 o closeTo(int, int)
Return the node that close to specified coordinate.
 o closeTo(int, int, int)
Return the node that close to specified coordinate.
 o copyFrom(Graph)
Copies the components from specified Graph to this Graph
 o deleteAllEdges()
Delete all edges
 o deleteAllOtherEdges(Color)
Delete all special edges.
 o deleteEdge(Edge)
Delete an edge of this graph.
 o deleteEdge(int, int)
Delete an edge of this graph.
 o deleteNode(int)
Delete the specified node
 o deleteVertex(Vertex)
Delete the specified vertex
 o directedAdjVerticesElements(int)
Returns an enumeration of the adjacency vertex of the node of this graph.
 o directedAdjVerticesElements(int, int)
Returns an enumeration of the adjacency vertex of the node of this graph.
 o directedAdjVerticesElements(Vertex)
Returns an enumeration of the adjacency vertex of v of this graph.
 o directedAdjVerticesElements(Vertex, int)
Returns an enumeration of the adjacency vertex of v of this graph.
 o edgesElements(int)
Returns an enumeration of the outgoing adjacency edges of the node of this graph.
 o edgesElements(int, int)
Returns an enumeration of the adjacency edges of the node of this graph.
 o edgesElements(Vertex)
Returns an enumeration of the outgoing adjacency edges of the vertex of this graph.
 o edgesElements(Vertex, int)
Returns an enumeration of the adjacency edges of the vertex of this graph.
 o getCanvasSize()
Get the size of the canvas.
 o getDescr()
Get the description of the graph.
 o getEdge(int, int)
Get the edge by both ends.
 o getNumOfEdges()
Return the number of edges in the graph.
 o getNumOfVertices()
Return the actual number of vertices in this graph.
 o getPredecessor(int)
Get the predecessor vertex of the specified node.
 o getPredecessor(Vertex)
Get the predecessor vertex of the specified vertex.
 o getPredecessorNode(int)
Get the predecessor node of the specified node.
 o getPredecessorNode(Vertex)
Get the predecessor node of the specified vertex.
 o getVertex(int)
Get the vertex by node (the identity of vertex)
 o getVertexSerialNo()
Return the next serial number of vertices, as well as the total number of vertices, including deleted vertices.
 o inAVertex(int, int)
Return the node that contains the specified coordinate.
 o isDirected()
Whether the graph is directed.
 o isEdge(int, int)
Return whether the edge exist specified indexes.
 o isEdgeUndir(int, int)
Return whether the edge exist specified indexes.
 o isModified()
Whether the graph has been modified.
 o isShowFlow()
Whether the graph algorithms need to consider the flow of the graph.
 o isVertexExist(int)
Return whether the vertex exist at the index (node)
 o makeVertex(int, int)
If there is a canvas space for vertex, then add vertex at specified coordinate.
 o purgeDeletedVertex()
Purge the deleted vertex.
 o reset()
Reset special attribute of the graph.
 o setCanvasSize(Dimension)
Set the size of the canvas.
 o setDescr(String)
Set the description of the graph.
 o setDirected(boolean)
Specified whether the graph has been modified.
 o setEdge(int, int, double, double)
Set edge attribute.
 o setEdge(int, int, double, double, Color)
Set edge attribute.
 o setModified(boolean)
Specified whether the graph has been modified.
 o setPredecessor(int, int)
Set the predecessor node of the specified node.
 o setPredecessor(int, Vertex)
Set the predecessor vertex of the specified node.
 o setPredecessor(Vertex, int)
Set the predecessor node of the specified vertex.
 o setPredecessor(Vertex, Vertex)
Set the predecessor vertex of the specified vertex.
 o setShowFlow(boolean)
Whether the graph algorithms need to consider the flow of the graph.
 o symmetricDifference(Graph)
Symmetric Difference edges (Excludsive OR) with other graph.
 o undirectedAdjVerticesElements(int)
Returns an enumeration of the adjacency vertex of the node of this graph.
 o undirectedAdjVerticesElements(Vertex)
Returns an enumeration of the adjacency vertex of v of this graph.
 o union(Graph)
Union edges with other graph.
 o verticesElements()
Returns an enumeration of the vertices of this graph.

Variables

 o NUL
 public static final int NUL
Indicate null item

 o OUT_ADJACENCY
 public static final int OUT_ADJACENCY
This constant value indicates that the getting adjacency edges as out adjacency edges.

 o IN_ADJACENCY
 public static final int IN_ADJACENCY
This constant value indicates that the getting adjacency edges as in adjacency edges.

 o serialNo
 public int serialNo
The serial number of the graph.

 o vertexSerialNo
 protected int vertexSerialNo
The serial number of the vertex.

 o modified
 protected boolean modified
Indicate if the graph has been modified.

 o vertexList
 protected ListArray vertexList
The ListArray that store vertices

 o edgeList
 protected ListArray2 edgeList
The ListArray that store edges

 o directed
 protected boolean directed
Whether the graph is directed.

 o showFlow
 protected boolean showFlow
Whether the flow of the graph show at screen.

 o MAX_VERTICES
 public static final int MAX_VERTICES
The maximum number of vertices capacity;

 o vertexDiameter
 public static int vertexDiameter
The diameter of a vertex;

 o vertexSpace
 public static int vertexSpace
The space between each two vertices

 o canvasSize
 protected Dimension canvasSize
The best fit canvas size of the graph

 o description
 protected String description
The description of the graph.

Constructors

 o Graph
 public Graph()
Construct a directed graph.

 o Graph
 public Graph(boolean directed)
Construct a graph.

Parameters:
directed - whether the graph is directed.
 o Graph
 public Graph(boolean directed,
              Dimension canvasSize)
Construct a graph.

Parameters:
directed - whether the graph is directed.
canvasSize - the size of canvas.

Methods

 o getDescr
 public String getDescr()
Get the description of the graph.

Returns:
the description of the graph.
 o setDescr
 public void setDescr(String descr)
Set the description of the graph.

Parameters:
descr - The description of the graph.
 o clone
 public Object clone()
Returns a deep-copied clone of this Graph.

Returns:
a deep-copied clone of this Graph.
Overrides:
clone in class Object
 o copyFrom
 public void copyFrom(Graph src)
Copies the components from specified Graph to this Graph

Parameters:
src - the source Graph
 o reset
 public void reset()
Reset special attribute of the graph.

See Also:
reset, reset, clean
 o clean
 public void clean()
Reset all special attribute the graph.

See Also:
clean, clean, reset
 o clear
 public void clear()
Remove all vertices and edges.

 o clear
 public void clear(boolean directed)
Remove all vertices and edges.

Parameters:
directed - set the new graph type.
 o isDirected
 public boolean isDirected()
Whether the graph is directed.

Returns:
whether the graph is directed.
 o setDirected
 protected void setDirected(boolean directed)
Specified whether the graph has been modified.

Parameters:
modified - whether the graph has been modified.
 o isModified
 public boolean isModified()
Whether the graph has been modified.

Returns:
whether the graph has been modified.
 o setModified
 public void setModified(boolean modified)
Specified whether the graph has been modified.

Parameters:
modified - whether the graph has been modified.
 o isShowFlow
 public boolean isShowFlow()
Whether the graph algorithms need to consider the flow of the graph.

Returns:
whether the graph algorithms need to consider the flow of the graph.
 o setShowFlow
 public void setShowFlow(boolean b)
Whether the graph algorithms need to consider the flow of the graph.

Returns:
whether the graph algorithms need to consider the flow of the graph.
 o symmetricDifference
 public void symmetricDifference(Graph g)
Symmetric Difference edges (Excludsive OR) with other graph.

Parameters:
g - the graph to process with this graph.
 o union
 public void union(Graph g)
Union edges with other graph.

Parameters:
g - the graph to union with this graph.
 o getCanvasSize
 public Dimension getCanvasSize()
Get the size of the canvas.

Returns:
the size of canvas
 o setCanvasSize
 public void setCanvasSize(Dimension d)
Set the size of the canvas.

Parameters:
d - The new size of canvas.
 o addVertex
 public void addVertex(int x,
                       int y)
Add vertex at specified coordinate.

Parameters:
x - the coordinate x of this vertex.
y - the coordinate y of this vertex.
 o addVertex
 public void addVertex(int x,
                       int y,
                       Color color)
Add vertex at specified coordinate.

Parameters:
x - the coordinate x of this vertex.
y - the coordinate y of this vertex.
color - the color of this vertex.
 o addVertex
 public void addVertex(Vertex v)
Add a clone of specified vertex into this graph.

The method use the infomation of specified vertex to create another vertex.

Parameters:
v - the vertex to add.
 o makeVertex
 public int makeVertex(int x,
                       int y)
If there is a canvas space for vertex, then add vertex at specified coordinate.

This method prevents vertices congesting in some place. If there is some vertices close to the coordinate of new vertex, makeVertex won't add vertex and return NUL , otherwise add vertex in this graph and return the vertexID of the vertex to add.

Parameters:
x - the coordinate x of this vertex.
y - the coordinate y of this vertex.
Returns:
the vertex ID if sucess; NUL if fail.
 o inAVertex
 public int inAVertex(int i,
                      int j)
Return the node that contains the specified coordinate.

Parameters:
x - the coordinate x.
y - the coordinate y.
Returns:
The node that contains the specified coordinate; NUL if none of vertices contain the corrdinate.
 o closeTo
 public int closeTo(int x,
                    int y)
Return the node that close to specified coordinate.

Parameters:
x - the coordinate x.
y - the coordinate y.
Returns:
The node that close to specified coordinate; NUL if none of vertices close the corrdinate.
 o closeTo
 public int closeTo(int x,
                    int y,
                    int distance)
Return the node that close to specified coordinate.

If Math.abs(vertex.x - x) < distance and Math.abs(vertex.y)-y)

Parameters:
x - the coordinate x.
y - the coordinate y.
distance - the distance.
Returns:
The node that close to specified coordinate; NUL if none of vertices close the corrdinate.
 o deleteVertex
 public void deleteVertex(Vertex v) throws NoSuchVertexException
Delete the specified vertex

Parameters:
v - the vertex to be delete.
Throws: NoSuchVertexException
if the v is not valid.
 o deleteNode
 public void deleteNode(int node) throws NoSuchVertexException
Delete the specified node

Parameters:
node - the node to be delete.
Throws: NoSuchVertexException
if the node is not valid.
 o getVertex
 public Vertex getVertex(int node) throws NoSuchVertexException
Get the vertex by node (the identity of vertex)

Parameters:
node - the identity of vertex
Throws: NoSuchVertexException
if the no vertex exist at index node
 o purgeDeletedVertex
 public void purgeDeletedVertex()
Purge the deleted vertex.

Renumbumering the vertex from 0 to number of vertices

 o getPredecessor
 public Vertex getPredecessor(int node) throws NoSuchVertexException
Get the predecessor vertex of the specified node.

Parameters:
node - the specified node.
Returns:
the predecessor vertex of the specified node.
Throws: NoSuchVertexException
if the no vertex exist at index node .
 o getPredecessor
 public Vertex getPredecessor(Vertex v) throws NoSuchVertexException
Get the predecessor vertex of the specified vertex.

Parameters:
v - the specified vertex.
Returns:
the predecessor vertex of the specified vertex.
Throws: NoSuchVertexException
if the v is null.
 o getPredecessorNode
 public int getPredecessorNode(int node) throws NoSuchVertexException
Get the predecessor node of the specified node.

Parameters:
node - the specified node.
Returns:
the predecessor node of the specified node.
Throws: NoSuchVertexException
if the no vertex exist at index node .
 o getPredecessorNode
 public int getPredecessorNode(Vertex v) throws NoSuchVertexException
Get the predecessor node of the specified vertex.

Parameters:
v - the specified vertex.
Returns:
the predecessor node of the specified vertex.
Throws: NoSuchVertexException
if the v is null.
 o setPredecessor
 public void setPredecessor(int node,
                            Vertex predecessor) throws NoSuchVertexException
Set the predecessor vertex of the specified node.

Parameters:
node - the node.
predecessor - the predecessor of node .
Throws: NoSuchVertexException
either code or predecessor is not valid.
 o setPredecessor
 public void setPredecessor(Vertex v,
                            Vertex predecessor) throws NoSuchVertexException
Set the predecessor vertex of the specified vertex.

Parameters:
v - the vertex.
predecessor - the predecessor of v .
Throws: NoSuchVertexException
either v or predecessor is not valid.
 o setPredecessor
 public void setPredecessor(int node,
                            int predecessorNode) throws NoSuchVertexException
Set the predecessor node of the specified node.

Parameters:
node - the node.
predecessorNode - the predecessor of node .
Throws: NoSuchVertexException
either node or predecessorNode is not valid.
 o setPredecessor
 public void setPredecessor(Vertex v,
                            int predecessorNode) throws NoSuchVertexException
Set the predecessor node of the specified vertex.

Parameters:
v - the vertex.
predecessorNode - the predecessor of vertex .
Throws: NoSuchVertexException
either v or predecessorNode is not valid.
 o isVertexExist
 public boolean isVertexExist(int node)
Return whether the vertex exist at the index (node)

Parameters:
node - the index (node).
Returns:
whether the vertex exist at the index.
 o getNumOfVertices
 public final int getNumOfVertices()
Return the actual number of vertices in this graph.

Deleted vertices don't count in this method. Use getVertexSerialNo instead while using for-loop or while loop

Returns:
the number of vertices in this graph.
See Also:
getVertexSerialNo
 o getVertexSerialNo
 public int getVertexSerialNo()
Return the next serial number of vertices, as well as the total number of vertices, including deleted vertices.

Use getNumOfVertices if you don't want to count deleted vertices.

Returns:
the next serial number of vertices.
See Also:
getNumOfVertices
 o verticesElements
 public final synchronized Enumeration verticesElements()
Returns an enumeration of the vertices of this graph.

Returns:
s an enumeration of the vertices of this graph.
 o addEdge
 public void addEdge(Edge edge)
Add a clone of specified edge into this graph.

The method use the infomation of specified edge to create another edge.

Parameters:
edge - the edge to add.
 o addEdge
 public void addEdge(int from,
                     int to,
                     double weight,
                     double flow)
Add an edge into this graph.

Parameters:
from - the start node of the edge.
to - the end node of the edge.
weight - the weight of the edge.
flow - the flow of the edge.
 o addEdge
 public void addEdge(int from,
                     int to,
                     double weight,
                     double flow,
                     Color color)
Add an edge into this graph.

Parameters:
from - the start node of the edge.
to - the end node of the edge.
weight - the weight of the edge.
flow - the flow of the edge.
color - the color of the edge.
 o deleteEdge
 public void deleteEdge(int from,
                        int to)
Delete an edge of this graph.

Parameters:
from - the start node of the edge.
to - the end node of the edge.
 o deleteEdge
 public void deleteEdge(Edge edge)
Delete an edge of this graph.

Parameters:
edge - the edge to be delete.
 o cleanAllVertices
 public void cleanAllVertices()
Clean all special attribute of Vertices.

See Also:
clean, cleanAllEdges
 o cleanAllEdges
 public void cleanAllEdges()
Clean all special attribute of Edge.

See Also:
clean, cleanAllVertices
 o deleteAllOtherEdges
 public void deleteAllOtherEdges(Color color)
Delete all special edges.

Delete edges which color is not same as color .

For example: If you want to keep the edge with color with Edge.normalColor, but delete other, you may use deleteAllOtherEdges(Edge.normalColor) to do this.

Parameters:
color - Ths edge with this status to keep.
 o deleteAllEdges
 public void deleteAllEdges()
Delete all edges

 o isEdge
 public boolean isEdge(int from,
                       int to)
Return whether the edge exist specified indexes.

Parameters:
from - the start node of the edge.
to - the end node of the edge.
Returns:
true if edge(from,to) exist; false otherwise.
 o isEdgeUndir
 public boolean isEdgeUndir(int from,
                            int to)
Return whether the edge exist specified indexes. Direction don't care.

Parameters:
from - the start node of the edge.
to - the end node of the edge.
Returns:
true if edge(from,to) or edge(to,from) exist; false otherwise.
 o getEdge
 public Edge getEdge(int from,
                     int to) throws NoSuchEdgeException
Get the edge by both ends.

Parameters:
from - the start node of the edge.
to - the end node of the edge.
Throws: NoSuchEdgeException
if the no edge exist at (from,to)
 o setEdge
 public void setEdge(int from,
                     int to,
                     double edgeWeight,
                     double edgeFlow)
Set edge attribute.

Parameters:
from - the start node of the edge.
to - the end node of the edge.
edgeWeight - the weight of the edge.
edgeFlow - the flow of the edge.
 o setEdge
 public void setEdge(int from,
                     int to,
                     double edgeWeight,
                     double edgeFlow,
                     Color color)
Set edge attribute.

Parameters:
from - the start node of the edge.
to - the end node of the edge.
edgeWeight - the weight of the edge.
edgeFlow - the flow of the edge.
status - the status of the edge.
color - the color of the edge.
 o getNumOfEdges
 public int getNumOfEdges()
Return the number of edges in the graph.

 o edgesElements
 public final synchronized Enumeration edgesElements(int node)
Returns an enumeration of the outgoing adjacency edges of the node of this graph.

Parameters:
node - the node.
 o edgesElements
 public final synchronized Enumeration edgesElements(Vertex v)
Returns an enumeration of the outgoing adjacency edges of the vertex of this graph.

Parameters:
v - the vertex.
 o edgesElements
 public final synchronized Enumeration edgesElements(int node,
                                                     int dimension)
Returns an enumeration of the adjacency edges of the node of this graph.

Parameters:
node - the node.
dimension - Graph.OUT_ADJACENCY : return the enumeration of outgoing adjacency edges; Graph.IN_ADJACENCY return the enumeration of incoming adjacency edges.
 o edgesElements
 public final synchronized Enumeration edgesElements(Vertex v,
                                                     int dimension)
Returns an enumeration of the adjacency edges of the vertex of this graph.

Parameters:
v - the vertex.
dimension - Graph.OUT_ADJACENCY : return the enumeration of outgoing adjacency edges; Graph.IN_ADJACENCY return the enumeration of incoming adjacency edges.
 o directedAdjVerticesElements
 public final synchronized Enumeration directedAdjVerticesElements(int node)
Returns an enumeration of the adjacency vertex of the node of this graph.

Parameters:
node - the node.
 o directedAdjVerticesElements
 public final synchronized Enumeration directedAdjVerticesElements(int node,
                                                                   int dimension)
Returns an enumeration of the adjacency vertex of the node of this graph.

Parameters:
v - the vertex.
dimension - Graph.OUT_ADJACENCY : return the enumeration of outgoing adjacency edges; Graph.IN_ADJACENCY return the enumeration of incoming adjacency edges.
 o directedAdjVerticesElements
 public final synchronized Enumeration directedAdjVerticesElements(Vertex v)
Returns an enumeration of the adjacency vertex of v of this graph.

Parameters:
v - the Vertex.
 o directedAdjVerticesElements
 public final synchronized Enumeration directedAdjVerticesElements(Vertex v,
                                                                   int dimension)
Returns an enumeration of the adjacency vertex of v of this graph.

Parameters:
v - the Vertex.
dimension - Graph.OUT_ADJACENCY : return the enumeration of outgoing adjacency edges; Graph.IN_ADJACENCY return the enumeration of incoming adjacency edges.
 o undirectedAdjVerticesElements
 public final synchronized Enumeration undirectedAdjVerticesElements(int node)
Returns an enumeration of the adjacency vertex of the node of this graph. Directed graph is treat as undirected graph.

Parameters:
node - the node.
 o undirectedAdjVerticesElements
 public final synchronized Enumeration undirectedAdjVerticesElements(Vertex v)
Returns an enumeration of the adjacency vertex of v of this graph. Directed graph is treat as undirected graph.

Parameters:
Vertex - the vertex.
 o allEdgesElements
 public final synchronized Enumeration allEdgesElements()
Returns an enumeration of the all edges of this graph.

Returns:
s an enumeration of the all edges of this graph.

All Packages  Class Hierarchy  This Package  Previous  Next  Index