@Test
 public void testMoreComplexGraph() {
   LevelGraph g = initShortcutsGraph(createGraph());
   int old = g.getAllEdges().maxId();
   PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g);
   prepare.doWork();
   assertEquals(old + 8, g.getAllEdges().maxId());
 }
 @Test
 public void testAddShortcuts() {
   LevelGraph g = createExampleGraph();
   int old = g.getAllEdges().maxId();
   PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g);
   prepare.doWork();
   assertEquals(old, g.getAllEdges().maxId());
 }
  @Override
  public PrepareContractionHierarchies prepareGraph(Graph g, FlagEncoder encoder, Weighting w) {
    PrepareContractionHierarchies ch = new PrepareContractionHierarchies(encoder, w).setGraph(g);
    // hack: prepare matrixgraph only once
    if (g != preparedMatrixGraph) ch.doWork();

    return ch;
  }
 @Test
 public void testRoundaboutUnpacking() {
   LevelGraph g = createGraph();
   initRoundaboutGraph(g);
   int old = g.getAllEdges().maxId();
   PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g);
   prepare.doWork();
   assertEquals(old + 25, g.getAllEdges().maxId());
   RoutingAlgorithm algo = prepare.createAlgo();
   Path p = algo.calcPath(4, 7);
   assertEquals(Helper.createTList(4, 5, 6, 7), p.calcNodes());
 }
 @Test
 public void testCircleBug() {
   LevelGraph g = createGraph();
   //  /--1
   // -0--/
   //  |
   g.edge(0, 1, 10, true);
   g.edge(0, 1, 4, true);
   g.edge(0, 2, 10, true);
   g.edge(0, 3, 10, true);
   PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g);
   prepare.doWork();
   assertEquals(0, prepare.shortcuts());
 }
 @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;
 }
  @Test
  public void testDirectedGraph2() {
    LevelGraph g = createGraph();
    initDirected2(g);
    int old = GHUtility.count(g.getAllEdges());
    PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g);
    prepare.doWork();
    // PrepareTowerNodesShortcutsTest.printEdges(g);
    assertEquals(old + 15, GHUtility.count(g.getAllEdges()));
    RoutingAlgorithm algo = prepare.createAlgo();

    Path p = algo.calcPath(0, 10);
    assertEquals(10, p.distance(), 1e-6);
    assertEquals(Helper.createTList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), p.calcNodes());
  }
 @Test
 public void testDirectedGraph() {
   LevelGraph g = createGraph();
   g.edge(5, 4, 3, false);
   g.edge(4, 5, 10, false);
   g.edge(2, 4, 1, false);
   g.edge(5, 2, 1, false);
   g.edge(3, 5, 1, false);
   g.edge(4, 3, 1, false);
   int old = GHUtility.count(g.getAllEdges());
   PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g);
   prepare.doWork();
   // PrepareTowerNodesShortcutsTest.printEdges(g);
   assertEquals(old + 3, GHUtility.count(g.getAllEdges()));
   RoutingAlgorithm algo = prepare.createAlgo();
   Path p = algo.calcPath(4, 2);
   assertEquals(3, p.distance(), 1e-6);
   assertEquals(Helper.createTList(4, 3, 5, 2), p.calcNodes());
 }
 public static RoutingAlgorithm[] createAlgos(final Graph g) {
   LevelGraph graphSimpleSC =
       (LevelGraphStorage) g.copyTo(new LevelGraphStorage(new RAMDirectory()).createNew(10));
   PrepareSimpleShortcuts prepare = new PrepareSimpleShortcuts().setGraph(graphSimpleSC);
   prepare.doWork();
   AStarBidirection astarSimpleSC = (AStarBidirection) prepare.createAStar();
   astarSimpleSC.setApproximation(false);
   LevelGraph graphCH =
       (LevelGraphStorage) g.copyTo(new LevelGraphStorage(new RAMDirectory()).createNew(10));
   PrepareContractionHierarchies prepareCH = new PrepareContractionHierarchies().setGraph(graphCH);
   prepareCH.doWork();
   return new RoutingAlgorithm[] {
     new AStar(g),
     new AStarBidirection(g),
     new DijkstraBidirectionRef(g),
     new DijkstraBidirection(g),
     new DijkstraSimple(g),
     prepare.createAlgo(),
     astarSimpleSC,
     prepareCH.createAlgo()
   };
 }