I seem to have come across a non-intuitive discrepancy between how vertexes
are stored in jgrapht graphs (in this case a SimpleDirectedGraph) in the
vertexSet, vs. how they are stored as the target of an edge (see below for
my usage of getEdgeTarget). I had thought they were identical - i.e. they
point to the same object (a SteveVertex in this case) and have the same
hash code - but they seem to be located in different places somehow, per
symptom below.
When my code below comes across a loop, in which it encounters the original
start vertex as the target of an edge, it does not show this vertex as
having been visited, even though the hashCode (SteveVertex@vertex1) is
identical to the first entry of the vertexSet which DOES show the vertex as
having been visited.
Any help would be greatly appreciated in diagnosing this.
private static SimpleDirectedGraph<SteveVertex, DefaultEdge> graph;
private static void SteveDepthFirstSearch(SteveVertex startVertex)
{
if (!startVertex.visited()) {
startVertex.visit();
for (DefaultEdge e : graph.outgoingEdgesOf(startVertex))
SteveDepthFirstSearch(graph.getEdgeTarget(e));
startVertex.setFinishOrder(counter);
counter++;
}
}
public static void main(String[] args) {
...
for (SteveVertex v: graph.vertexSet())
SteveDepthFirstSearch(v);
...
}
--
This communication is confidential and subject to and governed by the
confidentiality and use restrictions contained in Saama’s Electronic
Communications Disclaimer. <http://www.saama.com/disclaimer>
|