Search in sources :

Example 6 with EdgeIteratorState

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

the class NameSimilarityEdgeFilterTest method testThatShouldSucceed.

@Ignore
public void testThatShouldSucceed() {
    EdgeFilter edgeFilter;
    EdgeIteratorState edge;
    // The Problem is that Rd vs Road is abreviated, if we have Road, it works
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "257 Main Rd, Claremont, Cape Town, 7708, Afrique du Sud");
    edge = createTestEdgeIterator("Main Road");
    assertTrue(edgeFilter.accept(edge));
    // Just too much difference Between Google Maps and OSM @ 32.121435,-110.857969
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "7202 S Wilmot Rd, Tucson, AZ 85701");
    edge = createTestEdgeIterator("South Wilmot Road");
    assertTrue(edgeFilter.accept(edge));
    // @ 37.307774,13.581259
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Via Manzoni, 50/52, 92100 Agrigento AG, Italy");
    edge = createTestEdgeIterator("Via Alessandro Manzoni");
    assertTrue(edgeFilter.accept(edge));
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Av. Juan Ramón Ramírez, 12, 02630 La Roda, Albacete, Spain");
    edge = createTestEdgeIterator("Avenida Juan Ramón Ramírez");
    assertTrue(edgeFilter.accept(edge));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Ignore(org.junit.Ignore)

Example 7 with EdgeIteratorState

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

the class LocationIndexTreeCHTest method testCHGraphBug.

@Test
public void testCHGraphBug() {
    // 0
    // |
    // | X  2--3
    // |
    // 1
    GraphHopperStorage g = createGHStorage(new RAMDirectory(), encodingManager, false);
    NodeAccess na = g.getNodeAccess();
    na.setNode(0, 1, 0);
    na.setNode(1, 0, 0);
    na.setNode(2, 0.5, 0.5);
    na.setNode(3, 0.5, 1);
    EdgeIteratorState iter1 = g.edge(1, 0, 100, true);
    g.edge(2, 3, 100, true);
    CHGraphImpl lg = (CHGraphImpl) g.getGraph(CHGraph.class);
    g.freeze();
    lg.setLevel(0, 11);
    lg.setLevel(1, 10);
    // disconnect higher 0 from lower 1
    lg.disconnect(lg.createEdgeExplorer(), iter1);
    lg.setLevel(2, 12);
    lg.setLevel(3, 13);
    // disconnect higher 3 from lower 2
    lg.disconnect(lg.createEdgeExplorer(), iter1);
    LocationIndexTree index = createIndex(g, 100000);
    // very close to 2, but should match the edge 0--1
    GHIntHashSet set = new GHIntHashSet();
    index.findNetworkEntries(0.51, 0.2, set, 0);
    index.findNetworkEntries(0.51, 0.2, set, 1);
    IntSet expectedSet = new GHIntHashSet();
    expectedSet.add(0);
    expectedSet.add(2);
    assertEquals(expectedSet, set);
    assertEquals(0, findID(index, 0.51, 0.2));
    assertEquals(1, findID(index, 0.1, 0.1));
    assertEquals(2, findID(index, 0.51, 0.51));
    assertEquals(3, findID(index, 0.51, 1.1));
}
Also used : GHIntHashSet(com.graphhopper.coll.GHIntHashSet) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) CHEdgeIteratorState(com.graphhopper.util.CHEdgeIteratorState) IntSet(com.carrotsearch.hppc.IntSet) Test(org.junit.Test)

Example 8 with EdgeIteratorState

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

the class GtfsReader method wireUpStops.

