コード例 #1
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);
  }
コード例 #2
0
  /** Finds shortcuts, does not change the underlying graph. */
  void findShortcuts(ShortcutHandler sch) {
    long tmpDegreeCounter = 0;
    EdgeIterator incomingEdges = vehicleInExplorer.setBaseNode(sch.getNode());
    // collect outgoing nodes (goal-nodes) only once
    while (incomingEdges.next()) {
      int u_fromNode = incomingEdges.getAdjNode();
      // accept only uncontracted nodes
      if (g.getLevel(u_fromNode) != 0) continue;

      double v_u_weight = incomingEdges.getDistance();
      int skippedEdge1 = incomingEdges.getEdge();
      int incomingEdgeOrigCount = getOrigEdgeCount(skippedEdge1);
      // collect outgoing nodes (goal-nodes) only once
      EdgeIterator outgoingEdges = vehicleOutExplorer.setBaseNode(sch.getNode());
      // force fresh maps etc as this cannot be determined by from node alone (e.g. same from node
      // but different avoidNode)
      algo.clear();
      tmpDegreeCounter++;
      while (outgoingEdges.next()) {
        int w_toNode = outgoingEdges.getAdjNode();
        // add only uncontracted nodes
        if (g.getLevel(w_toNode) != 0 || u_fromNode == w_toNode) {
          continue;
        }

        // Limit weight as ferries or forbidden edges can increase local search too much.
        // If we decrease the correct weight we only explore less and introduce more shortcuts.
        // I.e. no change to accuracy is made.
        double existingDirectWeight = v_u_weight + outgoingEdges.getDistance();
        algo.setLimitWeight(existingDirectWeight)
            .setLimitVisitedNodes((int) meanDegree * 100)
            .setEdgeFilter(levelEdgeFilter.setAvoidNode(sch.getNode()));

        dijkstraSW.start();
        dijkstraCount++;
        int endNode = algo.findEndNode(u_fromNode, w_toNode);
        dijkstraSW.stop();

        // compare end node as the limit could force dijkstra to finish earlier
        if (endNode == w_toNode && algo.getWeight(endNode) <= existingDirectWeight)
          // FOUND witness path, so do not add shortcut
          continue;

        sch.foundShortcut(
            u_fromNode,
            w_toNode,
            existingDirectWeight,
            outgoingEdges,
            skippedEdge1,
            incomingEdgeOrigCount);
      }
    }
    if (sch instanceof AddShortcutHandler) {
      // sliding mean value when using "*2" => slower changes
      meanDegree = (meanDegree * 2 + tmpDegreeCounter) / 3;
      // meanDegree = (meanDegree + tmpDegreeCounter) / 2;
    }
  }
コード例 #3
0
  @Test
  public void testGetAllEdges() {
    graph = createGraph();
    graph.edge(0, 1, 2, true);
    graph.edge(3, 1, 1, false);
    graph.edge(3, 2, 1, false);

    EdgeIterator iter = graph.getAllEdges();
    assertTrue(iter.next());
    int edgeId = iter.getEdge();
    assertEquals(0, iter.getBaseNode());
    assertEquals(1, iter.getAdjNode());
    assertEquals(2, iter.getDistance(), 1e-6);

    assertTrue(iter.next());
    int edgeId2 = iter.getEdge();
    assertEquals(1, edgeId2 - edgeId);
    assertEquals(1, iter.getBaseNode());
    assertEquals(3, iter.getAdjNode());

    assertTrue(iter.next());
    assertEquals(2, iter.getBaseNode());
    assertEquals(3, iter.getAdjNode());

    assertFalse(iter.next());
  }