Search in sources :

Example 1 with QueryRoutingCHGraph

use of com.graphhopper.routing.querygraph.QueryRoutingCHGraph in project graphhopper by graphhopper.

the class MiniGraphUI method createAlgo.

private RoutingAlgorithm createAlgo(GraphHopper hopper) {
    Profile profile = hopper.getProfiles().iterator().next();
    if (useCH) {
        RoutingCHGraph chGraph = hopper.getCHGraphs().get(profile.getName());
        logger.info("CH algo, profile: " + profile.getName());
        QueryGraph qGraph = QueryGraph.create(hopper.getGraphHopperStorage(), fromRes, toRes);
        QueryRoutingCHGraph queryRoutingCHGraph = new QueryRoutingCHGraph(chGraph, qGraph);
        return new CHDebugAlgo(queryRoutingCHGraph, mg);
    } else {
        LandmarkStorage landmarks = hopper.getLandmarks().get(profile.getName());
        RoutingAlgorithmFactory algoFactory = (g, w, opts) -> {
            RoutingAlgorithm algo = new LMRoutingAlgorithmFactory(landmarks).createAlgo(g, w, opts);
            if (algo instanceof AStarBidirection) {
                return new DebugAStarBi(g, w, opts.getTraversalMode(), mg).setApproximation(((AStarBidirection) algo).getApproximation());
            } else if (algo instanceof AStar) {
                return new DebugAStar(g, w, opts.getTraversalMode(), mg);
            } else if (algo instanceof DijkstraBidirectionRef) {
                return new DebugDijkstraBidirection(g, w, opts.getTraversalMode(), mg);
            } else if (algo instanceof Dijkstra) {
                return new DebugDijkstraSimple(g, w, opts.getTraversalMode(), mg);
            }
            return algo;
        };
        AlgorithmOptions algoOpts = new AlgorithmOptions().setAlgorithm(Algorithms.ASTAR_BI);
        logger.info("algoOpts:" + algoOpts + ", weighting: " + landmarks.getWeighting() + ", profile: " + profile.getName());
        QueryGraph qGraph = QueryGraph.create(graph, fromRes, toRes);
        return algoFactory.createAlgo(qGraph, landmarks.getWeighting(), algoOpts);
    }
}
Also used : RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) Arrays(java.util.Arrays) GraphHopperConfig(com.graphhopper.GraphHopperConfig) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) com.graphhopper.routing(com.graphhopper.routing) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) LandmarkStorage(com.graphhopper.routing.lm.LandmarkStorage) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) StopWatch(com.graphhopper.util.StopWatch) LMRoutingAlgorithmFactory(com.graphhopper.routing.lm.LMRoutingAlgorithmFactory) MouseWheelEvent(java.awt.event.MouseWheelEvent) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) Profile(com.graphhopper.config.Profile) MouseAdapter(java.awt.event.MouseAdapter) Graph(com.graphhopper.storage.Graph) GraphHopper(com.graphhopper.GraphHopper) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Logger(org.slf4j.Logger) BBox(com.graphhopper.util.shapes.BBox) PMap(com.graphhopper.util.PMap) Algorithms(com.graphhopper.util.Parameters.Algorithms) BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) CHProfile(com.graphhopper.config.CHProfile) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) PointList(com.graphhopper.util.PointList) MouseEvent(java.awt.event.MouseEvent) GHBitSet(com.graphhopper.coll.GHBitSet) java.awt(java.awt) GHTBitSet(com.graphhopper.coll.GHTBitSet) NodeAccess(com.graphhopper.storage.NodeAccess) MouseWheelListener(java.awt.event.MouseWheelListener) Snap(com.graphhopper.storage.index.Snap) FetchMode(com.graphhopper.util.FetchMode) LMProfile(com.graphhopper.config.LMProfile) AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator) javax.swing(javax.swing) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) LMRoutingAlgorithmFactory(com.graphhopper.routing.lm.LMRoutingAlgorithmFactory) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) LandmarkStorage(com.graphhopper.routing.lm.LandmarkStorage) LMRoutingAlgorithmFactory(com.graphhopper.routing.lm.LMRoutingAlgorithmFactory) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph)

Example 2 with QueryRoutingCHGraph

