All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class rpi.goldsd.graph.Path

java.lang.Object
   |
   +----rpi.goldsd.graph.Path

public class Path
extends Object
implements Cloneable, Drawable
The Path class is an iterator class used to represent a path or walk through an associated graph.

Version:
2.0, 4/19/98
Author:
David Goldschmidt
See Also:
GraphBase

Variable Index

 o path
A Vector representing this path.

Constructor Index

 o Path()
Constructs an empty path.
 o Path(int)
Constructs an empty path with the initial path capacity.
 o Path(Path)
Constructs a path by copying another path.
 o Path(Vertex)
Constructs a path with a given start vertex.

Method Index

 o add(Edge)
Adds an edge and its corresponding destination vertex to the end of this path.
 o add(Vertex)
Adds an edge and its corresponding destination vertex to the end of this path.
 o addStartVertex(Vertex)
Initializes this path and adds the starting vertex to this path.
 o backtrack()
Removes the last vertex and edge from this path.
 o clone()
Clones this path.
 o concat(Path)
Concatenates the given path with this path by adding all elements of the given path to the end of this path.
 o contains(Edge)
Tests if a given edge exists in this path.
 o contains(Vertex)
Tests if a given vertex exists in this path.
 o edges()
Returns an enumeration of the edges in this path.
 o elements()
Returns an enumeration of the vertices and edges in this path.
 o firstVertex()
Returns a reference to the first vertex in this path.
 o graph()
Returns a reference to the graph associated with this path.
 o insertAfter(Path, Vertex)
Inserts a given path into this path after the first occurrence of the given vertex in this path.
 o isCycle()
Tests if this path is a cycle.
 o isReachable(Vertex, Vertex)
Tests if the given endVertex is reachable from the startVertex in this path.
 o lastVertex()
Returns a reference to the last vertex in this path.
 o length()
Returns the number of edges in this path.
 o name()
Returns the name of the graph this path is associated with.
 o occurrences(Edge)
Returns the number of occurrences of a given edge in this path.
 o occurrences(Vertex)
Returns the number of occurrences of a given vertex in this path.
 o pathCopyHelper(Path, Path)
This protected static method performs a deep copy of all edges and vertices in the path source to the path target.
 o toString()
Returns a String representation of this path.
 o vertices()
Returns an enumeration of the vertices of this path.
 o weight()
Returns the weight of this path, which is simply the sum of all weighted edges of this path.

Variables

 o path
 protected Vector path
A Vector representing this path. This Vector contains an alternating series of vertices and edges. Note that this Vector must begin and end with a Vertex object, thus the size() of the Vector will always be odd (unless it is zero).

Constructors

 o Path
 public Path(int capacity)
Constructs an empty path with the initial path capacity. If used, this value should indicate the number of vertices and edges making up this path, including the start and end vertices.

Parameters:
capacity - the initial capacity for the vector used to represent the path of alternating vertices and edges.
 o Path
 public Path(Vertex startVertex) throws IllegalArgumentException
Constructs a path with a given start vertex.

Parameters:
startVertex - the initial start vertex of this path.
Throws: IllegalArgumentException
if the start vertex argument is not in a graph.
 o Path
 public Path(Path P)
Constructs a path by copying another path.

Parameters:
P - the path to be copied.
 o Path
 public Path()
Constructs an empty path.

Methods

 o clone
 public Object clone()
Clones this path.

Returns:
a new path that is a clone of this path.
Overrides:
clone in class Object
 o pathCopyHelper
 protected static final void pathCopyHelper(Path target,
                                            Path source)
This protected static method performs a deep copy of all edges and vertices in the path source to the path target. Note that the target path is assumed to be constructed.

Parameters:
target - the target path object (should be an empty path).
source - the source path object.
 o contains
 public boolean contains(Edge E)
Tests if a given edge exists in this path.

Parameters:
E - the edge to test.
Returns:
true if the given edge E is in this path; false otherwise.
 o contains
 public boolean contains(Vertex V)
Tests if a given vertex exists in this path.

Parameters:
V - the vertex to test.
Returns:
true if the given vertex V is in this path; false otherwise.
 o edges
 public Enumeration edges()
Returns an enumeration of the edges in this path.

Returns:
an enumeration of the edges in this path.
 o elements
 public Enumeration elements()
Returns an enumeration of the vertices and edges in this path. Note that the nextElement() method of the enumeration returns alternating vertex and edge objects.

Returns:
an enumeration of the vertices and edges in this path.
 o firstVertex
 public Vertex firstVertex()
