Search in sources :

Example 31 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class CHQueryWithTurnCostsTest method testFindPathWithTurnCosts_loop.

@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testFindPathWithTurnCosts_loop(Fixture f) {
    // 3\
    // |/
    // 0 --- 2 --- 1
    final EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, false, f.encoder, f.graph.edge(0, 2).setDistance(4));
    final EdgeIteratorState edge2 = GHUtility.setSpeed(60, true, true, f.encoder, f.graph.edge(2, 3).setDistance(1));
    final EdgeIteratorState edge3 = GHUtility.setSpeed(60, true, false, f.encoder, f.graph.edge(3, 2).setDistance(7));
    final EdgeIteratorState edge4 = GHUtility.setSpeed(60, true, false, f.encoder, f.graph.edge(2, 1).setDistance(3));
    // need to specify edges explicitly because there are two edges between nodes 2 and 3
    f.setRestriction(edge1, edge4, 2);
    f.setTurnCost(edge1, edge2, 2, 3);
    f.freeze();
    // no shortcuts
    f.setIdentityLevels();
    // without u-turns we need to take the loop
    f.testPathCalculation(0, 1, 15, IntArrayList.from(0, 2, 3, 2, 1), 3);
    // additional check
    f.testPathCalculation(3, 1, 4, IntArrayList.from(3, 2, 1));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 32 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class DirectedBidirectionalDijkstraTest method directedRouting_noUTurnAtVirtualEdge.

@Test
public void directedRouting_noUTurnAtVirtualEdge() {
    // what happens if we force to leave the snapped (virtual) node in eastern direction, even though we would
    // like to go to node 0 just west from us ? we have to make sure there is no u-turn at node 1 (from the
    // virtual edge onto edge 1-0). the query graph does this for us!
    // x
    // 0 -- 1 -> 2
    // |         |
    // 5 <- 4 <- 3
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 2).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 3).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 4).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 5).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 0).setDistance(1));
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 1, 0);
    na.setNode(1, 1, 1);
    na.setNode(2, 1, 2);
    na.setNode(3, 0, 2);
    na.setNode(4, 0, 1);
    na.setNode(5, 0, 0);
    LocationIndexTree locationIndex = new LocationIndexTree(graph, graph.getDirectory());
    locationIndex.prepareIndex();
    Snap snap = locationIndex.findClosest(1.1, 0.5, EdgeFilter.ALL_EDGES);
    QueryGraph queryGraph = QueryGraph.create(graph, snap);
    assertEquals(Snap.Position.EDGE, snap.getSnappedPosition(), "wanted to get EDGE");
    assertEquals(6, snap.getClosestNode());
    // check what edges there are on the query graph directly, there should not be a direct connection from 1 to 0
    // anymore, but only the virtual edge from 1 to 6 (this is how the u-turn is prevented).
    assertEquals(new HashSet<>(Arrays.asList(0, 2)), GHUtility.getNeighbors(graph.createEdgeExplorer().setBaseNode(1)));
    assertEquals(new HashSet<>(Arrays.asList(6, 2)), GHUtility.getNeighbors(queryGraph.createEdgeExplorer().setBaseNode(1)));
    EdgeIteratorState virtualEdge = GHUtility.getEdge(queryGraph, 6, 1);
    int outEdge = virtualEdge.getEdge();
    BidirRoutingAlgorithm algo = createAlgo(queryGraph, weighting);
    Path path = algo.calcPath(6, 0, outEdge, ANY_EDGE);
    assertEquals(nodes(6, 1, 2, 3, 4, 5, 0), path.calcNodes());
    assertEquals(5 + virtualEdge.getDistance(), path.getDistance(), 1.e-3);
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Snap(com.graphhopper.storage.index.Snap) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 33 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class DirectedBidirectionalDijkstraTest method blockArea.