void wireUpStops() {
    for (Stop stop : feed.stops.values()) {
        if (stop.location_type == 0) {
            // Only stops. Not interested in parent stations for now.
            int streetNode = gtfsStorage.getStationNodes().get(stop.stop_id);
            if (arrivalTimelineNodes.containsKey(stop.stop_id)) {
                final Map<String, List<TimelineNodeIdWithTripId>> arrivalTimelineNodesByRoute = arrivalTimelineNodes.get(stop.stop_id).stream().collect(Collectors.groupingBy(t -> t.routeId));
                arrivalTimelineNodesByRoute.forEach((routeId, timelineNodesWithTripId) -> {
                    nodeAccess.setNode(i++, stop.stop_lat, stop.stop_lon);
                    int stopExitNode = i - 1;
                    nodeAccess.setAdditionalNodeField(stopExitNode, NodeType.STOP_EXIT_NODE.ordinal());
                    EdgeIteratorState exitEdge = graph.edge(stopExitNode, streetNode, 0.0, false);
                    setEdgeType(exitEdge, GtfsStorage.EdgeType.EXIT_PT);
                    exitEdge.setName(stop.stop_name);
                    gtfsStorage.getRoutes().put(exitEdge.getEdge(), routeId);
                    NavigableSet<Fun.Tuple2<Integer, Integer>> timeNodes = sorted(timelineNodesWithTripId);
                    wireUpAndAndConnectArrivalTimeline(stop, routeId, stopExitNode, timeNodes);
                });
            }
            if (departureTimelineNodes.containsKey(stop.stop_id)) {
                final Map<String, List<TimelineNodeIdWithTripId>> departureTimelineNodesByRoute = departureTimelineNodes.get(stop.stop_id).stream().collect(Collectors.groupingBy(t -> t.routeId));
                departureTimelineNodesByRoute.forEach((routeId, timelineNodesWithTripId) -> {
                    nodeAccess.setNode(i++, stop.stop_lat, stop.stop_lon);
                    int stopEnterNode = i - 1;
                    nodeAccess.setAdditionalNodeField(stopEnterNode, NodeType.STOP_ENTER_NODE.ordinal());
                    EdgeIteratorState entryEdge = graph.edge(streetNode, stopEnterNode, 0.0, false);
                    setEdgeType(entryEdge, GtfsStorage.EdgeType.ENTER_PT);
                    entryEdge.setName(stop.stop_name);
                    NavigableSet<Fun.Tuple2<Integer, Integer>> timeNodes = sorted(timelineNodesWithTripId);
                    wireUpAndAndConnectDepartureTimeline(stop, routeId, stopEnterNode, timeNodes);
                });
            }
        }
    }
    insertTransfers();
}
Also used : Transfer(com.conveyal.gtfs.model.Transfer) SortedSet(java.util.SortedSet) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) ListIterator(java.util.ListIterator) Writer.convertToGtfsTime(com.conveyal.gtfs.model.Entity.Writer.convertToGtfsTime) Stop(com.conveyal.gtfs.model.Stop) LoggerFactory(org.slf4j.LoggerFactory) DistanceCalc(com.graphhopper.util.DistanceCalc) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashMultimap(com.google.common.collect.HashMultimap) IntArrayList(com.carrotsearch.hppc.IntArrayList) Map(java.util.Map) Frequency(com.conveyal.gtfs.model.Frequency) Graph(com.graphhopper.storage.Graph) GtfsRealtime(com.google.transit.realtime.GtfsRealtime) Service(com.conveyal.gtfs.model.Service) Logger(org.slf4j.Logger) LocationIndex(com.graphhopper.storage.index.LocationIndex) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Helper(com.graphhopper.util.Helper) GTFSFeed(com.conveyal.gtfs.GTFSFeed) Collection(java.util.Collection) Set(java.util.Set) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) NavigableSet(java.util.NavigableSet) EdgeIterator(com.graphhopper.util.EdgeIterator) Collectors(java.util.stream.Collectors) SetMultimap(com.google.common.collect.SetMultimap) ZoneId(java.time.ZoneId) Fun(org.mapdb.Fun) DAYS(java.time.temporal.ChronoUnit.DAYS) List(java.util.List) NodeAccess(com.graphhopper.storage.NodeAccess) StopTime(com.conveyal.gtfs.model.StopTime) Trip(com.conveyal.gtfs.model.Trip) LocalDate(java.time.LocalDate) Optional(java.util.Optional) BitSet(java.util.BitSet) Comparator(java.util.Comparator) Route(com.conveyal.gtfs.model.Route) QueryResult(com.graphhopper.storage.index.QueryResult) Collections(java.util.Collections) Stop(com.conveyal.gtfs.model.Stop) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) ArrayList(java.util.ArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList) List(java.util.List)

