Search in sources :

Example 46 with EdgeIteratorState

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

the class AlternativeRoute method getAltNames.

static List<String> getAltNames(Graph graph, SPTEntry ee) {
    if (ee == null || !EdgeIterator.Edge.isValid(ee.edge))
        return Collections.emptyList();
    EdgeIteratorState iter = graph.getEdgeIteratorState(ee.edge, Integer.MIN_VALUE);
    if (iter == null)
        return Collections.emptyList();
    String str = iter.getName();
    if (str.isEmpty())
        return Collections.emptyList();
    return Collections.singletonList(str);
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Example 47 with EdgeIteratorState

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

the class QueryGraph method createEdgeExplorer.

@Override
public EdgeExplorer createEdgeExplorer(final EdgeFilter edgeFilter) {
    // re-use these objects between setBaseNode calls to prevent GC
    final EdgeExplorer mainExplorer = baseGraph.createEdgeExplorer(edgeFilter);
    final VirtualEdgeIterator virtualEdgeIterator = new VirtualEdgeIterator(edgeFilter, null);
    return new EdgeExplorer() {

        @Override
        public EdgeIterator setBaseNode(int baseNode) {
            if (isVirtualNode(baseNode)) {
                List<EdgeIteratorState> virtualEdges = virtualEdgesAtVirtualNodes.get(baseNode - baseNodes);
                return virtualEdgeIterator.reset(virtualEdges);
            } else {
                List<EdgeIteratorState> virtualEdges = virtualEdgesAtRealNodes.get(baseNode);
                if (virtualEdges == null) {
                    return mainExplorer.setBaseNode(baseNode);
                } else {
                    return virtualEdgeIterator.reset(virtualEdges);
                }
            }
        }
    };
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) EdgeExplorer(com.graphhopper.util.EdgeExplorer)

Example 48 with EdgeIteratorState

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

the class EdgeChangeBuilder method addVirtualEdges.

/**
 * Adds the virtual edges adjacent to the real tower nodes
 */
private void addVirtualEdges(boolean base, int node, int virtNode) {
    QueryOverlay.EdgeChanges edgeChanges = edgeChangesAtRealNodes.get(node);
    if (edgeChanges == null) {
        edgeChanges = new QueryOverlay.EdgeChanges(2, 2);
        edgeChangesAtRealNodes.put(node, edgeChanges);
    }
    EdgeIteratorState edge = base ? getVirtualEdge(virtNode * 4 + BASE_SNAP) : getVirtualEdge(virtNode * 4 + ADJ_SNAP);
    edgeChanges.getAdditionalEdges().add(edge);
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Example 49 with EdgeIteratorState

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

the class EdgeBasedNodeContractorTest method testContractNodes_necessaryAlternative.

@Test
public void testContractNodes_necessaryAlternative() {
    // 1
    // |    can't go 1->6->3
    // v
    // 2 -> 6 -> 3 -> 5 -> 4
    // |    ^
    // -> 0-|
    final EdgeIteratorState e6to0 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(6, 0).setDistance(4));
    final EdgeIteratorState e0to3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 3).setDistance(5));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 6).setDistance(1));
    final EdgeIteratorState e6to3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(6, 3).setDistance(1));
    final EdgeIteratorState e3to5 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 5).setDistance(2));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 6).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 4).setDistance(2));
    freeze();
    setMaxLevelOnAllNodes();
    setRestriction(1, 6, 3);
    contractAllNodesInOrder();
    checkShortcuts(// from contracting node 0: need a shortcut because of turn restriction
    createShortcut(3, 6, e6to0, e0to3, 9, false, true), // 2) in case we come from 2->6 (going via node 0 would be more expensive)
    createShortcut(5, 6, e6to0.getEdge(), e3to5.getEdge(), 7, e3to5.getEdge(), 11, false, true), createShortcut(5, 6, e6to3, e3to5, 3, 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 50 with EdgeIteratorState

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

the class EdgeBasedNodeContractorTest method testContractNode_noUnnecessaryShortcut_witnessPathOfEqualWeight.

@RepeatedTest(10)
public void testContractNode_noUnnecessaryShortcut_witnessPathOfEqualWeight() {
    // this test runs repeatedly because it might pass/fail by chance (because path lengths are equal)
    // 0 -> 1 -> 5 <_
    // v    v   \
    // 2 -> 3 -> 4
    GHUtility.setSpeed(60, true, false, 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(1, 5).setDistance(1));
    EdgeIteratorState e2to3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 3).setDistance(1));
    EdgeIteratorState e3to4 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 4).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 5).setDistance(1));
    EdgeIteratorState e5to3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 3).setDistance(1));
    freeze();
    setMaxLevelOnAllNodes();
    contractNodes(3, 2, 0, 1, 5, 4);
    // when contracting node 2 there is a witness (1-5-3-4) and no shortcut from 1 to 4 should be introduced.
    // what might be tricky here is that both the original path and the witness path have equal weight!
    // so we have to make sure that the equal weight witness is not rejected to update the currently best
    // path, or (depending on the implementation-specific edge traversal order) the original path does *not*
    // update/overwrite the already found witness path.
    checkShortcuts(createShortcut(2, 4, e2to3, e3to4, 2), createShortcut(5, 4, e5to3, e3to4, 2));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

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