@Test
public void blockArea() {
    // 0 - 1 - 2 - 3
    // |           |
    // 4 --- 5 --- 6
    EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(10));
    EdgeIteratorState edge2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 3).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 4).setDistance(100));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 5).setDistance(100));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 6).setDistance(100));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 3).setDistance(100));
    // usually we would take the direct route
    assertPath(calcPath(0, 3, ANY_EDGE, ANY_EDGE), 1.8, 30, 1800, nodes(0, 1, 2, 3));
    // with forced edges we might have to go around
    assertPath(calcPath(0, 3, 3, ANY_EDGE), 24, 400, 24000, nodes(0, 4, 5, 6, 3));
    assertPath(calcPath(0, 3, ANY_EDGE, 6), 24, 400, 24000, nodes(0, 4, 5, 6, 3));
    // with avoided edges we also have to take a longer route
    assertPath(calcPath(0, 3, ANY_EDGE, ANY_EDGE, createAvoidEdgeWeighting(edge1)), 24, 400, 24000, nodes(0, 4, 5, 6, 3));
    assertPath(calcPath(0, 3, ANY_EDGE, ANY_EDGE, createAvoidEdgeWeighting(edge2)), 24, 400, 24000, nodes(0, 4, 5, 6, 3));
    // enforcing forbidden start/target edges still does not allow using them
    assertNotFound(calcPath(0, 3, edge1.getEdge(), edge2.getEdge(), createAvoidEdgeWeighting(edge1)));
    assertNotFound(calcPath(0, 3, edge1.getEdge(), edge2.getEdge(), createAvoidEdgeWeighting(edge2)));
    // .. even when the nodes are just next to each other
    assertNotFound(calcPath(0, 1, edge1.getEdge(), ANY_EDGE, createAvoidEdgeWeighting(edge1)));
    assertNotFound(calcPath(0, 1, ANY_EDGE, edge2.getEdge(), createAvoidEdgeWeighting(edge2)));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 34 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class TunnelElevationInterpolatorTest method interpolatesElevationOfTunnelWithThreeOuterNodes.

@Test
public void interpolatesElevationOfTunnelWithThreeOuterNodes() {
    // @formatter:off
    /*
         * Graph structure:
         * 0-----1--T--2--T--3-----4
         *             |
         *             |
         *             T
         *             |
         *             |
         *             5--T--6-----7
         */
    // @formatter:on
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0, 0, 0);
    na.setNode(1, 10, 0, 10);
    na.setNode(2, 20, 0, 1000);
    na.setNode(3, 30, 0, 30);
    na.setNode(4, 40, 0, 40);
    na.setNode(5, 20, 10, 1000);
    na.setNode(6, 30, 10, 30);
    na.setNode(7, 40, 10, 40);
    FlagEncoder encoder = encodingManager.getEncoder("car");
    EdgeIteratorState edge01 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(10));
    EdgeIteratorState edge12 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(10));
    EdgeIteratorState edge23 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 3).setDistance(10));
    EdgeIteratorState edge34 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 4).setDistance(10));
    EdgeIteratorState edge25 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 5).setDistance(10));
    EdgeIteratorState edge56 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 6).setDistance(10));
    EdgeIteratorState edge67 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 7).setDistance(10));
    edge01.setFlags(encodingManager.handleWayTags(normalWay, relFlags));
    edge12.setFlags(encodingManager.handleWayTags(interpolatableWay, relFlags));
    edge23.setFlags(encodingManager.handleWayTags(interpolatableWay, relFlags));
    edge34.setFlags(encodingManager.handleWayTags(normalWay, relFlags));
    edge25.setFlags(encodingManager.handleWayTags(interpolatableWay, relFlags));
    edge56.setFlags(encodingManager.handleWayTags(interpolatableWay, relFlags));
    edge67.setFlags(encodingManager.handleWayTags(normalWay, relFlags));
    final GHIntHashSet outerNodeIds = new GHIntHashSet();
    final GHIntHashSet innerNodeIds = new GHIntHashSet();
    gatherOuterAndInnerNodeIdsOfStructure(edge12, outerNodeIds, innerNodeIds);
    assertEquals(GHIntHashSet.from(1, 3, 6), outerNodeIds);
    assertEquals(GHIntHashSet.from(2, 5), innerNodeIds);
    edgeElevationInterpolator.execute();
    assertEquals(0, na.getEle(0), PRECISION);
    assertEquals(10, na.getEle(1), PRECISION);
    assertEquals(20, na.getEle(2), PRECISION);
    assertEquals(30, na.getEle(3), PRECISION);
    assertEquals(40, na.getEle(4), PRECISION);
    assertEquals(20, na.getEle(5), PRECISION);
    assertEquals(30, na.getEle(6), PRECISION);
    assertEquals(40, na.getEle(7), PRECISION);
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.jupiter.api.Test)

Example 35 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class TunnelElevationInterpolatorTest method interpolatesElevationOfTunnelWithFourOuterNodes.

