From: Traven <mar...@gm...> - 2015-10-04 16:30:08
|
I'm sorry, I tried to simplify the case too much and made it unreadable. My core in reality looks more like this: SimpleDirectedWeightedGraph<String, DefaultWeightedEdge> graph = new SimpleDirectedWeightedGraph<String, DefaultWeightedEdge> (DefaultWeightedEdge.class); graph.addVertex("1"); graph.addVertex("2"); graph.addVertex("3"); graph.addVertex("4"); graph.addVertex("5"); DefaultWeightedEdge e1 = graph.addEdge("1", "2"); graph.setEdgeWeight(e1, 5); DefaultWeightedEdge e2 = graph.addEdge("2", "3"); graph.setEdgeWeight(e2, 10); DefaultWeightedEdge e3 = graph.addEdge("2", "4"); graph.setEdgeWeight(e3, 2); DefaultWeightedEdge e4 = graph.addEdge("4", "5"); graph.setEdgeWeight(e4, 2); DefaultWeightedEdge e5 = graph.addEdge("5", "3"); graph.setEdgeWeight(e5, 2); System.out.println("Shortest path from vertex 1 to vertex 5:"); List shortest_path = DijkstraShortestPath.findPathBetween(graph, "1", "3"); System.out.println(shortest_path); } In this case Dijkstra returns the correct, shortest path: 1->2->4->5->3. My problem is - for the same graph, I want to obtain the path containing the fewest number of transfers between vertices (in this case it would be 1->2->3). For this use-case the BFS would be the perfect solution. Is there a way to somehow use the BreadthFirstIterator from jgrapht API or do I have to write an algorithm by myself? -- View this message in context: http://jgrapht-users.107614.n3.nabble.com/Obtaining-a-path-from-BreadthFirstIterator-tp4025051p4025053.html Sent from the jgrapht-users mailing list archive at Nabble.com. |