void checkAlternatives(List<AlternativeRoute.AlternativeInfo> alternativeInfos) { assertFalse("alternativeInfos should contain alternatives", alternativeInfos.isEmpty()); AlternativeRoute.AlternativeInfo bestInfo = alternativeInfos.get(0); for (int i = 1; i < alternativeInfos.size(); i++) { AlternativeRoute.AlternativeInfo a = alternativeInfos.get(i); if (a.getPath().getWeight() < bestInfo.getPath().getWeight()) assertTrue("alternative is not longer -> " + a + " vs " + bestInfo, false); if (a.getShareWeight() > bestInfo.getPath().getWeight() || a.getShareWeight() > a.getPath().getWeight()) assertTrue("share or sortby incorrect -> " + a + " vs " + bestInfo, false); } }
@Test public void testWeightLimit_issue380() { GraphHopperStorage graph = createGHStorage(false); initGraphWeightLimit(graph); DijkstraOneToMany algo = (DijkstraOneToMany) createAlgo(graph); algo.setWeightLimit(3); Path p = algo.calcPath(0, 4); assertTrue(p.isFound()); assertEquals(3.0, p.getWeight(), 1e-6); algo = (DijkstraOneToMany) createAlgo(graph); p = algo.calcPath(0, 3); assertTrue(p.isFound()); assertEquals(3.0, p.getWeight(), 1e-6); }
@Test public void testCalcAlternatives() throws Exception { Weighting weighting = new FastestWeighting(carFE); GraphHopperStorage g = createTestGraph(true, em); AlternativeRoute altDijkstra = new AlternativeRoute(g, weighting, traversalMode); altDijkstra.setMaxShareFactor(0.5); altDijkstra.setMaxWeightFactor(2); List<AlternativeRoute.AlternativeInfo> pathInfos = altDijkstra.calcAlternatives(5, 4); checkAlternatives(pathInfos); assertEquals(2, pathInfos.size()); DijkstraBidirectionRef dijkstra = new DijkstraBidirectionRef(g, weighting, traversalMode); Path bestPath = dijkstra.calcPath(5, 4); Path bestAlt = pathInfos.get(0).getPath(); Path secondAlt = pathInfos.get(1).getPath(); assertEquals(bestPath.calcNodes(), bestAlt.calcNodes()); assertEquals(bestPath.getWeight(), bestAlt.getWeight(), 1e-3); assertEquals(IntArrayList.from(new int[]{5, 6, 3, 4}), bestAlt.calcNodes()); // Note: here plateau is longer, even longer than optimum, but path is longer // so which alternative is better? longer plateau.weight with bigger path.weight or smaller path.weight with smaller plateau.weight // assertEquals(Helper.createTList(5, 1, 9, 2, 3, 4), secondAlt.calcNodes()); assertEquals(IntArrayList.from(new int[]{5, 6, 7, 8, 4}), secondAlt.calcNodes()); assertEquals(1667.9, secondAlt.getWeight(), .1); }
fullTimeInMillis += path.getTime(); fullDistance += path.getDistance(); fullWeight += path.getWeight(); if (enableInstructions) { InstructionList il = path.calcInstructions(tr);
@Test public void testCalcAlternatives2() throws Exception { Weighting weighting = new FastestWeighting(carFE); Graph g = createTestGraph(true, em); AlternativeRoute altDijkstra = new AlternativeRoute(g, weighting, traversalMode); altDijkstra.setMaxPaths(3); altDijkstra.setMaxShareFactor(0.7); altDijkstra.setMinPlateauFactor(0.15); altDijkstra.setMaxWeightFactor(2); // edge based traversal requires a bit more exploration than the default of 1 altDijkstra.setMaxExplorationFactor(1.2); List<AlternativeRoute.AlternativeInfo> pathInfos = altDijkstra.calcAlternatives(5, 4); checkAlternatives(pathInfos); assertEquals(3, pathInfos.size()); // result is sorted based on the plateau to full weight ratio assertEquals(IntArrayList.from(new int[]{5, 6, 3, 4}), pathInfos.get(0).getPath().calcNodes()); assertEquals(IntArrayList.from(new int[]{5, 6, 7, 8, 4}), pathInfos.get(1).getPath().calcNodes()); assertEquals(IntArrayList.from(new int[]{5, 1, 9, 2, 3, 4}), pathInfos.get(2).getPath().calcNodes()); assertEquals(2416.0, pathInfos.get(2).getPath().getWeight(), .1); }
Path path = oneDirAlgoWithLandmarks.calcPath(41, 183); assertEquals(expectedPath.getWeight(), path.getWeight(), .1); assertEquals(expectedPath.calcNodes(), path.calcNodes()); assertEquals(expectedAlgo.getVisitedNodes(), oneDirAlgoWithLandmarks.getVisitedNodes() + 142); new AStarBidirection(graph, weighting, tm), opts); path = biDirAlgoWithLandmarks.calcPath(41, 183); assertEquals(expectedPath.getWeight(), path.getWeight(), .1); assertEquals(expectedPath.calcNodes(), path.calcNodes()); assertEquals(expectedAlgo.getVisitedNodes(), biDirAlgoWithLandmarks.getVisitedNodes() + 164); assertEquals(expectedPath.getWeight(), path.getWeight(), .1); assertEquals(expectedPath.calcNodes(), path.calcNodes()); assertEquals(expectedAlgo.getVisitedNodes(), qGraphOneDirAlgo.getVisitedNodes() + 133);
@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); }
assertEquals(37009621, p.getTime()); assertEquals(616827, p.getDistance(), 1); assertEquals(493462, p.getWeight(), 1);
fullTimeInMillis += path.getTime(); fullDistance += path.getDistance(); fullWeight += path.getWeight(); if (enableInstructions) { InstructionList il = path.calcInstructions(tr);
fullTimeInMillis += path.getTime(); fullDistance += path.getDistance(); fullWeight += path.getWeight(); if (enableInstructions) { InstructionList il = path.calcInstructions(tr);
fullTimeInMillis += path.getTime(); fullDistance += path.getDistance(); fullWeight += path.getWeight(); if (enableInstructions)