@Test
public void interpolatesElevationOfTunnelWithFourOuterNodes() {
    // @formatter:off
    /*
         * Graph structure:
         * 0-----1--T--2--T--3-----4
         *             |
         *             |
         *             T
         *             |
         *             |
         * 5-----6--T--7--T--8-----9
         */
    // @formatter:on
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0, 0, 0);
    na.setNode(1, 10, 0, 10);
    na.setNode(2, 20, 0, 1000);
    na.setNode(3, 30, 0, 30);
    na.setNode(4, 40, 0, 40);
    na.setNode(5, 0, 10, 40);
    na.setNode(6, 10, 10, 30);
    na.setNode(7, 20, 10, 1000);
    na.setNode(8, 30, 10, 10);
    na.setNode(9, 40, 10, 0);
    FlagEncoder encoder = encodingManager.getEncoder("car");
    EdgeIteratorState edge01, edge12, edge23, edge34, edge56, edge67, edge78, edge89, edge27;
    GHUtility.setSpeed(60, 60, encoder, edge01 = graph.edge(0, 1).setDistance(10), edge12 = graph.edge(1, 2).setDistance(10), edge23 = graph.edge(2, 3).setDistance(10), edge34 = graph.edge(3, 4).setDistance(10), edge56 = graph.edge(5, 6).setDistance(10), edge67 = graph.edge(6, 7).setDistance(10), edge78 = graph.edge(7, 8).setDistance(10), edge89 = graph.edge(8, 9).setDistance(10), edge27 = graph.edge(2, 7).setDistance(10));
    edge01.setFlags(encodingManager.handleWayTags(normalWay, relFlags));
    edge12.setFlags(encodingManager.handleWayTags(interpolatableWay, relFlags));
    edge23.setFlags(encodingManager.handleWayTags(interpolatableWay, relFlags));
    edge34.setFlags(encodingManager.handleWayTags(normalWay, relFlags));
    edge56.setFlags(encodingManager.handleWayTags(normalWay, relFlags));
    edge67.setFlags(encodingManager.handleWayTags(interpolatableWay, relFlags));
    edge78.setFlags(encodingManager.handleWayTags(interpolatableWay, relFlags));
    edge89.setFlags(encodingManager.handleWayTags(normalWay, relFlags));
    edge27.setFlags(encodingManager.handleWayTags(interpolatableWay, relFlags));
    final GHIntHashSet outerNodeIds = new GHIntHashSet();
    final GHIntHashSet innerNodeIds = new GHIntHashSet();
    gatherOuterAndInnerNodeIdsOfStructure(edge12, outerNodeIds, innerNodeIds);
    assertEquals(GHIntHashSet.from(1, 3, 6, 8), outerNodeIds);
    assertEquals(GHIntHashSet.from(2, 7), innerNodeIds);
    edgeElevationInterpolator.execute();
    assertEquals(0, na.getEle(0), PRECISION);
    assertEquals(10, na.getEle(1), PRECISION);
    assertEquals(20, na.getEle(2), PRECISION);
    assertEquals(30, na.getEle(3), PRECISION);
    assertEquals(40, na.getEle(4), PRECISION);
    assertEquals(40, na.getEle(5), PRECISION);
    assertEquals(30, na.getEle(6), PRECISION);
    assertEquals(20, na.getEle(7), PRECISION);
    assertEquals(10, na.getEle(8), PRECISION);
    assertEquals(0, na.getEle(9), PRECISION);
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.jupiter.api.Test)

Aggregations

EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)137 Test (org.junit.jupiter.api.Test)55 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)25 Test (org.junit.Test)22 RepeatedTest (org.junit.jupiter.api.RepeatedTest)17 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)13 Snap (com.graphhopper.storage.index.Snap)12 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)11 CHEdgeIteratorState (com.graphhopper.util.CHEdgeIteratorState)11 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)10 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)10 NodeAccess (com.graphhopper.storage.NodeAccess)10 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)9 GraphBuilder (com.graphhopper.storage.GraphBuilder)8 QueryRoutingCHGraph (com.graphhopper.routing.querygraph.QueryRoutingCHGraph)7 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)6 EncodingManager (com.graphhopper.routing.util.EncodingManager)6 GHPoint (com.graphhopper.util.shapes.GHPoint)6 Fun (org.mapdb.Fun)6 IntArrayList (com.carrotsearch.hppc.IntArrayList)5