The problem doesn't seem to be in the section of code you posted. Check
whether your visited() method actually does something.
"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)." Also, check whether your isVisited()
method returns the correct result.
I'm not sure where you get this idea from? This is not true. All methods
use the same vertex or edge objects. Furthermore, none of the methods
you've shown use equals/hashCode, so even if you had implemented them
wrong, I don't see why this would effect your result. Btw, I would
encourage you to have a look at the jgrapht graph source code. It is very
clear and gives you a good understanding of how the graph package works.
It will not make a difference, but in your code I would find it cleaner to
write:
for (SteveVertex neighborVertex :
Graphs.outgoingNeighborsOf(graph,startVertex)
SteveDepthFirstSearch(neighborVertex);
instead of:
for (DefaultEdge e : graph.outgoingEdgesOf(startVertex))
SteveDepthFirstSearch(graph.getEdgeTarget(e));
br,
Joris Kinable
On Sun, Aug 9, 2015 at 3:00 PM, Steven Barkin <ste...@sa...>
wrote:
> 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>
>
>
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> jgrapht-users mailing list
> jgr...@li...
> https://lists.sourceforge.net/lists/listinfo/jgrapht-users
>
>
|