Re: [jgrapht-users] Obtaining a path from BreadthFirstIterator
Brought to you by:
barak_naveh,
perfecthash
From: Szabolcs B. <bes...@gm...> - 2015-10-04 16:18:25
|
If you need a path in a given graph use the relevant method of any of the shortest path algorithm implementations, such as DijkstraShortestPath.findPathBetween(graph, source, destination). Üdvözlettel, Besenyei Szabolcs 2015-10-04 17:20 GMT+02:00 Traven <mar...@gm...>: > Here is the code to traverse the graph with BreathFirstIterator: > > public class GraphTest { > > public static void main(String[] args) { > DirectedGraph<Integer, DefaultEdge> graph = > new DefaultDirectedGraph <Integer, > DefaultEdge>(DefaultEdge.class); > > graph.addVertex(7); > graph.addVertex(4); > graph.addVertex(9); > graph.addVertex(3); > graph.addVertex(2); > graph.addVertex(5); > > > graph.addEdge(7, 4); > graph.addEdge(7, 9); > graph.addEdge(9, 3); > graph.addEdge(3, 2); > graph.addEdge(3, 5); > > GraphIterator<Integer, DefaultEdge> iterator = > new BreadthFirstIterator<Integer, DefaultEdge>(graph); > while (iterator.hasNext()) { > System.out.println( iterator.next() ); > } > } > } > As expected, the code prints out the list of all visited vertexes: > 7,4,9,3,2,5. My problem is - I don't know how can I use this API to obtain > a > path (with removed backtracks of algorithm, i.e for example for path from 7 > to 2: 7->9->3->2), not just the list of visited vertexes. Stopping it after > reaching the destination is obviously not enough. Have anyone already > solved > this issue? > > > > -- > View this message in context: > http://jgrapht-users.107614.n3.nabble.com/Obtaining-a-path-from-BreadthFirstIterator-tp4025051.html > Sent from the jgrapht-users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > _______________________________________________ > jgrapht-users mailing list > jgr...@li... > https://lists.sourceforge.net/lists/listinfo/jgrapht-users > |