Search in sources :

Example 81 with EdgeIteratorState

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

the class FakeWalkNetworkBuilder method buildWalkNetwork.

static void buildWalkNetwork(Collection<GTFSFeed> feeds, GraphHopperStorage graph, PtFlagEncoder encoder, DistanceCalc distCalc) {
    Collection<ConstraintVertex> sites = new ArrayList<>();
    Map<Vertex, Integer> vertex2nodeId = new HashMap<>();
    feeds.stream().flatMap(feed -> feed.stops.values().stream()).forEach(stop -> {
        int i = graph.getNodes();
        graph.getNodeAccess().setNode(i++, stop.stop_lat, stop.stop_lon);
        ConstraintVertex site = new ConstraintVertex(new Coordinate(stop.stop_lon, stop.stop_lat));
        sites.add(site);
        vertex2nodeId.put(site, i - 1);
    });
    ConformingDelaunayTriangulator conformingDelaunayTriangulator = new ConformingDelaunayTriangulator(sites, 0.0);
    conformingDelaunayTriangulator.setConstraints(new ArrayList(), new ArrayList());
    conformingDelaunayTriangulator.formInitialDelaunay();
    QuadEdgeSubdivision tin = conformingDelaunayTriangulator.getSubdivision();
    List<QuadEdge> edges = tin.getPrimaryEdges(false);
    for (QuadEdge edge : edges) {
        EdgeIteratorState ghEdge = graph.edge(vertex2nodeId.get(edge.orig()), vertex2nodeId.get(edge.dest()));
        double distance = distCalc.calcDist(edge.orig().getY(), edge.orig().getX(), edge.dest().getY(), edge.dest().getX());
        ghEdge.setDistance(distance);
        ghEdge.setFlags(encoder.setSpeed(ghEdge.getFlags(), 5.0));
        ghEdge.setFlags(encoder.setAccess(ghEdge.getFlags(), true, true));
    }
}
Also used : GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Coordinate(com.vividsolutions.jts.geom.Coordinate) QuadEdge(com.vividsolutions.jts.triangulate.quadedge.QuadEdge) java.util(java.util) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) ConformingDelaunayTriangulator(com.vividsolutions.jts.triangulate.ConformingDelaunayTriangulator) ConstraintVertex(com.vividsolutions.jts.triangulate.ConstraintVertex) Vertex(com.vividsolutions.jts.triangulate.quadedge.Vertex) GTFSFeed(com.conveyal.gtfs.GTFSFeed) DistanceCalc(com.graphhopper.util.DistanceCalc) QuadEdgeSubdivision(com.vividsolutions.jts.triangulate.quadedge.QuadEdgeSubdivision) ConstraintVertex(com.vividsolutions.jts.triangulate.ConstraintVertex) Vertex(com.vividsolutions.jts.triangulate.quadedge.Vertex) QuadEdge(com.vividsolutions.jts.triangulate.quadedge.QuadEdge) ConformingDelaunayTriangulator(com.vividsolutions.jts.triangulate.ConformingDelaunayTriangulator) QuadEdgeSubdivision(com.vividsolutions.jts.triangulate.quadedge.QuadEdgeSubdivision) ConstraintVertex(com.vividsolutions.jts.triangulate.ConstraintVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Example 82 with EdgeIteratorState

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

the class GtfsReader method insertInboundTransfers.

private void insertInboundTransfers(String fromStopId, String from_route_id, int minimumTransferTime, SortedSet<Fun.Tuple2<Integer, Integer>> toStopTimelineNode) {
    int stationNode = gtfsStorage.getStationNodes().get(fromStopId);
    EdgeIterator i = graph.createEdgeExplorer().setBaseNode(stationNode);
    while (i.next()) {
        GtfsStorage.EdgeType edgeType = encoder.getEdgeType(i.getFlags());
        if (edgeType == GtfsStorage.EdgeType.EXIT_PT) {
            String routeId = gtfsStorage.getRoutes().get(i.getEdge());
            if (from_route_id == null || from_route_id.equals(routeId)) {
                EdgeIterator j = graph.createEdgeExplorer().setBaseNode(i.getAdjNode());
                while (j.next()) {
                    GtfsStorage.EdgeType edgeType2 = encoder.getEdgeType(j.getFlags());
                    if (edgeType2 == GtfsStorage.EdgeType.LEAVE_TIME_EXPANDED_NETWORK) {
                        int arrivalTime = (int) encoder.getTime(j.getFlags());
                        SortedSet<Fun.Tuple2<Integer, Integer>> tailSet = toStopTimelineNode.tailSet(new Fun.Tuple2<>(arrivalTime + minimumTransferTime, -1));
                        if (!tailSet.isEmpty()) {
                            Fun.Tuple2<Integer, Integer> e = tailSet.first();
                            EdgeIteratorState edge = graph.edge(j.getAdjNode(), e.b, 0.0, false);
                            setEdgeType(edge, GtfsStorage.EdgeType.TRANSFER);
                            edge.setFlags(encoder.setTime(edge.getFlags(), e.a - arrivalTime));
                        }
                    }
                }
            }
        }
    }
}
Also used : EdgeIterator(com.graphhopper.util.EdgeIterator) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Fun(org.mapdb.Fun)

Example 83 with EdgeIteratorState

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

the class GtfsReader method addDelayedBoardEdge.

int addDelayedBoardEdge(ZoneId zoneId, GtfsRealtime.TripDescriptor tripDescriptor, int stopSequence, int departureTime, int departureNode, BitSet validOnDay) {
    Trip trip = feed.trips.get(tripDescriptor.getTripId());
    final int departureTimelineNode = i++;
    StopTime stopTime = feed.stop_times.get(new Fun.Tuple2(tripDescriptor.getTripId(), stopSequence));
    Stop stop = feed.stops.get(stopTime.stop_id);
    nodeAccess.setNode(departureTimelineNode, stop.stop_lat, stop.stop_lon);
    nodeAccess.setAdditionalNodeField(departureTimelineNode, NodeType.INTERNAL_PT.ordinal());
    times.put(departureTimelineNode, departureTime);
    departureTimelineNodes.put(stopTime.stop_id, new TimelineNodeIdWithTripId(departureTimelineNode, tripDescriptor.getTripId(), trip.route_id));
    int dayShift = departureTime / (24 * 60 * 60);
    GtfsStorage.Validity validOn = new GtfsStorage.Validity(getValidOn(validOnDay, dayShift), zoneId, startDate);
    int validityId;
    if (gtfsStorage.getOperatingDayPatterns().containsKey(validOn)) {
        validityId = gtfsStorage.getOperatingDayPatterns().get(validOn);
    } else {
        validityId = gtfsStorage.getOperatingDayPatterns().size();
        gtfsStorage.getOperatingDayPatterns().put(validOn, validityId);
    }
    EdgeIteratorState boardEdge = graph.edge(departureTimelineNode, departureNode, 0.0, false);
    boardEdge.setName(getRouteName(feed, trip));
    setEdgeType(boardEdge, GtfsStorage.EdgeType.BOARD);
    gtfsStorage.getStopSequences().put(boardEdge.getEdge(), stopSequence);
    gtfsStorage.getTripDescriptors().put(boardEdge.getEdge(), tripDescriptor.toByteArray());
    boardEdge.setFlags(encoder.setValidityId(boardEdge.getFlags(), validityId));
    boardEdge.setFlags(encoder.setTransfers(boardEdge.getFlags(), 1));
    return boardEdge.getEdge();
}
Also used : Trip(com.conveyal.gtfs.model.Trip) Stop(com.conveyal.gtfs.model.Stop) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Fun(org.mapdb.Fun) StopTime(com.conveyal.gtfs.model.StopTime)

Example 84 with EdgeIteratorState

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

the class InstructionsOutgoingEdges method isLeavingCurrentStreet.

/**
 * If the name and prevName changes this method checks if either the current street is continued on a
 * different edge or if the edge we are turning onto is continued on a different edge.
 * If either of these properties is true, we can be quite certain that a turn instruction should be provided.
 */
public boolean isLeavingCurrentStreet(String prevName, String name) {
    if (InstructionsHelper.isNameSimilar(name, prevName)) {
        return false;
    }
    // If flags are changing, there might be a chance we find these flags on a different edge
    boolean checkFlag = currentEdge.getFlags() != prevEdge.getFlags();
    for (EdgeIteratorState edge : allowedOutgoingEdges) {
        String edgeName = edge.getName();
        long edgeFlag = edge.getFlags();
        // leave the current street || enter a different street
        if (isTheSameStreet(prevName, prevEdge.getFlags(), edgeName, edgeFlag, checkFlag) || isTheSameStreet(name, currentEdge.getFlags(), edgeName, edgeFlag, checkFlag)) {
            return true;
        }
    }
    return false;
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Example 85 with EdgeIteratorState

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

the class NodeContractorTest method testFindShortcuts_Roundabout.

@Test
public void testFindShortcuts_Roundabout() {
    // 1 -- 3 -- 4 ---> 5 ---> 6 -- 7
    // \           /
    // <--- 8 <---
    final EdgeIteratorState iter1to3 = graph.edge(1, 3, 1, true);
    final EdgeIteratorState iter3to4 = graph.edge(3, 4, 1, true);
    final EdgeIteratorState iter4to5 = graph.edge(4, 5, 1, false);
    final EdgeIteratorState iter5to6 = graph.edge(5, 6, 1, false);
    final EdgeIteratorState iter6to8 = graph.edge(6, 8, 2, false);
    final EdgeIteratorState iter8to4 = graph.edge(8, 4, 1, false);
    graph.edge(6, 7, 1, true);
    graph.freeze();
    CHEdgeIteratorState sc1to4 = lg.shortcut(1, 4);
    sc1to4.setFlags(PrepareEncoder.getScDirMask());
    sc1to4.setWeight(2);
    sc1to4.setDistance(2);
    sc1to4.setSkippedEdges(iter1to3.getEdge(), iter3to4.getEdge());
    long f = PrepareEncoder.getScFwdDir();
    CHEdgeIteratorState sc4to6 = lg.shortcut(4, 6);
    sc4to6.setFlags(f);
    sc4to6.setWeight(2);
    sc4to6.setDistance(2);
    sc4to6.setSkippedEdges(iter4to5.getEdge(), iter5to6.getEdge());
    CHEdgeIteratorState sc6to4 = lg.shortcut(6, 4);
    sc6to4.setFlags(f);
    sc6to4.setWeight(3);
    sc6to4.setDistance(3);
    sc6to4.setSkippedEdges(iter6to8.getEdge(), iter8to4.getEdge());
    setMaxLevelOnAllNodes();
    lg.setLevel(3, 3);
    lg.setLevel(5, 5);
    lg.setLevel(7, 7);
    lg.setLevel(8, 8);
    Shortcut manualSc1 = expectedShortcut(1, 4, iter1to3, iter3to4, true, true);
    Shortcut manualSc2 = expectedShortcut(4, 6, iter4to5, iter5to6, true, false);
    Shortcut manualSc3 = expectedShortcut(4, 6, iter6to8, iter8to4, false, true);
    checkShortcuts(manualSc1, manualSc2, manualSc3);
    // after 'manual contraction' of nodes 3, 5, 8 the graph looks like:
    // 1 -- 4 -->-- 6 -- 7
    // \      |
    // --<----
    // contract node 4!
    NodeContractor nodeContractor = createNodeContractor();
    nodeContractor.contractNode(4);
    checkShortcuts(manualSc1, manualSc2, manualSc3, // there should be two different shortcuts for both directions!
    expectedShortcut(1, 6, sc1to4, sc4to6, true, false), expectedShortcut(1, 6, sc6to4, sc1to4, false, true));
}
Also used : CHEdgeIteratorState(com.graphhopper.util.CHEdgeIteratorState) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) CHEdgeIteratorState(com.graphhopper.util.CHEdgeIteratorState) Test(org.junit.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