/** * Create a new storage from the specified one without copying the data. */ public static GraphHopperStorage newStorage(GraphHopperStorage store) { Directory outdir = guessDirectory(store); boolean is3D = store.getNodeAccess().is3D(); return new GraphHopperStorage(store.getCHWeightings(), outdir, store.getEncodingManager(), is3D, store.getExtension()). create(store.getNodes()); }
for (String gtfsFile : gtfsFiles) { try { ((GtfsStorage) graphHopperStorage.getExtension()).loadGtfsFromFile("gtfs_" + id++, new ZipFile(gtfsFile)); } catch (IOException e) { throw new RuntimeException(e);
@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); } } } }
@Test public void testMergeFlagsBeforeAdding() { FlagEncoder carEncoder = new CarFlagEncoder(5, 5, 3); FlagEncoder bikeEncoder = new BikeFlagEncoder(5, 5, 3); EncodingManager manager = new EncodingManager(carEncoder, bikeEncoder); GraphHopperStorage g = new GraphBuilder(manager).create(); initGraph(g); TurnCostExtension tcs = (TurnCostExtension) g.getExtension(); long carRestricted = carEncoder.getTurnFlags(true, 0); long bikeRestricted = bikeEncoder.getTurnFlags(true, 0); int edge23 = getEdge(g, 2, 3).getEdge(); int edge02 = getEdge(g, 0, 2).getEdge(); tcs.addTurnInfo(edge02, 2, edge23, carRestricted | bikeRestricted); long flags023 = tcs.getTurnCostFlags(edge02, 2, edge23); assertEquals(Double.POSITIVE_INFINITY, carEncoder.getTurnCost(flags023), 0); assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags023), 0); } }
@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 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 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()); }
final GraphHopperStorage g = createStorage(createEncodingManager(false)); initGraph(g); TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
GraphHopperStorage g = new GraphBuilder(manager).create(); initGraph(g); TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
/** * Create a new storage from the specified one without copying the data. */ public static GraphHopperStorage newStorage(GraphHopperStorage store) { Directory outdir = guessDirectory(store); boolean is3D = store.getNodeAccess().is3D(); return new GraphHopperStorage(store.getCHWeightings(), outdir, store.getEncodingManager(), is3D, store.getExtension()). create(store.getNodes()); }
/** * Create a new storage from the specified one without copying the data. */ public static GraphHopperStorage newStorage( GraphHopperStorage store ) { Directory outdir = guessDirectory(store); boolean is3D = store.getNodeAccess().is3D(); return new GraphHopperStorage(store.getCHWeightings(), outdir, store.getEncodingManager(), is3D, store.getExtension()). create(store.getNodes()); }
/** * Create a new storage from the specified one without copying the data. */ public static GraphHopperStorage newStorage(GraphHopperStorage store) { Directory outdir = guessDirectory(store); boolean is3D = store.getNodeAccess().is3D(); return new GraphHopperStorage(store.getCHWeightings(), outdir, store.getEncodingManager(), is3D, store.getExtension()). create(store.getNodes()); }