Search in sources :

Example 21 with EdgeExplorer

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

the class OSMTurnRelationParser method addRelationToTCStorage.

/**
 * Add the specified relation to the TurnCostStorage
 */
void addRelationToTCStorage(OSMTurnRelation osmTurnRelation, ExternalInternalMap map, Graph graph) {
    TurnCostStorage tcs = graph.getTurnCostStorage();
    int viaNode = map.getInternalNodeIdOfOsmNode(osmTurnRelation.getViaOsmNodeId());
    EdgeExplorer edgeOutExplorer = getOutExplorer(graph), edgeInExplorer = getInExplorer(graph);
    try {
        int edgeIdFrom = EdgeIterator.NO_EDGE;
        // get all incoming edges and receive the edge which is defined by fromOsm
        EdgeIterator iter = edgeInExplorer.setBaseNode(viaNode);
        while (iter.next()) {
            if (map.getOsmIdOfInternalEdge(iter.getEdge()) == osmTurnRelation.getOsmIdFrom()) {
                edgeIdFrom = iter.getEdge();
                break;
            }
        }
        if (!EdgeIterator.Edge.isValid(edgeIdFrom))
            return;
        // get all outgoing edges of the via node
        iter = edgeOutExplorer.setBaseNode(viaNode);
        // for TYPE_NOT_*  we add ONE restriction  (from, via, to)
        while (iter.next()) {
            int edgeId = iter.getEdge();
            long wayId = map.getOsmIdOfInternalEdge(edgeId);
            if (edgeId != edgeIdFrom && osmTurnRelation.getRestriction() == OSMTurnRelation.Type.ONLY && wayId != osmTurnRelation.getOsmIdTo() || osmTurnRelation.getRestriction() == OSMTurnRelation.Type.NOT && wayId == osmTurnRelation.getOsmIdTo() && wayId >= 0) {
                tcs.set(turnCostEnc, edgeIdFrom, viaNode, iter.getEdge(), Double.POSITIVE_INFINITY);
                if (osmTurnRelation.getRestriction() == OSMTurnRelation.Type.NOT)
                    break;
            }
        }
    } catch (Exception e) {
        throw new IllegalStateException("Could not built turn table entry for relation of node with osmId:" + osmTurnRelation.getViaOsmNodeId(), e);
    }
}
Also used : EdgeIterator(com.graphhopper.util.EdgeIterator) EdgeExplorer(com.graphhopper.util.EdgeExplorer) TurnCostStorage(com.graphhopper.storage.TurnCostStorage)

Example 22 with EdgeExplorer

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

the class EdgeBasedTarjanSCC method findComponentForEdgeKey.

private void findComponentForEdgeKey(int p, int adjNode) {
    setupNextEdgeKey(p);
    // we have to create a new explorer on each iteration because of the nested edge iterations
    final int edge = getEdgeFromKey(p);
    EdgeExplorer explorer = graph.createEdgeExplorer();
    EdgeIterator iter = explorer.setBaseNode(adjNode);
    while (iter.next()) {
        if (!edgeTransitionFilter.accept(edge, iter))
            continue;
        int q = createEdgeKey(iter, false);
        handleNeighbor(p, q, iter.getAdjNode());
        // both ways
        if (iter.getBaseNode() == iter.getAdjNode())
            handleNeighbor(p, q + 1, iter.getAdjNode());
    }
    buildComponent(p);
}
Also used : EdgeIterator(com.graphhopper.util.EdgeIterator) EdgeExplorer(com.graphhopper.util.EdgeExplorer)

Aggregations

EdgeExplorer (com.graphhopper.util.EdgeExplorer)22 Test (org.junit.Test)10 EdgeIterator (com.graphhopper.util.EdgeIterator)8 Graph (com.graphhopper.storage.Graph)7 GraphBuilder (com.graphhopper.storage.GraphBuilder)5 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)3 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)3 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)2 SPTEntry (com.graphhopper.storage.SPTEntry)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntIntHashMap (com.carrotsearch.hppc.IntIntHashMap)1 IntLongHashMap (com.carrotsearch.hppc.IntLongHashMap)1 GTFSFeed (com.conveyal.gtfs.GTFSFeed)1 Agency (com.conveyal.gtfs.model.Agency)1 Fare (com.conveyal.gtfs.model.Fare)1 StopTime (com.conveyal.gtfs.model.StopTime)1