+ path.calcNodes().size() + ", millis: " + path.getTime() + ", visited nodes:" + algo.getVisitedNodes()); g2.setColor(red);
fullTimeInMillis += path.getTime(); fullDistance += path.getDistance(); fullWeight += path.getWeight();
@Test public void testCalcFootPath() { AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new ShortestWeighting(footEncoder)).build(); GraphHopperStorage ghStorage = createGHStorage(encodingManager, Arrays.asList(opts.getWeighting()), false); initFootVsCar(ghStorage); Path p1 = createAlgo(ghStorage, opts). calcPath(0, 7); assertEquals(p1.toString(), 17000, p1.getDistance(), 1e-6); assertEquals(p1.toString(), 12240 * 1000, p1.getTime()); assertEquals(IntArrayList.from(new int[]{0, 4, 5, 7}), p1.calcNodes()); }
@Test public void testCalcFastestPath() { GraphHopperStorage graphShortest = createGHStorage(false); initDirectedAndDiffSpeed(graphShortest, carEncoder); Path p1 = createAlgo(graphShortest, defaultOpts). calcPath(0, 3); assertEquals(IntArrayList.from(new int[]{0, 1, 5, 2, 3}), p1.calcNodes()); assertEquals(p1.toString(), 402.3, p1.getDistance(), .1); assertEquals(p1.toString(), 144823, p1.getTime()); AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new FastestWeighting(carEncoder)).build(); GraphHopperStorage graphFastest = createGHStorage(encodingManager, Arrays.asList(opts.getWeighting()), false); initDirectedAndDiffSpeed(graphFastest, carEncoder); Path p2 = createAlgo(graphFastest, opts). calcPath(0, 3); assertEquals(IntArrayList.from(new int[]{0, 4, 6, 7, 5, 3}), p2.calcNodes()); assertEquals(p2.toString(), 1261.7, p2.getDistance(), 0.1); assertEquals(p2.toString(), 111442, p2.getTime()); }
@Test public void testTwoWeightsPerEdge() { FlagEncoder encoder = new Bike2WeightFlagEncoder(); EncodingManager em = new EncodingManager(encoder); AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new FastestWeighting(encoder)).build(); GraphHopperStorage graph = createGHStorage(em, Arrays.asList(opts.getWeighting()), true); initEleGraph(graph); // force the other path GHUtility.getEdge(graph, 0, 3).setFlags(encoder.setProperties(10, false, true)); // for two weights per edge it happened that Path (and also the Weighting) read the wrong side // of the speed and read 0 => infinity weight => overflow of millis => negative millis! Path p = createAlgo(graph, opts). calcPath(0, 10); assertEquals(85124371, p.getTime()); assertEquals(425622, p.getDistance(), 1); assertEquals(85124.4, p.getWeight(), 1); }
@Test public void testBaseGraph() { CarFlagEncoder carFE = new CarFlagEncoder(); EncodingManager em = new EncodingManager(carFE); AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new ShortestWeighting(carFE)).build(); GraphHopperStorage ghStorage = createGHStorage(em, Arrays.asList(opts.getWeighting()), false); initDirectedAndDiffSpeed(ghStorage, carFE); // do CH preparation for car createFactory(ghStorage, opts); // use base graph for solving normal Dijkstra Path p1 = new RoutingAlgorithmFactorySimple().createAlgo(ghStorage, defaultOpts).calcPath(0, 3); assertEquals(IntArrayList.from(0, 1, 5, 2, 3), p1.calcNodes()); assertEquals(p1.toString(), 402.29, p1.getDistance(), 1e-2); assertEquals(p1.toString(), 144823, p1.getTime()); }
assertEquals(34000, sumDistances(wayList), 1e-1); assertEquals(5, gpxList.size()); assertEquals(1604120, p.getTime()); assertEquals(1604120, gpxList.get(gpxList.size() - 1).getTime());
@Test public void testBaseGraphMultipleVehicles() { AlgorithmOptions footOptions = AlgorithmOptions.start(). weighting(new FastestWeighting(footEncoder)).build(); AlgorithmOptions carOptions = AlgorithmOptions.start(). weighting(new FastestWeighting(carEncoder)).build(); GraphHopperStorage g = createGHStorage(encodingManager, Arrays.asList(footOptions.getWeighting(), carOptions.getWeighting()), false); initFootVsCar(g); // do CH preparation for car RoutingAlgorithmFactory contractedFactory = createFactory(g, carOptions); // use contracted graph Path p1 = contractedFactory.createAlgo(getGraph(g, carOptions.getWeighting()), carOptions).calcPath(0, 7); assertEquals(IntArrayList.from(0, 4, 6, 7), p1.calcNodes()); assertEquals(p1.toString(), 15000, p1.getDistance(), 1e-6); // use base graph for solving normal Dijkstra via car Path p2 = new RoutingAlgorithmFactorySimple().createAlgo(g, carOptions).calcPath(0, 7); assertEquals(IntArrayList.from(0, 4, 6, 7), p2.calcNodes()); assertEquals(p2.toString(), 15000, p2.getDistance(), 1e-6); assertEquals(p2.toString(), 2700 * 1000, p2.getTime()); // use base graph for solving normal Dijkstra via foot Path p3 = new RoutingAlgorithmFactorySimple().createAlgo(g, footOptions).calcPath(0, 7); assertEquals(p3.toString(), 17000, p3.getDistance(), 1e-6); assertEquals(p3.toString(), 12240 * 1000, p3.getTime()); assertEquals(IntArrayList.from(0, 4, 5, 7), p3.calcNodes()); }
p = factory.createAlgo(qGraph, fakeOpts).calcPath(from.getClosestNode(), to.getClosestNode()); assertEquals(IntArrayList.from(new int[]{12, 0, 1, 2, 11, 7, 10, 13}), p.calcNodes()); assertEquals(37009621, p.getTime()); assertEquals(616827, p.getDistance(), 1); assertEquals(493462, p.getWeight(), 1);
calcPath(5, 1); assertEquals(IntArrayList.from(new int[]{5, 6, 7, 4, 3, 1}), p.calcNodes()); assertEquals(301, p.getTime(), .1);
assertEquals(1064, p.getTime()); assertEquals(4.2, p.getDistance(), 1e-5);
private DistanceTime unpackSingleEdge2DistTime(int tmpEdge, int endNode, boolean isReverseOrder) { Path tmpPath = unpackSingleEdge(routingGraph, routingGraph.getBaseGraph(), encoder, tmpEdge, endNode,isReverseOrder); DistanceTime dtTmp = new DistanceTime(tmpPath.getDistance(), tmpPath.getTime()); return dtTmp; }
private MatchResult computeMatchResult(List<SequenceState<GPXExtension, GPXEntry, Path>> seq, Map<String, EdgeIteratorState> virtualEdgesMap, List<GPXEntry> gpxList, QueryGraph queryGraph) { double distance = 0.0; long time = 0; for (SequenceState<GPXExtension, GPXEntry, Path> transitionAndState : seq) { if (transitionAndState.transitionDescriptor != null) { distance += transitionAndState.transitionDescriptor.getDistance(); time += transitionAndState.transitionDescriptor.getTime(); } } List<EdgeIteratorState> edges = new ArrayList<>(); for (SequenceState<GPXExtension, GPXEntry, Path> state : seq) { if (state.transitionDescriptor != null) { edges.addAll(state.transitionDescriptor.calcEdges()); } } Path mergedPath = new MapMatchedPath(queryGraph.getBaseGraph(), weighting, edges); List<EdgeMatch> edgeMatches = computeEdgeMatches(seq, virtualEdgesMap); MatchResult matchResult = new MatchResult(edgeMatches); matchResult.setMergedPath(mergedPath); matchResult.setMatchMillis(time); matchResult.setMatchLength(distance); matchResult.setGPXEntriesMillis(durationMillis(gpxList)); matchResult.setGPXEntriesLength(gpxLength(gpxList)); return matchResult; }
private MatchResult computeMatchResult(List<SequenceState<GPXExtension, GPXEntry, Path>> seq, Map<String, EdgeIteratorState> virtualEdgesMap, List<GPXEntry> gpxList, QueryGraph queryGraph) { double distance = 0.0; long time = 0; for (SequenceState<GPXExtension, GPXEntry, Path> transitionAndState : seq) { if (transitionAndState.transitionDescriptor != null) { distance += transitionAndState.transitionDescriptor.getDistance(); time += transitionAndState.transitionDescriptor.getTime(); } } List<EdgeIteratorState> edges = new ArrayList<>(); for (SequenceState<GPXExtension, GPXEntry, Path> state : seq) { if (state.transitionDescriptor != null) { edges.addAll(state.transitionDescriptor.calcEdges()); } } Path mergedPath = new MapMatchedPath(queryGraph.getBaseGraph(), weighting, edges); List<EdgeMatch> edgeMatches = computeEdgeMatches(seq, virtualEdgesMap); MatchResult matchResult = new MatchResult(edgeMatches); matchResult.setMergedPath(mergedPath); matchResult.setMatchMillis(time); matchResult.setMatchLength(distance); matchResult.setGPXEntriesMillis(durationMillis(gpxList)); matchResult.setGPXEntriesLength(gpxLength(gpxList)); return matchResult; }
if (path.getTime() < 0) throw new RuntimeException("Time was negative. Please report as bug and include:" + ghRequest);
if (path.getTime() < 0) throw new RuntimeException("Time was negative. Please report as bug and include:" + ghRequest);
fullTimeInMillis += path.getTime(); fullDistance += path.getDistance(); fullWeight += path.getWeight();
Path path = paths.get(pathIndex); description.addAll(path.getDescription()); fullTimeInMillis += path.getTime(); fullDistance += path.getDistance(); fullWeight += path.getWeight();