@Test
  public void testDifferentEdgeFilter() {
    Graph g = new GraphBuilder(encodingManager).levelGraphCreate();
    g.edge(4, 3, 10, true);
    g.edge(3, 6, 10, true);

    g.edge(4, 5, 10, true);
    g.edge(5, 6, 10, true);

    AlgorithmPreparation prep = prepareGraph(g);
    DijkstraOneToMany algo = (DijkstraOneToMany) prep.createAlgo();
    algo.setEdgeFilter(
        new EdgeFilter() {
          @Override
          public boolean accept(EdgeIteratorState iter) {
            return iter.getAdjNode() != 5;
          }
        });
    Path p = algo.calcPath(4, 6);
    assertEquals(Helper.createTList(4, 3, 6), p.calcNodes());

    // important call!
    algo.clear();
    algo.setEdgeFilter(
        new EdgeFilter() {
          @Override
          public boolean accept(EdgeIteratorState iter) {
            return iter.getAdjNode() != 3;
          }
        });
    p = algo.calcPath(4, 6);
    assertEquals(Helper.createTList(4, 5, 6), p.calcNodes());
  }
  @Test
  public void testAddSkipNodes() {
    Graph g = createWikipediaTestGraph();
    Path p = prepareGraph(g).createAlgo().calcPath(0, 4);
    assertEquals(p.toString(), 20, p.weight(), 1e-6);
    assertTrue(p.toString(), p.calcNodes().contains(5));

    DijkstraBidirectionRef db = new DijkstraBidirectionRef(g);
    db.addSkipNode(5);
    p = db.calcPath(0, 4);
    assertFalse(p.toString(), p.calcNodes().contains(5));
    assertEquals(Helper.createTList(0, 2, 3, 4), p.calcNodes());
  }
  @Test
  public void testUseCache() {
    AlgorithmPreparation prep = prepareGraph(createTestGraph());
    RoutingAlgorithm algo = prep.createAlgo();
    Path p = algo.calcPath(0, 4);
    assertEquals(Helper.createTList(0, 4), p.calcNodes());

    // expand SPT
    p = algo.calcPath(0, 7);
    assertEquals(Helper.createTList(0, 4, 6, 5, 7), p.calcNodes());

    // use SPT
    p = algo.calcPath(0, 2);
    assertEquals(Helper.createTList(0, 1, 2), p.calcNodes());
  }
  @Test
  public void testPathRecursiveUnpacking() {
    // use an encoder where it is possible to store 2 weights per edge
    FlagEncoder encoder = new Bike2WeightFlagEncoder();
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    EncodingManager em = new EncodingManager(encoder);
    GraphHopperStorage ghStorage =
        createGHStorage(em, Collections.<Weighting>singleton(weighting), false);
    CHGraphImpl g2 = (CHGraphImpl) ghStorage.getGraph(CHGraph.class, weighting);
    g2.edge(0, 1, 1, true);
    EdgeIteratorState iter1_1 = g2.edge(0, 2, 1.4, false);
    EdgeIteratorState iter1_2 = g2.edge(2, 5, 1.4, false);
    g2.edge(1, 2, 1, true);
    g2.edge(1, 3, 3, true);
    g2.edge(2, 3, 1, true);
    g2.edge(4, 3, 1, true);
    g2.edge(2, 5, 1.4, true);
    g2.edge(3, 5, 1, true);
    g2.edge(5, 6, 1, true);
    g2.edge(4, 6, 1, true);
    g2.edge(6, 7, 1, true);
    EdgeIteratorState iter2_2 = g2.edge(5, 7);
    iter2_2.setDistance(1.4).setFlags(encoder.setProperties(10, true, false));

    ghStorage.freeze();
    // simulate preparation
    CHEdgeIteratorState iter2_1 = g2.shortcut(0, 5);
    iter2_1.setDistance(2.8).setFlags(encoder.setProperties(10, true, false));
    iter2_1.setSkippedEdges(iter1_1.getEdge(), iter1_2.getEdge());
    CHEdgeIteratorState tmp = g2.shortcut(0, 7);
    tmp.setDistance(4.2).setFlags(encoder.setProperties(10, true, false));
    tmp.setSkippedEdges(iter2_1.getEdge(), iter2_2.getEdge());
    g2.setLevel(1, 0);
    g2.setLevel(3, 1);
    g2.setLevel(4, 2);
    g2.setLevel(6, 3);
    g2.setLevel(2, 4);
    g2.setLevel(5, 5);
    g2.setLevel(7, 6);
    g2.setLevel(0, 7);

    AlgorithmOptions opts = new AlgorithmOptions(AlgorithmOptions.DIJKSTRA_BI, encoder, weighting);
    Path p =
        new PrepareContractionHierarchies(
                new GHDirectory("", DAType.RAM_INT),
                ghStorage,
                g2,
                encoder,
                weighting,
                TraversalMode.NODE_BASED)
            .createAlgo(g2, opts)
            .calcPath(0, 7);

    assertEquals(Helper.createTList(0, 2, 5, 7), p.calcNodes());
    assertEquals(1064, p.getTime());
    assertEquals(4.2, p.getDistance(), 1e-5);
  }
