Search in sources :

Example 61 with EdgeIteratorState

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

the class NodeBasedNodeContractorTest method testShortcutMergeBug.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testShortcutMergeBug(boolean reverse) {
    // We refer to this real world situation http://www.openstreetmap.org/#map=19/52.71205/-1.77326
    // assume the following graph:
    // 
    // ---1---->----2-----3
    // \--------/
    // 
    // where there are two roads from 1 to 2 and the directed road has a smaller weight. to get from 2 to 1 we
    // have to use the bidirectional edge despite the higher weight and therefore we need an extra shortcut for
    // this.
    final EdgeIteratorState edge1to2bidirected = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(2));
    final EdgeIteratorState edge1to2directed = GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 2).setDistance(1));
    final EdgeIteratorState edge2to3 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 3).setDistance(1));
    freeze();
    setMaxLevelOnAllNodes();
    if (reverse) {
        contractInOrder(2, 1, 3);
        checkShortcuts(expectedShortcut(1, 3, edge1to2directed, edge2to3, true, false), expectedShortcut(1, 3, edge1to2bidirected, edge2to3, false, true));
    } else {
        contractInOrder(2, 3, 1);
        checkShortcuts(expectedShortcut(3, 1, edge2to3, edge1to2bidirected, true, false), expectedShortcut(3, 1, edge2to3, edge1to2directed, false, true));
    }
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with EdgeIteratorState

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

the class NodeBasedNodeContractorTest method testContractNode_bidirected_shortcutsRequired.

@Test
public void testContractNode_bidirected_shortcutsRequired() {
    // 0 -- 1 -- 2
    final EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(1));
    final EdgeIteratorState edge2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(2));
    freeze();
    contractInOrder(1, 2, 0);
    checkShortcuts(expectedShortcut(2, 0, edge2, edge1, true, true));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 63 with EdgeIteratorState

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

the class NodeBasedNodeContractorTest method testFindShortcuts_Roundabout.

@Test
public void testFindShortcuts_Roundabout() {
    // 1 -- 3 -- 4 ---> 5 ---> 6 -- 7
    // \           /
    // <--- 8 <---
    final EdgeIteratorState iter1to3 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 3).setDistance(1));
    final EdgeIteratorState iter3to4 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 4).setDistance(1));
    final EdgeIteratorState iter4to5 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 5).setDistance(1));
    final EdgeIteratorState iter5to6 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 6).setDistance(1));
    final EdgeIteratorState iter6to8 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(6, 8).setDistance(2));
    final EdgeIteratorState iter8to4 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(8, 4).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 7).setDistance(1));
    freeze();
    contractInOrder(3, 5, 7, 8, 4, 1, 6);
    // note: after contraction of nodes 3, 5, 8 the graph looks like this:
    // 1 -- 4 -->-- 6 -- 7
    // \      |
    // --<----
    RoutingCHGraph lg = graph.createCHGraph(store, chConfig);
    checkShortcuts(expectedShortcut(4, 1, iter3to4, iter1to3, true, true), expectedShortcut(4, 6, iter8to4, iter6to8, false, true), expectedShortcut(4, 6, iter4to5, iter5to6, true, false), // there should be two different shortcuts for both directions!
    expectedShortcut(1, 6, lg.getEdgeIteratorState(8, 4), lg.getEdgeIteratorState(7, 6), true, false), expectedShortcut(1, 6, lg.getEdgeIteratorState(8, 1), lg.getEdgeIteratorState(9, 4), false, true));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 64 with EdgeIteratorState

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

the class NodeBasedNodeContractorTest method testContractNode_directed_shortcutRequired_reverse.

@Test
public void testContractNode_directed_shortcutRequired_reverse() {
    // 0 <-- 1 <-- 2
    final EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 1).setDistance(1));
    final EdgeIteratorState edge2 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 0).setDistance(2));
    freeze();
    setMaxLevelOnAllNodes();
    contractInOrder(1, 2, 0);
    checkShortcuts(expectedShortcut(2, 0, edge1, edge2, true, false));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with EdgeIteratorState

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

the class NodeBasedNodeContractorTest method testContractNode_directed_shortcutRequired.

@Test
public void testContractNode_directed_shortcutRequired() {
    // 0 --> 1 --> 2
    final EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 1).setDistance(1));
    final EdgeIteratorState edge2 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 2).setDistance(2));
    freeze();
    setMaxLevelOnAllNodes();
    contractInOrder(1, 0, 2);
    checkShortcuts(expectedShortcut(0, 2, edge1, edge2, true, false));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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