org.jgrapht.alg.shortestpath.DijkstraShortestPath Java Examples
The following examples show how to use
org.jgrapht.alg.shortestpath.DijkstraShortestPath.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleRoadMapPlanner.java From coordination_oru with GNU General Public License v3.0 | 6 votes |
/** * Get the shortest path connecting given locations (two or more). The path between successive pairs of locations * is computed with Dijkstra's algorithm, where edge weights are path lengths. * @param locations At least two location names. * @return The shortest path connecting given locations. */ public PoseSteering[] getShortestPath(String[] locations) { if (locations.length < 2) throw new Error("Please provide at least two locations for path extraction!"); DijkstraShortestPath<String, DefaultWeightedEdge> dijkstraShortestPath = new DijkstraShortestPath<String, DefaultWeightedEdge>(graph); ArrayList<PoseSteering> overallShortestPath = new ArrayList<PoseSteering>(); for (int k = 0; k < locations.length-1; k++) { GraphPath<String, DefaultWeightedEdge> gp = dijkstraShortestPath.getPath(locations[k], locations[k+1]); if (gp == null) return null; List<String> oneShortestPath = gp.getVertexList(); ArrayList<PoseSteering> allPoses = new ArrayList<PoseSteering>(); for (int i = 0; i < oneShortestPath.size()-1; i++) { //PoseSteering[] onePath = loadKnownPath(oneShortestPath.get(i),oneShortestPath.get(i+1)); PoseSteering[] onePath = paths.get(oneShortestPath.get(i)+"->"+oneShortestPath.get(i+1)); if (i == 0) allPoses.add(onePath[0]); for (int j = 1; j < onePath.length-1; j++) { allPoses.add(onePath[j]); } if (i == oneShortestPath.size()-2) allPoses.add(onePath[onePath.length-1]); } if (k == 0) overallShortestPath.add(allPoses.get(0)); for (int i = 1; i < allPoses.size(); i++) { overallShortestPath.add(allPoses.get(i)); } } return overallShortestPath.toArray(new PoseSteering[overallShortestPath.size()]); }
Example #2
Source File: Missions.java From coordination_oru with GNU General Public License v3.0 | 6 votes |
/** * Get the shortest path connecting given locations (two or more). The path between successive pairs of locations * is computed with Dijkstra's algorithm, where edge weights are path lengths. * @param locations At least two location names. * @return The shortest path connecting given locations. */ public static PoseSteering[] getShortestPath(String ... locations) { if (locations.length < 2) throw new Error("Please provide at least two locations for path extraction!"); DijkstraShortestPath<String, DefaultWeightedEdge> dijkstraShortestPath = new DijkstraShortestPath<String, DefaultWeightedEdge>(graph); ArrayList<PoseSteering> overallShortestPath = new ArrayList<PoseSteering>(); for (int k = 0; k < locations.length-1; k++) { GraphPath<String, DefaultWeightedEdge> gp = dijkstraShortestPath.getPath(locations[k], locations[k+1]); if (gp == null) return null; List<String> oneShortestPath = gp.getVertexList(); ArrayList<PoseSteering> allPoses = new ArrayList<PoseSteering>(); for (int i = 0; i < oneShortestPath.size()-1; i++) { //PoseSteering[] onePath = loadKnownPath(oneShortestPath.get(i),oneShortestPath.get(i+1)); PoseSteering[] onePath = paths.get(oneShortestPath.get(i)+"->"+oneShortestPath.get(i+1)); if (i == 0) allPoses.add(onePath[0]); for (int j = 1; j < onePath.length-1; j++) { allPoses.add(onePath[j]); } if (i == oneShortestPath.size()-2) allPoses.add(onePath[onePath.length-1]); } if (k == 0) overallShortestPath.add(allPoses.get(0)); for (int i = 1; i < allPoses.size(); i++) { overallShortestPath.add(allPoses.get(i)); } } return overallShortestPath.toArray(new PoseSteering[overallShortestPath.size()]); }
Example #3
Source File: GraphFunctions.java From symja_android_library with GNU General Public License v3.0 | 6 votes |
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { try { GraphExpr<ExprEdge> gex = createGraph(ast.arg1()); if (gex == null) { return F.NIL; } Graph<IExpr, ExprEdge> g = gex.toData(); DijkstraShortestPath<IExpr, ExprEdge> dijkstraAlg = new DijkstraShortestPath<>(g); SingleSourcePaths<IExpr, ExprEdge> iPaths = dijkstraAlg.getPaths(ast.arg2()); GraphPath<IExpr, ExprEdge> path = iPaths.getPath(ast.arg3()); return Object2Expr.convertList(path.getVertexList()); } catch (RuntimeException rex) { if (FEConfig.SHOW_STACKTRACE) { rex.printStackTrace(); } } return F.NIL; }
Example #4
Source File: ShortestPath.java From waltz with Apache License 2.0 | 5 votes |
private static GraphPath<EntityReference, DefaultEdge> findShortestPath(Graph<EntityReference, DefaultEdge> g, EntityReference start, EntityReference end) { DijkstraShortestPath<EntityReference, DefaultEdge> dijkstraAlg = new DijkstraShortestPath<>(g); SingleSourcePaths<EntityReference, DefaultEdge> iPaths = dijkstraAlg.getPaths(start); return iPaths.getPath(end); }
Example #5
Source File: DijkstraPointRouterFactory.java From openAGV with Apache License 2.0 | 4 votes |
@Override protected ShortestPathAlgorithm<String, ModelEdge> createShortestPathAlgorithm( Graph<String, ModelEdge> graph) { return new DijkstraShortestPath<>(graph); }
Example #6
Source File: ShortestPathTest.java From JQF with BSD 2-Clause "Simplified" License | 4 votes |
@Fuzz public void dijkstra(@GraphModel(nodes=10, weighted=true) Graph graph) { new DijkstraShortestPath<>(graph).getPaths(1); }
Example #7
Source File: DirectedGraphUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void givenDirectedGraph_whenGetDijkstraShortestPath_thenGetNotNullPath() { DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(directedGraph); List<String> shortestPath = dijkstraShortestPath.getPath("v1", "v4").getVertexList(); assertNotNull(shortestPath); }