edu.gwu.algtest
Class GraphEdge
java.lang.Object
|
+--edu.gwu.algtest.GraphEdge
- public class GraphEdge
- extends java.lang.Object
A GraphEdge instance is used to store a single edge, directed or undirected.
The information stored are the two vertices on either side of the edge, and the edge weight (if any).
A directed edge has a start-vertex and an end-vertex, and so, using the variables below
make sense. What about an undirected edge? Since GraphEdge instances are
used in adjacency-lists, observe that the undirected edge (3, 2) is stored in the vertex
list for vertex 3 and the vertex list for vertex 2. In the vertex-list for
vertex 3, we would use 3 as the startVertex and 2 as the endVertex. Likewise, in the
the vertex list for vertex 2, we will use 2 as the startVertex and 3 as the endVertex.
Thus, the variables are suitable for undirected graph edges as well.
NOTE: the equals method checks both vertices, but not the weight.
|
Field Summary |
int |
endVertex
The end vertex of the edge. |
int |
startVertex
The start vertex of the edge. |
double |
weight
Edge weight (default value: 1) |
|
Constructor Summary |
GraphEdge(int s,
int e,
double w)
Constructor that takes all fields. |
|
Method Summary |
boolean |
equals(java.lang.Object obj)
equals will compare two graph edges to see it they represent
the same edge: they are equal if the startVertex of each are identical and
the endVertex of each are identical. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
startVertex
public int startVertex
- The start vertex of the edge.
endVertex
public int endVertex
- The end vertex of the edge.
weight
public double weight
- Edge weight (default value: 1)
GraphEdge
public GraphEdge(int s,
int e,
double w)
- Constructor that takes all fields.
- Parameters:
s - an int valuee - an int valuew - a double value
equals
public boolean equals(java.lang.Object obj)
equals will compare two graph edges to see it they represent
the same edge: they are equal if the startVertex of each are identical and
the endVertex of each are identical. The weight is ignored.
- Overrides:
equals in class java.lang.Object
- Parameters:
obj - an Object value- Returns:
- a
boolean value
toString
public java.lang.String toString()
- Overrides:
toString in class java.lang.Object