algorithm(algoStr).traversalMode(tMode).weighting(weighting). maxVisitedNodes(maxVisitedNodesForRequest). hints(hints).
AlgorithmOptions opts = AlgorithmOptions.start().weighting(weighting).traversalMode(tm). build();
@Test public void testBlockANode() { GraphHopperStorage g = createStorage(createEncodingManager(true)); initGraph(g); TurnCostExtension tcs = (TurnCostExtension) g.getExtension(); blockNode3(g, tcs, carEncoder); for (int i=0; i<=7; i++) { if (i==3) continue; for (int j=0; j<=7; j++) { if (j==3) continue; Path p = createAlgo(g, AlgorithmOptions.start(). weighting(createWeighting(carEncoder, tcs, 40)). traversalMode(TraversalMode.EDGE_BASED_2DIR).build()). calcPath(i, j); assertTrue(p.isFound()); // We can go from everywhere to everywhere else without using node 3 for (IntCursor node : p.calcNodes()) { assertNotEquals(p.calcNodes().toString(), 3, node.value); } } } }
algorithm(algoStr).traversalMode(tMode).weighting(weighting). maxVisitedNodes(maxVisitedNodesForRequest). hints(hints).
algorithm(algoStr).traversalMode(tMode).weighting(weighting). maxVisitedNodes(maxVisitedNodesForRequest). hints(hints).
algorithm(algoStr).traversalMode(tMode).flagEncoder(encoder).weighting(weighting). maxVisitedNodes(maxVisitedNodesForRequest). hints(hints).
.traversalMode(graphHopper.getTraversalMode()) .maxVisitedNodes(maxVisitedNodes) .hints(new HintsMap().put("vehicle", vehicleStr))
algorithm(Parameters.Algorithms.DIJKSTRA_BI).traversalMode(hopper.getTraversalMode()). weighting(new FastestWeighting(firstEncoder)). maxVisitedNodes(args.getInt("max_visited_nodes")).
/** * This method clones the specified AlgorithmOption object with the possibility for further * changes. */ public static Builder start(AlgorithmOptions opts) { Builder b = new Builder(); if (opts.algorithm != null) b.algorithm(opts.getAlgorithm()); if (opts.traversalMode != null) b.traversalMode(opts.getTraversalMode()); if (opts.weighting != null) b.weighting(opts.getWeighting()); if (opts.maxVisitedNodes >= 0) b.maxVisitedNodes(opts.maxVisitedNodes); if (!opts.hints.isEmpty()) b.hints(opts.hints); return b; }
/** * This method clones the specified AlgorithmOption object with the possibility for further * changes. */ public static Builder start(AlgorithmOptions opts) { Builder b = new Builder(); if (opts.algorithm != null) b.algorithm(opts.getAlgorithm()); if (opts.traversalMode != null) b.traversalMode(opts.getTraversalMode()); if (opts.weighting != null) b.weighting(opts.getWeighting()); if (opts.maxVisitedNodes >= 0) b.maxVisitedNodes(opts.maxVisitedNodes); if (!opts.hints.isEmpty()) b.hints(opts.hints); return b; }
/** * This method clones the specified AlgorithmOption object with the possibility for further * changes. */ public static Builder start( AlgorithmOptions opts ) { Builder b = new Builder(); if (opts.algorithm != null) b.algorithm(opts.getAlgorithm()); if (opts.flagEncoder != null) b.flagEncoder(opts.getFlagEncoder()); if (opts.traversalMode != null) b.traversalMode(opts.getTraversalMode()); if (opts.weighting != null) b.weighting(opts.getWeighting()); if (opts.maxVisitedNodes >= 0) b.maxVisitedNodes(opts.maxVisitedNodes); return b; }
traversalMode(TraversalMode.EDGE_BASED_2DIR).build()). calcPath(5, 1); assertEquals(IntArrayList.from(new int[]{5, 6, 7, 4, 3, 1}), p.calcNodes());
@Test public void testBasicTurnRestriction() { GraphHopperStorage g = createStorage(createEncodingManager(true)); initGraph(g); TurnCostExtension tcs = (TurnCostExtension) g.getExtension(); initTurnRestrictions(g, tcs, carEncoder); Path p = createAlgo(g, AlgorithmOptions.start(). weighting(createWeighting(carEncoder, tcs, 40)). traversalMode(TraversalMode.EDGE_BASED_2DIR).build()). calcPath(5, 1); assertEquals(IntArrayList.from(new int[]{5, 2, 3, 4, 7, 6, 3, 1}), p.calcNodes()); // test 7-6-5 and reverse p = createAlgo(g, AlgorithmOptions.start(). weighting(createWeighting(carEncoder, tcs, 40)). traversalMode(TraversalMode.EDGE_BASED_1DIR).build()). calcPath(5, 7); assertEquals(IntArrayList.from(new int[]{5, 6, 7}), p.calcNodes()); p = createAlgo(g, AlgorithmOptions.start(). weighting(createWeighting(carEncoder, tcs, 40)). traversalMode(TraversalMode.EDGE_BASED_1DIR).build()). calcPath(7, 5); assertEquals(IntArrayList.from(new int[]{7, 6, 3, 2, 5}), p.calcNodes()); }
@Test public void testBasicTurnCosts() { GraphHopperStorage g = createStorage(createEncodingManager(false)); initGraph(g); TurnCostExtension tcs = (TurnCostExtension) g.getExtension(); Path p = createAlgo(g, AlgorithmOptions.start(). weighting(createWeighting(carEncoder, tcs, 40)). traversalMode(TraversalMode.EDGE_BASED_1DIR).build()). calcPath(5, 1); // no restriction and costs EdgeIteratorState e3_6 = getEdge(g, 5, 6); e3_6.setDistance(2); assertEquals(IntArrayList.from(new int[]{5, 2, 3, 1}), p.calcNodes()); // now introduce some turn costs long tflags = carEncoder.getTurnFlags(false, 2); tcs.addTurnInfo(getEdge(g, 5, 2).getEdge(), 2, getEdge(g, 2, 3).getEdge(), tflags); p = createAlgo(g, AlgorithmOptions.start(). weighting(createWeighting(carEncoder, tcs, 40)). traversalMode(TraversalMode.EDGE_BASED_1DIR).build()). calcPath(5, 1); assertEquals(IntArrayList.from(new int[]{5, 6, 3, 1}), p.calcNodes()); }
@Test public void testUTurns() { GraphHopperStorage g = createStorage(createEncodingManager(true)); initGraph(g); TurnCostExtension tcs = (TurnCostExtension) g.getExtension(); long tflags = carEncoder.getTurnFlags(true, 0); // force u-turn via lowering the cost for it EdgeIteratorState e3_6 = getEdge(g, 3, 6); e3_6.setDistance(0.1); getEdge(g, 3, 2).setDistance(864); getEdge(g, 1, 0).setDistance(864); tcs.addTurnInfo(getEdge(g, 7, 6).getEdge(), 6, getEdge(g, 6, 5).getEdge(), tflags); tcs.addTurnInfo(getEdge(g, 4, 3).getEdge(), 3, e3_6.getEdge(), tflags); AlgorithmOptions opts = AlgorithmOptions.start(). weighting(createWeighting(carEncoder, tcs, 50)). traversalMode(TraversalMode.EDGE_BASED_2DIR_UTURN).build(); Path p = createAlgo(g, opts).calcPath(7, 5); assertEquals(IntArrayList.from(new int[]{7, 6, 3, 6, 5}), p.calcNodes()); // no u-turn for 6-3 opts = AlgorithmOptions.start(). weighting(createWeighting(carEncoder, tcs, 100)). traversalMode(TraversalMode.EDGE_BASED_2DIR_UTURN).build(); tcs.addTurnInfo(getEdge(g, 6, 3).getEdge(), 3, getEdge(g, 3, 6).getEdge(), tflags); p = createAlgo(g, opts).calcPath(7, 5); assertEquals(IntArrayList.from(new int[]{7, 6, 3, 2, 5}), p.calcNodes()); }
/** * This method clones the specified AlgorithmOption object with the possibility for further * changes. */ public static Builder start(AlgorithmOptions opts) { Builder b = new Builder(); if (opts.algorithm != null) b.algorithm(opts.getAlgorithm()); if (opts.traversalMode != null) b.traversalMode(opts.getTraversalMode()); if (opts.weighting != null) b.weighting(opts.getWeighting()); if (opts.maxVisitedNodes >= 0) b.maxVisitedNodes(opts.maxVisitedNodes); if (!opts.hints.isEmpty()) b.hints(opts.hints); return b; }