use of com.graphhopper.routing.querygraph.QueryRoutingCHGraph in project graphhopper by graphhopper.

the class QueryRoutingCHGraphTest method getBaseGraph.

@Test
public void getBaseGraph() {
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(10));
    graph.freeze();
    CHConfig chConfig = CHConfig.edgeBased("x", weighting);
    CHStorage chStore = graph.createCHStorage(chConfig);
    RoutingCHGraph routingCHGraph = graph.createCHGraph(chStore, chConfig);
    QueryGraph queryGraph = QueryGraph.create(graph, Collections.<Snap>emptyList());
    assertSame(graph.getBaseGraph(), routingCHGraph.getBaseGraph());
    QueryRoutingCHGraph queryCHGraph = new QueryRoutingCHGraph(routingCHGraph, queryGraph);
    assertSame(queryGraph, queryCHGraph.getBaseGraph());
}
Also used : QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) Test(org.junit.jupiter.api.Test)

Example 3 with QueryRoutingCHGraph

use of com.graphhopper.routing.querygraph.QueryRoutingCHGraph in project graphhopper by graphhopper.

the class QueryRoutingCHGraphTest method withVirtualEdges.

@Test
public void withVirtualEdges() {
    // 2 3
    // 0-x-1-2
    // 3
    na.setNode(0, 50.00, 10.00);
    na.setNode(1, 50.00, 10.10);
    na.setNode(2, 50.00, 10.20);
    EdgeIteratorState edge = addEdge(graph, 0, 1);
    addEdge(graph, 1, 2);
    graph.freeze();
    assertEquals(2, graph.getEdges());
    CHConfig chConfig = CHConfig.edgeBased("x", weighting);
    CHStorage chStore = graph.createCHStorage(chConfig);
    RoutingCHGraph routingCHGraph = graph.createCHGraph(chStore, chConfig);
    Snap snap = new Snap(50.00, 10.05);
    snap.setClosestEdge(edge);
    snap.setWayIndex(0);
    snap.setSnappedPosition(Snap.Position.EDGE);
    snap.calcSnappedPoint(DistancePlaneProjection.DIST_PLANE);
    QueryGraph queryGraph = QueryGraph.create(graph, Collections.singletonList(snap));
    QueryRoutingCHGraph queryCHGraph = new QueryRoutingCHGraph(routingCHGraph, queryGraph);
    assertEquals(4, queryCHGraph.getNodes());
    assertEquals(2 + 4, queryCHGraph.getEdges());
    assertNodesConnected(queryCHGraph, 1, 2, true);
    // virtual edges at virtual node 3
    assertNodesConnected(queryCHGraph, 0, 3, true);
    assertNodesConnected(queryCHGraph, 3, 1, true);
    // out-iter at real node
    RoutingCHEdgeIterator outIter = queryCHGraph.createOutEdgeExplorer().setBaseNode(2);
    assertNextEdge(outIter, 2, 1, 1);
    assertEnd(outIter);
    // in-iter at real node
    RoutingCHEdgeIterator inIter = queryCHGraph.createInEdgeExplorer().setBaseNode(2);
    assertNextEdge(inIter, 2, 1, 1);
    assertEnd(inIter);
    // out-iter at real node next to virtual node
    outIter = queryCHGraph.createOutEdgeExplorer().setBaseNode(0);
    assertNextEdge(outIter, 0, 3, 2);
    assertEnd(outIter);
    // in-iter at real node next to virtual node
    inIter = queryCHGraph.createInEdgeExplorer().setBaseNode(1);
    assertNextEdge(inIter, 1, 3, 3);
    assertNextEdge(inIter, 1, 2, 1);
    assertEnd(inIter);
    // out-iter at virtual node
    outIter = queryCHGraph.createOutEdgeExplorer().setBaseNode(3);
    assertNextEdge(outIter, 3, 0, 2);
    assertNextEdge(outIter, 3, 1, 3);
    assertEnd(outIter);
    // in-iter at virtual node
    inIter = queryCHGraph.createInEdgeExplorer().setBaseNode(3);
    assertNextEdge(inIter, 3, 0, 2);
    assertNextEdge(inIter, 3, 1, 3);
    assertEnd(inIter);
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) Snap(com.graphhopper.storage.index.Snap) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) Test(org.junit.jupiter.api.Test)

