【问题标题】:Graphhopper: ClassCastException when calculating path with CH Astar/Dikstra BiGraphhopper:使用 CH Astar/Dikstra Bi 计算路径时出现 ClassCastException
【发布时间】:2016-11-10 10:19:41
【问题描述】:

仅使用 WGS84 坐标我可以write the graph and index to disk。在另一个 java 项目中,我从磁盘读取图形和索引。这也适用于以下代码。

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());

但是,首先我想知道为什么收缩层次结构的准备需要这么多时间。我原以为已经做好了准备。这又做完了吗?名为“shortcuts_fastest_car”的文件的用途是什么?

其次,一旦调用了algorithm.calcPath,我就会收到一个令人困惑的ClassCastException。

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)

怎么了?是否缺少一些配置标志?

【问题讨论】:

    标签: graphhopper


    【解决方案1】:

    我认为你必须通过 CH 图

    graph.getGraph(CHGraphImpl.class)

    而不仅仅是 graph 到 QueryGraph 构造函数。

    【讨论】:

    • 谢谢彼得。那成功了。如果documentation 可以反映代码的最新更改,那就太好了。
    • 完成。当从磁盘读回已经准备好的文件时,PrepareContractionHierarchies 是否真的不需要 doWork() ?
    • 是的(也许我们应该切换到我们的论坛进行讨论)
    猜你喜欢
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    • 2019-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 2011-06-22
    相关资源
    最近更新 更多