[jgrapht-users] shortest path - getting all vertices, not just edges
Brought to you by:
barak_naveh,
perfecthash
From: Sophia K. <sop...@ya...> - 2011-08-23 14:56:02
|
Dear All, It's a totally newbie question, and I must have overlooked something (so I apologize in advance). I couldn't find an elegant solution and had to implement it in an ugly way which I would like to change. 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. Could you please suggest a better solution for this? I would really prefer to do it right away using the instance of DijkstraShortestPath. Thanks in advance! Best,Sophia |