Graphhopper:使用CH Astar/Dikstra Bi计算路径时,ClassCastException [英] Graphhopper: ClassCastException when calculating path with CH Astar/Dikstra Bi

查看:232
本文介绍了Graphhopper:使用CH Astar/Dikstra Bi计算路径时,ClassCastException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅使用WGS84坐标,我就可以将图形和索引写入磁盘.在另一个Java项目中,我从磁盘读取图形和索引.使用以下代码也可以正常工作.

Using only WGS84 coordinates I can write the graph and index to disk. In another java project I read graph and index from disk. This also works fine with the following code.

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"的文件的用途是什么?

However, first I wonder why the preparation of the contraction hierarchies needs so much time. I would have expected that the preparation had been done already. Is this done again? What's the purpose of the file named "shortcuts_fastest_car"?

第二,一旦调用algorithm.calcPath,我会收到一个令人困惑的ClassCastException.

Second, I receive a confusing ClassCastException once algorithm.calcPath is called.

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)

出了什么问题?是否缺少一些配置标志?

What's going wrong? Is there some config flag missing?

推荐答案

我认为您必须通过CH图

I think you have to pass the CH graph

graph.getGraph(CHGraphImpl.class)

而不是QueryGraph构造函数的graph.

instead of just graph to the QueryGraph constructor.

这篇关于Graphhopper:使用CH Astar/Dikstra Bi计算路径时,ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