Search in sources :

Example 16 with QueryResult

use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.

the class QueryGraphTest method testIteration_Issue163.

@Test
public void testIteration_Issue163() {
    EdgeFilter outEdgeFilter = new DefaultEdgeFilter(encodingManager.getEncoder("car"), false, true);
    EdgeFilter inEdgeFilter = new DefaultEdgeFilter(encodingManager.getEncoder("car"), true, false);
    EdgeExplorer inExplorer = g.createEdgeExplorer(inEdgeFilter);
    EdgeExplorer outExplorer = g.createEdgeExplorer(outEdgeFilter);
    int nodeA = 0;
    int nodeB = 1;
    /* init test graph: one directional edge going from A to B, via virtual nodes C and D
         * 
         *   (C)-(D)
         *  /       \
         * A         B
         */
    g.getNodeAccess().setNode(nodeA, 1, 0);
    g.getNodeAccess().setNode(nodeB, 1, 10);
    g.edge(nodeA, nodeB, 10, false).setWayGeometry(Helper.createPointList(1.5, 3, 1.5, 7));
    // assert the behavior for classic edgeIterator
    assertEdgeIdsStayingEqual(inExplorer, outExplorer, nodeA, nodeB);
    // setup query results
    EdgeIteratorState it = GHUtility.getEdge(g, nodeA, nodeB);
    QueryResult res1 = createLocationResult(1.5, 3, it, 1, QueryResult.Position.EDGE);
    QueryResult res2 = createLocationResult(1.5, 7, it, 2, QueryResult.Position.EDGE);
    QueryGraph q = new QueryGraph(g);
    q.lookup(Arrays.asList(res1, res2));
    int nodeC = res1.getClosestNode();
    int nodeD = res2.getClosestNode();
    inExplorer = q.createEdgeExplorer(inEdgeFilter);
    outExplorer = q.createEdgeExplorer(outEdgeFilter);
    // assert the same behavior for queryGraph
    assertEdgeIdsStayingEqual(inExplorer, outExplorer, nodeA, nodeC);
    assertEdgeIdsStayingEqual(inExplorer, outExplorer, nodeC, nodeD);
    assertEdgeIdsStayingEqual(inExplorer, outExplorer, nodeD, nodeB);
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 17 with QueryResult

use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.

the class QueryGraphTest method testOneWayLoop_Issue162.

@Test
public void testOneWayLoop_Issue162() {
    // do query at x, where edge is oneway
    // 
    // |\
    // | x
    // 0<-\
    // |
    // 1
    NodeAccess na = g.getNodeAccess();
    na.setNode(0, 0, 0);
    na.setNode(1, 0, -0.001);
    g.edge(0, 1, 10, true);
    // in the case of identical nodes the wayGeometry defines the direction!
    EdgeIteratorState edge = g.edge(0, 0).setDistance(100).setFlags(carEncoder.setProperties(20, true, false)).setWayGeometry(Helper.createPointList(0.001, 0, 0, 0.001));
    QueryResult qr = new QueryResult(0.0011, 0.0009);
    qr.setClosestEdge(edge);
    qr.setWayIndex(1);
    qr.calcSnappedPoint(new DistanceCalc2D());
    QueryGraph qg = new QueryGraph(g);
    qg.lookup(Arrays.asList(qr));
    EdgeExplorer ee = qg.createEdgeExplorer();
    assertTrue(qr.getClosestNode() > 1);
    assertEquals(2, GHUtility.count(ee.setBaseNode(qr.getClosestNode())));
    EdgeIterator iter = ee.setBaseNode(qr.getClosestNode());
    iter.next();
    assertTrue(iter.toString(), iter.isForward(carEncoder));
    assertFalse(iter.toString(), iter.isBackward(carEncoder));
    iter.next();
    assertFalse(iter.toString(), iter.isForward(carEncoder));
    assertTrue(iter.toString(), iter.isBackward(carEncoder));
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) Test(org.junit.Test)

Example 18 with QueryResult

use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.

the class QueryGraphTest method testLoopStreet_Issue151.

@Test
public void testLoopStreet_Issue151() {
    // do query at x should result in ignoring only the bottom edge 1-3 not the upper one => getNeighbors are 0, 5, 3 and not only 0, 5
    // 
    // 0--1--3--4
    // |  |
    // x---
    // 
    g.edge(0, 1, 10, true);
    g.edge(1, 3, 10, true);
    g.edge(3, 4, 10, true);
    EdgeIteratorState edge = g.edge(1, 3, 20, true).setWayGeometry(Helper.createPointList(-0.001, 0.001, -0.001, 0.002));
    AbstractRoutingAlgorithmTester.updateDistancesFor(g, 0, 0, 0);
    AbstractRoutingAlgorithmTester.updateDistancesFor(g, 1, 0, 0.001);
    AbstractRoutingAlgorithmTester.updateDistancesFor(g, 3, 0, 0.002);
    AbstractRoutingAlgorithmTester.updateDistancesFor(g, 4, 0, 0.003);
    QueryResult qr = new QueryResult(-0.0005, 0.001);
    qr.setClosestEdge(edge);
    qr.setWayIndex(1);
    qr.calcSnappedPoint(new DistanceCalc2D());
    QueryGraph qg = new QueryGraph(g);
    qg.lookup(Arrays.asList(qr));
    EdgeExplorer ee = qg.createEdgeExplorer();
    assertEquals(GHUtility.asSet(0, 5, 3), GHUtility.getNeighbors(ee.setBaseNode(1)));
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) Test(org.junit.Test)

Example 19 with QueryResult

use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.

the class RoundTripRoutingTemplateTest method testLookupAndCalcPaths_simpleSquareGraph.

@Test
public void testLookupAndCalcPaths_simpleSquareGraph() {
    Graph g = createSquareGraph();
    // start at node 0 and head south, make sure the round trip is long enough to reach most southern node 6
    GHPoint start = new GHPoint(1, -1);
    double heading = 180.0;
    int numPoints = 2;
    double roundTripDistance = 670000;
    GHRequest ghRequest = new GHRequest(Collections.singletonList(start), Collections.singletonList(heading));
    ghRequest.getHints().put(Parameters.Algorithms.RoundTrip.POINTS, numPoints);
    ghRequest.getHints().put(Parameters.Algorithms.RoundTrip.DISTANCE, roundTripDistance);
    LocationIndex locationIndex = new LocationIndexTree(g, new RAMDirectory()).prepareIndex();
    RoundTripRoutingTemplate routingTemplate = new RoundTripRoutingTemplate(ghRequest, new GHResponse(), locationIndex, 1);
    List<QueryResult> stagePoints = routingTemplate.lookup(ghRequest.getPoints(), carFE);
    assertEquals(3, stagePoints.size());
    assertEquals(0, stagePoints.get(0).getClosestNode());
    assertEquals(6, stagePoints.get(1).getClosestNode());
    assertEquals(0, stagePoints.get(2).getClosestNode());
    QueryGraph queryGraph = new QueryGraph(g);
    queryGraph.lookup(stagePoints);
    Weighting weighting = new FastestWeighting(carFE);
    List<Path> paths = routingTemplate.calcPaths(queryGraph, new RoutingAlgorithmFactorySimple(), new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode));
    // make sure the resulting paths are connected and form a round trip starting and ending at the start node 0
    assertEquals(2, paths.size());
    assertEquals(Helper.createTList(0, 7, 6, 5), paths.get(0).calcNodes());
    assertEquals(Helper.createTList(5, 4, 3, 2, 1, 0), paths.get(1).calcNodes());
}
Also used : LocationIndex(com.graphhopper.storage.index.LocationIndex) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) QueryResult(com.graphhopper.storage.index.QueryResult) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) GHRequest(com.graphhopper.GHRequest) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 20 with QueryResult

