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));
}
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));
}
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();
}
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;
}
}
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;
}
}
});
}
}
}
}
Aggregations