public void initSimpleGraph(Graph g) {
   //  6 |       4
   //  5 |
   //    |     6
   //  4 |              5
   //  3 |
   //  2 |    1
   //  1 |          3
   //  0 |    2
   // -1 | 0
   // ---|-------------------
   //    |-2 -1 0 1 2 3 4
   //
   NodeAccess na = g.getNodeAccess();
   na.setNode(0, -1, -2);
   na.setNode(1, 2, -1);
   na.setNode(2, 0, 1);
   na.setNode(3, 1, 2);
   na.setNode(4, 6, 1);
   na.setNode(5, 4, 4);
   na.setNode(6, 4.5, -0.5);
   g.edge(0, 1, 3.5, true);
   g.edge(0, 2, 2.5, true);
   g.edge(2, 3, 1, true);
   g.edge(3, 4, 3.2, true);
   g.edge(1, 4, 2.4, true);
   g.edge(3, 5, 1.5, true);
   // make sure 6 is connected
   g.edge(6, 4, 1.2, true);
 }
  @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());
  }
Пример #3
0
  @Test
  public void testCopy() {
    Graph g = initUnsorted(createGraph());
    EdgeIteratorState eb = g.edge(6, 5, 11, true);
    eb.setWayGeometry(Helper.createPointList(12, 10, -1, 3));
    LevelGraph lg = new GraphBuilder(encodingManager).levelGraphCreate();
    GHUtility.copyTo(g, lg);
    eb = lg.getEdgeProps(eb.getEdge(), 6);
    assertEquals(Helper.createPointList(-1, 3, 12, 10), eb.getWayGeometry());
    assertEquals(0, lg.getLevel(0));
    assertEquals(0, lg.getLevel(1));
    assertEquals(0, lg.getLatitude(0), 1e-6);
    assertEquals(1, lg.getLongitude(0), 1e-6);
    assertEquals(2.5, lg.getLatitude(1), 1e-6);
    assertEquals(4.5, lg.getLongitude(1), 1e-6);
    assertEquals(9, lg.getNodes());
    EdgeIterator iter = lg.createEdgeExplorer().setBaseNode(8);
    iter.next();
    assertEquals(2.05, iter.getDistance(), 1e-6);
    assertEquals("11", BitUtil.toBitString(iter.getFlags(), 2));
    iter.next();
    assertEquals(0.5, iter.getDistance(), 1e-6);
    assertEquals("11", BitUtil.toBitString(iter.getFlags(), 2));

    iter = lg.createEdgeExplorer().setBaseNode(7);
    iter.next();
    assertEquals(2.1, iter.getDistance(), 1e-6);
    assertEquals("01", BitUtil.toBitString(iter.getFlags(), 2));
    assertTrue(iter.next());
    assertEquals(0.7, iter.getDistance(), 1e-6);
  }
Пример #4
0
  int addEdge(int fromIndex, int toIndex, PointList pointList, int flags) {
    double towerNodeDistance = 0;
    double prevLat = pointList.latitude(0);
    double prevLon = pointList.longitude(0);
    double lat;
    double lon;
    PointList pillarNodes = new PointList(pointList.size() - 2);
    int nodes = pointList.size();
    for (int i = 1; i < nodes; i++) {
      lat = pointList.latitude(i);
      lon = pointList.longitude(i);
      towerNodeDistance += callback.calcDist(prevLat, prevLon, lat, lon);
      prevLat = lat;
      prevLon = lon;
      if (nodes > 2 && i < nodes - 1) pillarNodes.add(lat, lon);
    }
    if (towerNodeDistance == 0) {
      // As investigation shows often two paths should have crossed via one identical point
      // but end up in two very close points. later this will be removed/fixed while
      // removing short edges where one node is of degree 2
      zeroCounter++;
      towerNodeDistance = 0.0001;
    }

    EdgeIterator iter = g.edge(fromIndex, toIndex, towerNodeDistance, flags);
    if (nodes > 2) iter.wayGeometry(pillarNodes);
    return nodes;
  }
 //       8
 //       |
 //    6->0->1->3->7
 //    |        |
 //    |        v
 // 10<-2---4<---5
 //    9
 public static void initDirected1(Graph g) {
   g.edge(0, 8, 1, true);
   g.edge(0, 1, 1, false);
   g.edge(1, 3, 1, false);
   g.edge(3, 7, 1, false);
   g.edge(3, 5, 1, false);
   g.edge(5, 4, 1, false);
   g.edge(4, 2, 1, true);
   g.edge(2, 9, 1, false);
   g.edge(2, 10, 1, false);
   g.edge(2, 6, 1, true);
   g.edge(6, 0, 1, false);
 }
