Currently i am using GraphHopper for movement trip simulation and i am using just the core library.
My question is does GraphHopper can fetch all possible path from origin to destination? Because when i run the code below, it only return 2 from 3 expected paths.
For example:
from JKT-BGR to JKT-MRD, should generate following possible paths:
JKT-BGR -> JKT-CAW -> JKT-KML -> JKT-MRD
JKT-BGR -> JKT-KSI -> JKT-KML -> JKT-MRD
JKT-BGR -> JKT-KSI -> JKT-DPK -> JKT-MRD
my code:
public class GraphHopperTest {
static String stringify(Map<Integer, String> nodeMap, Path path) {
String result = "";
IntIndexedContainer vertexList = path.calcNodes();
if (vertexList != null && !vertexList.isEmpty()) {
for (int i = 0; i < vertexList.size(); i++) {
result += nodeMap.get(vertexList.get(i));
if (i != vertexList.size() - 1) {
result = result + " -> ";
}
}
}
return result;
}
public static void main(String[] args) {
final EncodingManager encodingManager = EncodingManager.create("car");
final FlagEncoder carEncoder = encodingManager.getEncoder("car");
Weighting defaultWeighting = new ShortestWeighting(carEncoder);
Map<Integer, String> nodeMap = new HashMap<>();
nodeMap.put(1, "JKT-BGR");
nodeMap.put(2, "JKT-CAW");
nodeMap.put(3, "JKT-DPK");
nodeMap.put(4, "JKT-KML");
nodeMap.put(5, "JKT-KSI");
nodeMap.put(6, "JKT-MRD");
GraphHopperStorage G = new GraphBuilder(encodingManager).create();
G.edge(1, 2, 1, false);
G.edge(1, 5, 1, false);
G.edge(2, 4, 1, false);
G.edge(5, 4, 1, false);
G.edge(5, 3, 1, false);
G.edge(4, 6, 1, false);
G.edge(3, 6, 1, false);
Set<IntIndexedContainer> uniquePaths = new HashSet<>();
RoutingAlgorithm algo1 = new AlternativeRoute(G, defaultWeighting, TraversalMode.NODE_BASED);
List<Path> paths1 = algo1.calcPaths(1, 6);
System.out.println("GH - Traversal mode = NODE_BASED");
for (Path p:paths1) {
uniquePaths.add(p.calcNodes());
System.out.println(stringify(nodeMap, p));
}
}
}