use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.

the class RoundTripRoutingTemplateTest method testCalcRoundTrip.

@Test
public void testCalcRoundTrip() throws Exception {
    Weighting weighting = new FastestWeighting(carFE);
    Graph g = createTestGraph(true);
    RoundTripRoutingTemplate rTripRouting = new RoundTripRoutingTemplate(new GHRequest(), new GHResponse(), null, 1);
    LocationIndex locationIndex = new LocationIndexTree(g, new RAMDirectory()).prepareIndex();
    QueryResult qr4 = locationIndex.findClosest(0.05, 0.25, EdgeFilter.ALL_EDGES);
    assertEquals(4, qr4.getClosestNode());
    QueryResult qr5 = locationIndex.findClosest(0.00, 0.05, EdgeFilter.ALL_EDGES);
    assertEquals(5, qr5.getClosestNode());
    QueryResult qr6 = locationIndex.findClosest(0.00, 0.10, EdgeFilter.ALL_EDGES);
    assertEquals(6, qr6.getClosestNode());
    QueryGraph qGraph = new QueryGraph(g);
    qGraph.lookup(qr4, qr5);
    rTripRouting.setQueryResults(Arrays.asList(qr5, qr4, qr5));
    List<Path> paths = rTripRouting.calcPaths(qGraph, new RoutingAlgorithmFactorySimple(), new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode));
    assertEquals(2, paths.size());
    assertEquals(Helper.createTList(5, 6, 3, 4), paths.get(0).calcNodes());
    assertEquals(Helper.createTList(4, 8, 7, 6, 5), paths.get(1).calcNodes());
    qGraph = new QueryGraph(g);
    qGraph.lookup(qr4, qr6);
    rTripRouting.setQueryResults(Arrays.asList(qr6, qr4, qr6));
    paths = rTripRouting.calcPaths(qGraph, new RoutingAlgorithmFactorySimple(), new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode));
    assertEquals(2, paths.size());
    assertEquals(Helper.createTList(6, 3, 4), paths.get(0).calcNodes());
    assertEquals(Helper.createTList(4, 8, 7, 6), paths.get(1).calcNodes());
}
Also used : GHResponse(com.graphhopper.GHResponse) LocationIndex(com.graphhopper.storage.index.LocationIndex) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) QueryResult(com.graphhopper.storage.index.QueryResult) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) GHRequest(com.graphhopper.GHRequest) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.Test)

Aggregations

QueryResult (com.graphhopper.storage.index.QueryResult)39 GHPoint (com.graphhopper.util.shapes.GHPoint)20 Test (org.junit.Test)20 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 LocationIndex (com.graphhopper.storage.index.LocationIndex)4 Weighting (com.graphhopper.routing.weighting.Weighting)3 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)3 GHRequest (com.graphhopper.GHRequest)2 GHResponse (com.graphhopper.GHResponse)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)2 GHPoint3D (com.graphhopper.util.shapes.GHPoint3D)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)1 Stop (com.conveyal.gtfs.model.Stop)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GraphHopper (com.graphhopper.GraphHopper)1 GHIntObjectHashMap (com.graphhopper.coll.GHIntObjectHashMap)1