Example 4 with QueryRoutingCHGraph

use of com.graphhopper.routing.querygraph.QueryRoutingCHGraph in project graphhopper by graphhopper.

the class QueryRoutingCHGraphTest method getLevel.

@Test
public void getLevel() {
    // 0-x-1
    na.setNode(0, 50.00, 10.00);
    na.setNode(1, 50.00, 10.10);
    EdgeIteratorState edge = addEdge(graph, 0, 1);
    graph.freeze();
    CHConfig chConfig = CHConfig.edgeBased("x", weighting);
    CHStorage chStore = graph.createCHStorage(chConfig);
    RoutingCHGraph routingCHGraph = graph.createCHGraph(chStore, chConfig);
    CHStorageBuilder chBuilder = new CHStorageBuilder(chStore);
    chBuilder.setLevel(0, 5);
    chBuilder.setLevel(1, 7);
    Snap snap = new Snap(50.00, 10.05);
    snap.setClosestEdge(edge);
    snap.setWayIndex(0);
    snap.setSnappedPosition(Snap.Position.EDGE);
    snap.calcSnappedPoint(DistancePlaneProjection.DIST_PLANE);
    QueryGraph queryGraph = QueryGraph.create(graph, Collections.singletonList(snap));
    QueryRoutingCHGraph queryCHGraph = new QueryRoutingCHGraph(routingCHGraph, queryGraph);
    assertEquals(5, queryCHGraph.getLevel(0));
    assertEquals(7, queryCHGraph.getLevel(1));
    assertEquals(Integer.MAX_VALUE, queryCHGraph.getLevel(2));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) Snap(com.graphhopper.storage.index.Snap) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) Test(org.junit.jupiter.api.Test)

Example 5 with QueryRoutingCHGraph

use of com.graphhopper.routing.querygraph.QueryRoutingCHGraph in project graphhopper by graphhopper.

the class QueryRoutingCHGraphTest method getWeight.

