Re: [jgrapht-users] shortest path - getting all vertices, not just edges
Brought to you by:
barak_naveh,
perfecthash
From: <hnr...@gr...> - 2011-08-23 21:26:51
|
Dear Sophia, I'm not absolutely certain I understood your problem, but I think you're having problems with g.getEdgeTarget(e3) returning c, whereas you would like to receive b, is that correct? In that case Graphs.getOppositeVertex(g, e3, c) might be what you're looking for. It can be used to conveniently cycle through a path: src = c; for (E e : edgelist_starting_at_c) { println(src); println(e); src = Graphs.getOppositeVertex(g, e, src) ; } Hope this helps, Ernst de Ridder -- Information System on Graph Classes and their Inclusions (ISGCI) http://www.graphclasses.org ----- Reply message ----- From: "Sophia Katrenko" <sop...@ya...> To: <jgr...@li...> Subject: [jgrapht-users] shortest path - getting all vertices, not just edges Date: Tue, Aug 23, 2011 16:55 In short, I have an undirected graph and use the Dijsktra method to find the shortest path between two vertices. I'd like to output not only edges, but also traverse all the vertices on the way. Since I only get edges by using both DijkstraShortestPath.findPathBetween() and DijkstraShortestPath.getPath(), I do iterate over all edges in the path and, for each edge 'e', I output vertices using the getEdgeTarget(e). It does work well, however in the cases like below, it doesn't work even though a graph is undirected: e1(a, d)e2(a, b)e3(b, c) path between 'c' and 'd' is [e3, e2, e1] or [e3, b, e2, a, e1, d] However, I cannot get the last solution because I use getEdgeTarget, so I have to do some extra checks in the code to arrive at this path. |