En utilisant uniquement les coordonnées WGS84 je peux write the graph and index to disk. Dans un autre projet java, j'ai lu graph et index à partir du disque. Cela fonctionne également très bien avec le code suivant.Graphhopper: ClassCastException lors du calcul du chemin avec CH Astar/Dikstra Bi
FlagEncoder encoder = new CarFlagEncoder();
EncodingManager em = new EncodingManager(encoder);
GraphBuilder gb = new GraphBuilder(em).
setLocation(testDir).
setStore(true).
setCHGraph(new FastestWeighting(encoder));
// Load and use the graph
GraphHopperStorage graph = gb.load();
// Load index
LocationIndex index = new LocationIndexTree(graph.getBaseGraph(), graph.getDirectory());
if (!index.loadExisting())
throw new IllegalStateException("location index cannot be loaded!");
AlgorithmOptions algoOpts = AlgorithmOptions.start().algorithm(Parameters.Algorithms.ASTAR_BI).
traversalMode(TraversalMode.NODE_BASED).
weighting(new FastestWeighting(encoder)).
build();
PrepareContractionHierarchies pch = new PrepareContractionHierarchies(graph.getDirectory(), graph, graph.getGraph(CHGraphImpl.class), new FastestWeighting(encoder), TraversalMode.NODE_BASED);
pch.doWork();
QueryResult fromQR = index.findClosest(fromCoordinate.x, fromCoordinate.y, EdgeFilter.ALL_EDGES);
QueryResult toQR = index.findClosest(toCoordinate.x, toCoordinate.y, EdgeFilter.ALL_EDGES);
QueryGraph queryGraph = new QueryGraph(graph);
queryGraph.lookup(fromQR, toQR);
RoutingAlgorithm algorithm = pch.createAlgo(queryGraph, algoOpts);
Path path = algorithm.calcPath(fromQR.getClosestNode(), toQR.getClosestNode());
Cependant, je me demande d'abord pourquoi la préparation des hiérarchies de contraction a besoin de beaucoup de temps. Je m'attendrais à ce que la préparation ait déjà été faite. Est-ce fait à nouveau? Quel est le but du fichier nommé "shortcuts_fastest_car"?
Deuxièmement, je reçois un ClassCastException
confus une fois que algorithm.calcPath
est appelée.
Exception in thread "main" java.lang.ClassCastException: com.graphhopper.storage.BaseGraph$EdgeIterable cannot be cast to com.graphhopper.util.CHEdgeIteratorState
at com.graphhopper.routing.util.LevelEdgeFilter.accept(LevelEdgeFilter.java:48)
at com.graphhopper.routing.AbstractRoutingAlgorithm.accept(AbstractRoutingAlgorithm.java:79)
at com.graphhopper.routing.AStarBidirection.fillEdges(AStarBidirection.java:217)
at com.graphhopper.routing.AStarBidirection.fillEdgesFrom(AStarBidirection.java:194)
at com.graphhopper.routing.AbstractBidirAlgo.runAlgo(AbstractBidirAlgo.java:68)
at com.graphhopper.routing.AbstractBidirAlgo.calcPath(AbstractBidirAlgo.java:61)
Qu'est-ce qui ne va pas? Y a-t-il un drapeau de configuration manquant?
Merci Peter. Cela a fait l'affaire. Ce serait génial si la [documentation] (https://github.com/graphhopper/graphhopper/blob/master/docs/core/low-level-api.md) pouvait refléter les dernières modifications du code. – Andreas
Ah, oui. Pourriez-vous faire une demande d'extraction :)? – Karussell
Terminé. Est-il vrai que le PrepareContractionHierarchies ne nécessite pas le doWork() lorsque les fichiers déjà préparés sont lus à partir du disque? – Andreas