@Test
public void getWeight() {
    // /---\
    // 0-x-1-2
    // 3
    na.setNode(0, 50.00, 10.00);
    na.setNode(1, 50.00, 10.10);
    na.setNode(2, 50.00, 10.20);
    EdgeIteratorState edge = addEdge(graph, 0, 1).set(encoder.getAverageSpeedEnc(), 90, 30);
    addEdge(graph, 1, 2);
    graph.freeze();
    CHConfig chConfig = CHConfig.edgeBased("x", weighting);
    CHStorage chStore = graph.createCHStorage(chConfig);
    RoutingCHGraph routingCHGraph = graph.createCHGraph(chStore, chConfig);
    CHStorageBuilder chBuilder = new CHStorageBuilder(chStore);
    chBuilder.setIdentityLevels();
    chBuilder.addShortcutEdgeBased(0, 2, PrepareEncoder.getScDirMask(), 20, 0, 1, 0, 1);
    // without query graph
    RoutingCHEdgeIterator iter = routingCHGraph.createOutEdgeExplorer().setBaseNode(0);
    assertNextShortcut(iter, 0, 2, 0, 1);
    assertEquals(20, iter.getWeight(false), 1.e-6);
    assertEquals(20, iter.getWeight(true), 1.e-6);
    assertNextEdge(iter, 0, 1, 0);
    assertEquals(285.89888, iter.getWeight(false), 1.e-6);
    assertEquals(857.69664, iter.getWeight(true), 1.e-6);
    assertEnd(iter);
    // for incoming edges its the same
    iter = routingCHGraph.createInEdgeExplorer().setBaseNode(0);
    assertNextShortcut(iter, 0, 2, 0, 1);
    assertEquals(20, iter.getWeight(false), 1.e-6);
    assertEquals(20, iter.getWeight(true), 1.e-6);
    assertNextEdge(iter, 0, 1, 0);
    assertEquals(285.89888, iter.getWeight(false), 1.e-6);
    assertEquals(857.69664, iter.getWeight(true), 1.e-6);
    assertEnd(iter);
    // now including virtual edges
    Snap snap = new Snap(50.00, 10.05);
    snap.setClosestEdge(edge);
    snap.setWayIndex(0);
    snap.setSnappedPosition(Snap.Position.EDGE);
    snap.calcSnappedPoint(DistancePlaneProjection.DIST_PLANE);
    QueryGraph queryGraph = QueryGraph.create(graph, Collections.singletonList(snap));
    QueryRoutingCHGraph queryCHGraph = new QueryRoutingCHGraph(routingCHGraph, queryGraph);
    iter = queryCHGraph.createOutEdgeExplorer().setBaseNode(0);
    assertNextEdge(iter, 0, 3, 2);
    // should be about half the weight as for the original edge as the query point is in the middle of the edge
    assertEquals(142.9494, iter.getWeight(false), 1.e-4);
    assertEquals(428.8483, iter.getWeight(true), 1.e-4);
    assertNextShortcut(iter, 0, 2, 0, 1);
    assertEquals(20, iter.getWeight(false), 1.e-6);
    assertEquals(20, iter.getWeight(true), 1.e-6);
    assertEnd(iter);
    iter = queryCHGraph.createInEdgeExplorer().setBaseNode(0);
    assertNextEdge(iter, 0, 3, 2);
    assertEquals(142.9494, iter.getWeight(false), 1.e-4);
    assertEquals(428.8483, iter.getWeight(true), 1.e-4);
    assertNextShortcut(iter, 0, 2, 0, 1);
    assertEquals(20, iter.getWeight(false), 1.e-6);
    assertEquals(20, iter.getWeight(true), 1.e-6);
    assertEnd(iter);
    // at the virtual node
    iter = queryCHGraph.createOutEdgeExplorer().setBaseNode(3);
    assertNextEdge(iter, 3, 0, 2);
    assertEquals(428.8483, iter.getWeight(false), 1.e-4);
    assertEquals(142.9494, iter.getWeight(true), 1.e-4);
    assertNextEdge(iter, 3, 1, 3);
    assertEquals(142.9494, iter.getWeight(false), 1.e-4);
    assertEquals(428.8483, iter.getWeight(true), 1.e-4);
    assertEnd(iter);
    iter = queryCHGraph.createInEdgeExplorer().setBaseNode(3);
    assertNextEdge(iter, 3, 0, 2);
    assertEquals(428.8483, iter.getWeight(false), 1.e-4);
    assertEquals(142.9494, iter.getWeight(true), 1.e-4);
    assertNextEdge(iter, 3, 1, 3);
    assertEquals(142.9494, iter.getWeight(false), 1.e-4);
    assertEquals(428.8483, iter.getWeight(true), 1.e-4);
    assertEnd(iter);
    // getting a single edge
    RoutingCHEdgeIteratorState edgeState = queryCHGraph.getEdgeIteratorState(3, 3);
    assertEdgeState(edgeState, 0, 3, 2);
    assertEquals(142.9494, edgeState.getWeight(false), 1.e-4);
    assertEquals(428.8483, edgeState.getWeight(true), 1.e-4);
    edgeState = queryCHGraph.getEdgeIteratorState(3, 0);
    assertEdgeState(edgeState, 3, 0, 2);
    assertEquals(428.8483, edgeState.getWeight(false), 1.e-4);
    assertEquals(142.9494, edgeState.getWeight(true), 1.e-4);
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) Snap(com.graphhopper.storage.index.Snap) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) Test(org.junit.jupiter.api.Test)

Aggregations

QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)16 QueryRoutingCHGraph (com.graphhopper.routing.querygraph.QueryRoutingCHGraph)16 Snap (com.graphhopper.storage.index.Snap)12 Test (org.junit.jupiter.api.Test)11 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)7 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)5 Path (com.graphhopper.routing.Path)3 RoutingAlgorithm (com.graphhopper.routing.RoutingAlgorithm)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 PMap (com.graphhopper.util.PMap)2 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)1 GraphHopper (com.graphhopper.GraphHopper)1 GraphHopperConfig (com.graphhopper.GraphHopperConfig)1 GHBitSet (com.graphhopper.coll.GHBitSet)1 GHTBitSet (com.graphhopper.coll.GHTBitSet)1 CHProfile (com.graphhopper.config.CHProfile)1 LMProfile (com.graphhopper.config.LMProfile)1