Returns a reference to the first vertex in this path.

Returns:
a reference to the first vertex in this path.
 o graph
 public GraphBase graph()
Returns a reference to the graph associated with this path.

Returns:
a reference to the graph associated with this path; or null if this path is not associated with a graph (which implies that the path is empty).
 o isCycle
 public boolean isCycle()
Tests if this path is a cycle.

Returns:
true if the first and last vertices are the same; false otherwise.
 o isReachable
 public boolean isReachable(Vertex startVertex,
                            Vertex endVertex)
Tests if the given endVertex is reachable from the startVertex in this path. Note that if this path is a cycle, then if the two given vertices exist in this path, then this method returns true. Also note that if duplicate vertices appear in the path, then the first occurrence of the startVertex is used as a starting place.

Parameters:
startVertex - the vertex to start the traversal from.
endVertex - the destination vertex.
Returns:
true if endVertex is reachable from startVertex; false otherwise.
 o lastVertex
 public Vertex lastVertex()
Returns a reference to the last vertex in this path.

Returns:
a reference to the last vertex in this path.
 o length
 public int length()
Returns the number of edges in this path.

Returns:
the number of edges in this path.
 o name
 public String name()
Returns the name of the graph this path is associated with.

Returns:
the name of the graph this path is associated with.
 o occurrences
 public int occurrences(Edge E)
Returns the number of occurrences of a given edge in this path.

Returns:
the number of occurrences of the given edge E in this path.
 o occurrences
 public int occurrences(Vertex V)
Returns the number of occurrences of a given vertex in this path.

Returns:
the number of occurrences of the given vertex V in this path.
 o toString
 public String toString()
Returns a String representation of this path. The String begins with "Path: " and then makes use of the toString() method of each of the vertices of this path, separating each vertex with "->" to represent an edge.

Returns:
a String representation of this path.
Overrides:
toString in class Object
 o vertices
 public Enumeration vertices()
Returns an enumeration of the vertices of this path.

Returns:
an enumeration of the vertices of this path.
 o weight
 public double weight()
Returns the weight of this path, which is simply the sum of all weighted edges of this path.

Returns:
the weight of this path.
 o add
 public void add(Edge E) throws IllegalArgumentException
Adds an edge and its corresponding destination vertex to the end of this path. The edge must be associated with the last vertex of this path. Note that this method actually adds two references to the end of this path: first the given edge E, and second the destination vertex found by traversing E from the last vertex of this path.

Parameters:
E - the edge to be added.
Throws: IllegalArgumentException
if the edge is not associated with the last vertex of this path.
 o add
 public void add(Vertex V) throws IllegalArgumentException
Adds an edge and its corresponding destination vertex to the end of this path. The edge must be associated with the last vertex of this path. Note that this method actually adds two references to the end of this path: first the given edge, and second the given destination vertex.

Parameters:
V - the vertex to be added.
Throws: IllegalArgumentException
if there is no edge connecting the last vertex of this path and the given vertex argument.
 o addStartVertex
 public void addStartVertex(Vertex V) throws IllegalArgumentException
Initializes this path and adds the starting vertex to this path. Note that this method removes all elements from the existing path, if any.

Parameters:
V - the starting vertex of this path.
Throws: IllegalArgumentException
if the Vertex argument is not in a graph object.
 o backtrack
 public Edge backtrack()
Removes the last vertex and edge from this path.

Returns:
the edge removed from this path; or null if the path contains no edges.
 o concat
 public void concat(Path P) throws IllegalArgumentException
Concatenates the given path with this path by adding all elements of the given path to the end of this path. Note that the last vertex of this path must be the same as the first vertex of the given path P.

Parameters:
P - the path to be added to this path.
Throws: IllegalArgumentException
if the last vertex of this path is not the first vertex of the given Path object.
 o insertAfter
 public void insertAfter(Path P,
                         Vertex V) throws IllegalArgumentException, VertexNotFoundException
Inserts a given path into this path after the first occurrence of the given vertex in this path. The vertex V must exist in this path and be the first and last vertex in the given path P (i.e. the given path P must be a cycle).

Parameters:
P - the path to be inserted.
V - the vertex after which the path P is to be inserted.
Throws: IllegalArgumentException
if the given Path object is not a cycle, or if the given Vertex object does not begin the given Path object.
Throws: VertexNotFoundException
if the given Vertex object is not in this path.

All Packages  Class Hierarchy  This Package  Previous  Next  Index