Search in sources :

Example 51 with EdgeIteratorState

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

the class EdgeBasedNodeContractorTest method testNodeContraction_forwardLoopNeedsToBeRecognizedAsIncoming.

@Test
public void testNodeContraction_forwardLoopNeedsToBeRecognizedAsIncoming() {
    // ---
    // \ /
    // 0 -- 1 -- 2 -- 3 -- 4
    EdgeIteratorState edge0 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(1));
    EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 1).setDistance(1));
    EdgeIteratorState edge2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(1));
    EdgeIteratorState edge3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 3).setDistance(1));
    EdgeIteratorState edge4 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 4).setDistance(1));
    setRestriction(edge0, edge2, 1);
    freeze();
    setMaxLevelOnAllNodes();
    contractNodes(2, 0, 4, 1, 3);
    checkShortcuts(// i.e. it has only a fwd flag
    createShortcut(1, 3, edge2, edge3, 2));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 52 with EdgeIteratorState

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

the class EdgeBasedNodeContractorTest method testNodeContraction_parallelEdges_onlyOneLoopShortcutNeeded.

@Test
public void testNodeContraction_parallelEdges_onlyOneLoopShortcutNeeded() {
    // 0 -- 1 -- 2
    // \--/
    EdgeIteratorState edge0 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(2));
    EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 0).setDistance(4));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(5));
    setTurnCost(edge0, edge1, 0, 1);
    setTurnCost(edge1, edge0, 0, 2);
    freeze();
    setMaxLevelOnAllNodes();
    contractNodes(0, 2, 1);
    // it is sufficient to be able to travel the 1-0-1 loop in one (the cheaper) direction
    checkShortcuts(createShortcut(1, 1, 0, 1, 0, 1, 7));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 53 with EdgeIteratorState

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

the class EdgeBasedNodeContractorTest method testContractNode_twoNormalEdges_bidirectional_differentCosts.

@Test
public void testContractNode_twoNormalEdges_bidirectional_differentCosts() {
    // 0 -- 3 -- 2 -- 4 -- 1
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 3).setDistance(1));
    final EdgeIteratorState e2to3 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 2).setDistance(3));
    final EdgeIteratorState e2to4 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 4).setDistance(5));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 1).setDistance(1));
    setTurnCost(e2to3, e2to4, 2, 4);
    setTurnCost(e2to4, e2to3, 2, 7);
    freeze();
    setMaxLevelOnAllNodes();
    contractNodes(2, 0, 1, 3, 4);
    checkShortcuts(createShortcut(3, 4, e2to3, e2to4, 12, true, false), createShortcut(3, 4, e2to4, e2to3, 15, false, true));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 54 with EdgeIteratorState

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

the class EdgeBasedNodeContractorTest method runTestWithTurnCostAndLoop.

private void runTestWithTurnCostAndLoop(boolean loopHelps) {
    // />\
    // \ /
    // 0 --> 3 --> 2 --> 4 --> 1
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 3).setDistance(1));
    final EdgeIteratorState e3to2 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 2).setDistance(3));
    final EdgeIteratorState e2to2 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 2).setDistance(2));
    final EdgeIteratorState e2to4 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 4).setDistance(5));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 1).setDistance(1));
    setTurnCost(e3to2, e2to2, 2, 2);
    setTurnCost(e2to2, e2to4, 2, 1);
    setTurnCost(e3to2, e2to4, 2, loopHelps ? 6 : 3);
    freeze();
    setMaxLevelOnAllNodes();
    contractNodes(2, 0, 1, 3, 4);
    if (loopHelps) {
        // it is better to take the loop at node 2, so we need to introduce two shortcuts where the second contains
        // the first (this is important for path unpacking)
        checkShortcuts(createShortcut(2, 3, e3to2, e2to2, 7, false, true), createShortcut(3, 4, e3to2.getEdge(), e2to4.getEdge(), 5, e2to4.getEdge(), 13, true, false));
    } else {
        // taking the loop would be worse, so the path is just 3-2-4 and we only need a single shortcut
        checkShortcuts(createShortcut(3, 4, e3to2, e2to4, 11));
    }
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Example 55 with EdgeIteratorState

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

the class EdgeBasedNodeContractorTest method testContractNode_twoNormalEdges_noTurncosts.

@Test
public void testContractNode_twoNormalEdges_noTurncosts() {
    // 0 --> 3 --> 2 --> 4 --> 1
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 3).setDistance(1));
    final EdgeIteratorState e3to2 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 2).setDistance(3));
    final EdgeIteratorState e2to4 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 4).setDistance(5));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 1).setDistance(1));
    freeze();
    setMaxLevelOnAllNodes();
    EdgeBasedNodeContractor nodeContractor = createNodeContractor();
    contractNode(nodeContractor, 0, 0);
    contractNode(nodeContractor, 1, 1);
    // no shortcuts so far
    checkShortcuts();
    // contracting node 2 should yield a shortcut to preserve the shortest path from (1->2) to (3->4). note that
    // it does not matter that nodes 0 and 1 have lower level and are contracted already!
    contractNode(nodeContractor, 2, 2);
    contractNode(nodeContractor, 3, 3);
    contractNode(nodeContractor, 4, 4);
    nodeContractor.finishContraction();
    checkShortcuts(createShortcut(3, 4, e3to2, e2to4, 8));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) RepeatedTest(org.junit.jupiter.api.RepeatedTest) 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