Пример #6
0
 Graph initUnsorted(Graph g) {
   g.setNode(0, 0, 1);
   g.setNode(1, 2.5, 4.5);
   g.setNode(2, 4.5, 4.5);
   g.setNode(3, 3, 0.5);
   g.setNode(4, 2.8, 2.8);
   g.setNode(5, 4.2, 1.6);
   g.setNode(6, 2.3, 2.2);
   g.setNode(7, 5, 1.5);
   g.setNode(8, 4.6, 4);
   g.edge(8, 2, 0.5, true);
   g.edge(7, 3, 2.1, false);
   g.edge(1, 0, 3.9, true);
   g.edge(7, 5, 0.7, true);
   g.edge(1, 2, 1.9, true);
   g.edge(8, 1, 2.05, true);
   return g;
 }
Пример #7
0
 @Test
 public void testSortDirected() {
   Graph g = createGraph();
   g.setNode(0, 0, 1);
   g.setNode(1, 2.5, 2);
   g.setNode(2, 3.5, 3);
   g.edge(0, 1, 1.1, false);
   g.edge(2, 1, 1.1, false);
   GHUtility.sortDFS(g, createGraph());
 }
  @Test
  public void testCannotCalculateSP2() {
    Graph g = createGraph(10);
    g.edge(0, 1, 1, false);
    g.edge(1, 2, 1, false);

    DijkstraBidirectionRef db = new DijkstraBidirectionRef(g);
    db.addSkipNode(1);
    Path p = db.calcPath(0, 2);
    assertFalse(p.found());
  }