Example 9 with EdgeIteratorState

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

the class GtfsReader method wireUpAndAndConnectArrivalTimeline.

private void wireUpAndAndConnectArrivalTimeline(Stop toStop, String routeId, int stopExitNode, NavigableSet<Fun.Tuple2<Integer, Integer>> timeNodes) {
    ZoneId zoneId = ZoneId.of(feed.agency.get(feed.routes.get(routeId).agency_id).agency_timezone);
    int time = 0;
    int prev = -1;
    for (Fun.Tuple2<Integer, Integer> e : timeNodes.descendingSet()) {
        EdgeIteratorState leaveTimeExpandedNetworkEdge = graph.edge(e.b, stopExitNode, 0.0, false);
        setEdgeType(leaveTimeExpandedNetworkEdge, GtfsStorage.EdgeType.LEAVE_TIME_EXPANDED_NETWORK);
        int arrivalTime = e.a;
        leaveTimeExpandedNetworkEdge.setFlags(encoder.setTime(leaveTimeExpandedNetworkEdge.getFlags(), arrivalTime));
        setFeedIdWithTimezone(leaveTimeExpandedNetworkEdge, new GtfsStorage.FeedIdWithTimezone(id, zoneId));
        if (prev != -1) {
            EdgeIteratorState edge = graph.edge(e.b, prev, 0.0, false);
            setEdgeType(edge, GtfsStorage.EdgeType.WAIT_ARRIVAL);
            edge.setName(toStop.stop_name);
            edge.setFlags(encoder.setTime(edge.getFlags(), time - e.a));
        }
        time = e.a;
        prev = e.b;
    }
}
Also used : ZoneId(java.time.ZoneId) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Fun(org.mapdb.Fun)

Example 10 with EdgeIteratorState

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

the class GtfsReader method insertOutboundTransfers.

private void insertOutboundTransfers(String toStopId, String toRouteId, int minimumTransferTime, SortedSet<Fun.Tuple2<Integer, Integer>> fromStopTimelineNodes) {
    int stationNode = gtfsStorage.getStationNodes().get(toStopId);
    EdgeIterator i = graph.getBaseGraph().createEdgeExplorer().setBaseNode(stationNode);
    while (i.next()) {
        GtfsStorage.EdgeType edgeType = encoder.getEdgeType(i.getFlags());
        if (edgeType == GtfsStorage.EdgeType.ENTER_PT) {
            String routeId = gtfsStorage.getRoutes().get(i.getEdge());
            if (toRouteId == null || toRouteId.equals(routeId)) {
                fromStopTimelineNodes.forEach(e -> {
                    EdgeIterator j = graph.getBaseGraph().createEdgeExplorer().setBaseNode(i.getAdjNode());
                    while (j.next()) {
                        GtfsStorage.EdgeType edgeType2 = encoder.getEdgeType(j.getFlags());
                        if (edgeType2 == GtfsStorage.EdgeType.ENTER_TIME_EXPANDED_NETWORK) {
                            int departureTime = (int) encoder.getTime(j.getFlags());
                            if (departureTime < e.a + minimumTransferTime) {
                                continue;
                            }
                            EdgeIteratorState edge = graph.edge(e.b, j.getAdjNode(), 0.0, false);
                            setEdgeType(edge, GtfsStorage.EdgeType.TRANSFER);
                            edge.setFlags(encoder.setTime(edge.getFlags(), departureTime - e.a));
                            break;
                        }
                    }
                });
            }
        }
    }
}
Also used : EdgeIterator(com.graphhopper.util.EdgeIterator) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

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