Exemplo n.º 5
0
  @Test
  public void testNoExpand() {
    LevelGraph g = createGraph(20);
    g.edge(0, 1, 10, true); // 1
    g.edge(1, 2, 10, true); // 2
    g.edge(2, 3, 10, true); // 3
    g.edge(3, 4, 10, true); // 4

    Path4Shortcuts path = new Path4Shortcuts(g, ShortestCarCalc.DEFAULT);
    path.edgeEntry = new EdgeEntry(3, 3, 10);
    path.edgeEntry.parent = new EdgeEntry(2, 2, 10);
    path.edgeEntry.parent.parent = new EdgeEntry(1, 1, 10);
    path.edgeEntry.parent.parent.parent = new EdgeEntry(EdgeIterator.NO_EDGE, 0, 0);
    path.edgeTo = new EdgeEntry(4, 3, 10);
    path.edgeTo.parent = new EdgeEntry(EdgeIterator.NO_EDGE, 4, 0);
    Path p = path.extract();
    assertEquals(5, p.calcNodes().size());
    assertEquals(Helper.createTList(0, 1, 2, 3, 4), p.calcNodes());
  }
  @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());
  }
Exemplo n.º 7
0
  @Test
  public void testExpand() {
    LevelGraphStorage g = (LevelGraphStorage) createGraph(20);
    EdgeSkipIterator iter = g.edge(0, 1, 10, true); // 1
    g.edge(1, 2, 10, true); // 2
    EdgeSkipIterator iter3 = g.edge(2, 3, 10, true); // 3

    g.setLevel(1, -1);
    g.setLevel(2, -1);
    EdgeSkipIterator iter4 = g.edge(0, 2, 20, CarStreetType.flagsDefault(true));
    iter4.skippedEdge(iter.edge()); // 4

    Path4Shortcuts path = new Path4Shortcuts(g, ShortestCarCalc.DEFAULT);
    path.edgeEntry = new EdgeEntry(iter4.edge(), 2, 20);
    path.edgeEntry.parent = new EdgeEntry(EdgeIterator.NO_EDGE, 0, 0);
    path.edgeTo = new EdgeEntry(iter3.edge(), 2, 10);
    path.edgeTo.parent = new EdgeEntry(EdgeIterator.NO_EDGE, 3, 0);
    Path p = path.extract();
    assertEquals(Helper.createTList(0, 1, 2, 3), p.calcNodes());
    assertEquals(4, p.calcNodes().size());
  }
Exemplo n.º 8
0
 @Test
 public void testExtract() {
   Graph g = createGraph();
   g.edge(1, 2, 10, true);
   PathBidirRef pw = new PathBidirRef(g, carEncoder);
   EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges);
   EdgeIterator iter = explorer.setBaseNode(1);
   iter.next();
   pw.edgeEntry = new EdgeEntry(iter.getEdge(), 2, 0);
   pw.edgeEntry.parent = new EdgeEntry(EdgeIterator.NO_EDGE, 1, 10);
   pw.edgeTo = new EdgeEntry(EdgeIterator.NO_EDGE, 2, 0);
   Path p = pw.extract();
   assertEquals(Helper.createTList(1, 2), p.calcNodes());
   assertEquals(10, p.getDistance(), 1e-4);
 }
  @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());
  }