Пример #9
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);
 }
 // 0-1-2-3-4
 // |     / |
 // |    8  |
 // \   /   /
 //  7-6-5-/
 void initBiGraph(Graph graph) {
   graph.edge(0, 1, 100, true);
   graph.edge(1, 2, 1, true);
   graph.edge(2, 3, 1, true);
   graph.edge(3, 4, 1, true);
   graph.edge(4, 5, 25, true);
   graph.edge(5, 6, 25, true);
   graph.edge(6, 7, 5, true);
   graph.edge(7, 0, 5, true);
   graph.edge(3, 8, 20, true);
   graph.edge(8, 6, 20, true);
 }
 // 0-1-.....-9-10
 // |         ^   \
 // |         |    |
 // 17-16-...-11<-/
 public static void initDirected2(Graph g) {
   g.edge(0, 1, 1, true);
   g.edge(1, 2, 1, true);
   g.edge(2, 3, 1, true);
   g.edge(3, 4, 1, true);
   g.edge(4, 5, 1, true);
   g.edge(5, 6, 1, true);
   g.edge(6, 7, 1, true);
   g.edge(7, 8, 1, true);
   g.edge(8, 9, 1, true);
   g.edge(9, 10, 1, true);
   g.edge(10, 11, 1, false);
   g.edge(11, 12, 1, true);
   g.edge(11, 9, 3, false);
   g.edge(12, 13, 1, true);
   g.edge(13, 14, 1, true);
   g.edge(14, 15, 1, true);
   g.edge(15, 16, 1, true);
   g.edge(16, 17, 1, true);
   g.edge(17, 0, 1, true);
 }
  void initRoundaboutGraph(Graph g) {
    //              roundabout:
    // 16-0-9-10--11   12<-13
    //    \       \  /      \
    //    17       \|        7-8-..
    // -15-1--2--3--4       /     /
    //     /         \-5->6/     /
    //  -14            \________/

    g.edge(16, 0, 1, true);
    g.edge(0, 9, 1, true);
    g.edge(0, 17, 1, true);
    g.edge(9, 10, 1, true);
    g.edge(10, 11, 1, true);
    g.edge(11, 28, 1, true);
    g.edge(28, 29, 1, true);
    g.edge(29, 30, 1, true);
    g.edge(30, 31, 1, true);
    g.edge(31, 4, 1, true);

    g.edge(17, 1, 1, true);
    g.edge(15, 1, 1, true);
    g.edge(14, 1, 1, true);
    g.edge(14, 18, 1, true);
    g.edge(18, 19, 1, true);
    g.edge(19, 20, 1, true);
    g.edge(20, 15, 1, true);
    g.edge(19, 21, 1, true);
    g.edge(21, 16, 1, true);
    g.edge(1, 2, 1, true);
    g.edge(2, 3, 1, true);
    g.edge(3, 4, 1, true);

    g.edge(4, 5, 1, false);
    g.edge(5, 6, 1, false);
    g.edge(6, 7, 1, false);
    g.edge(7, 13, 1, false);
    g.edge(13, 12, 1, false);
    g.edge(12, 4, 1, false);

    g.edge(7, 8, 1, true);
    g.edge(8, 22, 1, true);
    g.edge(22, 23, 1, true);
    g.edge(23, 24, 1, true);
    g.edge(24, 25, 1, true);
    g.edge(25, 27, 1, true);
    g.edge(27, 5, 1, true);
    g.edge(25, 26, 1, false);
    g.edge(26, 25, 1, false);
  }
  public Graph createSampleGraph(EncodingManager encodingManager) {
    Graph graph = AbstractLocationIndexTester.this.createGHStorage(encodingManager);
    // length does not matter here but lat,lon and outgoing edges do!

    //
    //   lat             /--------\
    //    5   o-        p--------\ q
    //          \  /-----\-----n | |
    //    4       k    /--l--    m/
    //           / \  j      \   |
    //    3     |   g  \  h---i  /
    //          |       \    /  /
    //    2     e---------f--  /
    //                   /  \-d
    //    1        /--b--      \
    //            |    \--------c
    //    0       a
    //
    //   lon: 0   1   2   3   4   5
    int a0 = 0;
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0, 1.0001f);
    int b1 = 1;
    na.setNode(1, 1, 2);
    int c2 = 2;
    na.setNode(2, 0.5f, 4.5f);
    int d3 = 3;
    na.setNode(3, 1.5f, 3.8f);
    int e4 = 4;
    na.setNode(4, 2.01f, 0.5f);
    int f5 = 5;
    na.setNode(5, 2, 3);
    int g6 = 6;
    na.setNode(6, 3, 1.5f);
    int h7 = 7;
    na.setNode(7, 2.99f, 3.01f);
    int i8 = 8;
    na.setNode(8, 3, 4);
    int j9 = 9;
    na.setNode(9, 3.3f, 2.2f);
    int k10 = 10;
    na.setNode(10, 4, 1);
    int l11 = 11;
    na.setNode(11, 4.1f, 3);
    int m12 = 12;
    na.setNode(12, 4, 4.5f);
    int n13 = 13;
    na.setNode(13, 4.5f, 4.1f);
    int o14 = 14;
    na.setNode(14, 5, 0);
    int p15 = 15;
    na.setNode(15, 4.9f, 2.5f);
    int q16 = 16;
    na.setNode(16, 5, 5);
    // => 17 locations

    graph.edge(a0, b1, 1, true);
    graph.edge(c2, b1, 1, true);
    graph.edge(c2, d3, 1, true);
    graph.edge(f5, b1, 1, true);
    graph.edge(e4, f5, 1, true);
    graph.edge(m12, d3, 1, true);
    graph.edge(e4, k10, 1, true);
    graph.edge(f5, d3, 1, true);
    graph.edge(f5, i8, 1, true);
    graph.edge(f5, j9, 1, true);
    graph.edge(k10, g6, 1, true);
    graph.edge(j9, l11, 1, true);
    graph.edge(i8, l11, 1, true);
    graph.edge(i8, h7, 1, true);
    graph.edge(k10, n13, 1, true);
    graph.edge(k10, o14, 1, true);
    graph.edge(l11, p15, 1, true);
    graph.edge(m12, p15, 1, true);
    graph.edge(q16, p15, 1, true);
    graph.edge(q16, m12, 1, true);
    return graph;
  }