コード例 #1
0
 @Override
 public RoutingAlgorithmFactory createFactory(
     GraphHopperStorage ghStorage, AlgorithmOptions opts) {
   PrepareContractionHierarchies ch =
       new PrepareContractionHierarchies(
           new GHDirectory("", DAType.RAM_INT),
           ghStorage,
           getGraph(ghStorage, opts.getWeighting()),
           opts.getFlagEncoder(),
           opts.getWeighting(),
           TraversalMode.NODE_BASED);
   ch.doWork();
   return ch;
 }
コード例 #2
0
  @Test
  public void testBaseGraph() {
    CarFlagEncoder carFE = new CarFlagEncoder();
    AlgorithmOptions opts =
        AlgorithmOptions.start().flagEncoder(carFE).weighting(new ShortestWeighting(carFE)).build();
    GraphHopperStorage ghStorage =
        createGHStorage(
            new EncodingManager(carFE), Collections.singleton(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(Helper.createTList(0, 1, 5, 2, 3), p1.calcNodes());
    assertEquals(p1.toString(), 402.29, p1.getDistance(), 1e-2);
    assertEquals(p1.toString(), 144823, p1.getTime());
  }
コード例 #3
0
  @Test
  public void testBaseGraphMultipleVehicles() {
    AlgorithmOptions footOptions =
        AlgorithmOptions.start()
            .flagEncoder(footEncoder)
            .weighting(new FastestWeighting(footEncoder))
            .build();
    AlgorithmOptions carOptions =
        AlgorithmOptions.start()
            .flagEncoder(carEncoder)
            .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(Helper.createTList(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(Helper.createTList(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(Helper.createTList(0, 4, 5, 7), p3.calcNodes());
  }