forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoutingService.java
413 lines (344 loc) · 13.2 KB
/
RoutingService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
package org.opentripplanner.routing;
import gnu.trove.set.TIntSet;
import java.io.Serializable;
import java.time.Instant;
import java.util.BitSet;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.opentripplanner.common.geometry.HashGridSpatialIndex;
import org.opentripplanner.ext.flex.FlexIndex;
import org.opentripplanner.graph_builder.DataImportIssueStore;
import org.opentripplanner.graph_builder.linking.VertexLinker;
import org.opentripplanner.graph_builder.module.osm.WayPropertySetSource.DrivingDirection;
import org.opentripplanner.model.GraphBundle;
import org.opentripplanner.model.calendar.CalendarServiceData;
import org.opentripplanner.model.calendar.ServiceDate;
import org.opentripplanner.model.transfer.TransferService;
import org.opentripplanner.routing.algorithm.RoutingWorker;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.TransitLayer;
import org.opentripplanner.routing.api.request.RoutingRequest;
import org.opentripplanner.routing.api.response.RoutingResponse;
import org.opentripplanner.routing.core.intersection_model.IntersectionTraversalCostModel;
import org.opentripplanner.routing.edgetype.StreetEdge;
import org.opentripplanner.routing.graph.Edge;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.graph.GraphIndex;
import org.opentripplanner.routing.graph.Vertex;
import org.opentripplanner.routing.graphfinder.GraphFinder;
import org.opentripplanner.routing.graphfinder.NearbyStop;
import org.opentripplanner.routing.graphfinder.PlaceAtDistance;
import org.opentripplanner.routing.graphfinder.PlaceType;
import org.opentripplanner.routing.impl.StreetVertexIndex;
import org.opentripplanner.routing.services.RealtimeVehiclePositionService;
import org.opentripplanner.routing.services.TransitAlertService;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingService;
import org.opentripplanner.routing.vehicle_rental.VehicleRentalStationService;
import org.opentripplanner.routing.vertextype.TransitStopVertex;
import org.opentripplanner.standalone.server.Router;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.network.TransitMode;
import org.opentripplanner.transit.model.site.Stop;
import org.opentripplanner.transit.service.TransitService;
import org.opentripplanner.util.WorldEnvelope;
/**
* Entry point for requests towards the routing API.
*/
public class RoutingService {
private final Graph graph;
private final GraphIndex graphIndex;
private final GraphFinder graphFinder;
public RoutingService(Graph graph) {
this.graph = graph;
this.graphIndex = graph.index;
this.graphFinder = GraphFinder.getInstance(graph);
}
// TODO We should probably not have the Router as a parameter here
public RoutingResponse route(RoutingRequest request, Router router) {
var zoneId = graph.getTimeZone().toZoneId();
RoutingWorker worker = new RoutingWorker(router, request, zoneId);
return worker.route();
}
/** {@link Graph#addVertex(Vertex)} */
public void addVertex(Vertex v) {
this.graph.addVertex(v);
}
/** {@link Graph#removeEdge(Edge)} */
public void removeEdge(Edge e) {
this.graph.removeEdge(e);
}
/** {@link Graph#getVertex(String)} */
public Vertex getVertex(String label) {
return this.graph.getVertex(label);
}
/** {@link Graph#getVertices()} */
public Collection<Vertex> getVertices() {
return this.graph.getVertices();
}
/** {@link Graph#getVerticesOfType(Class)} */
public <T extends Vertex> List<T> getVerticesOfType(Class<T> cls) {
return this.graph.getVerticesOfType(cls);
}
/** {@link Graph#getEdges()} */
public Collection<Edge> getEdges() {
return this.graph.getEdges();
}
/** {@link Graph#getEdgesOfType(Class)} */
public <T extends Edge> List<T> getEdgesOfType(Class<T> cls) {
return this.graph.getEdgesOfType(cls);
}
/** {@link Graph#getStreetEdges()} */
public Collection<StreetEdge> getStreetEdges() {
return this.graph.getStreetEdges();
}
/** {@link Graph#getRealtimeTransitLayer()} */
public TransitLayer getRealtimeTransitLayer() {
return this.graph.getRealtimeTransitLayer();
}
/** {@link Graph#setRealtimeTransitLayer(TransitLayer)} */
public void setRealtimeTransitLayer(TransitLayer realtimeTransitLayer) {
this.graph.setRealtimeTransitLayer(realtimeTransitLayer);
}
/** {@link Graph#hasRealtimeTransitLayer()} */
public boolean hasRealtimeTransitLayer() {
return this.graph.hasRealtimeTransitLayer();
}
/** {@link Graph#containsVertex(Vertex)} */
public boolean containsVertex(Vertex v) {
return this.graph.containsVertex(v);
}
/** {@link Graph#putService(Class, Serializable)} */
public <T extends Serializable> T putService(Class<T> serviceType, T service) {
return this.graph.putService(serviceType, service);
}
/** {@link Graph#hasService(Class)} */
public boolean hasService(Class<? extends Serializable> serviceType) {
return this.graph.hasService(serviceType);
}
/** {@link Graph#getService(Class)} */
public <T extends Serializable> T getService(Class<T> serviceType) {
return this.graph.getService(serviceType);
}
/** {@link Graph#getService(Class, boolean)} */
public <T extends Serializable> T getService(Class<T> serviceType, boolean autoCreate) {
return this.graph.getService(serviceType, autoCreate);
}
/** {@link Graph#remove(Vertex)} */
public void remove(Vertex vertex) {
this.graph.remove(vertex);
}
/** {@link Graph#removeIfUnconnected(Vertex)} */
public void removeIfUnconnected(Vertex v) {
this.graph.removeIfUnconnected(v);
}
/** {@link Graph#getExtent()} */
public Envelope getExtent() {
return this.graph.getExtent();
}
/** {@link Graph#getTransferService()} */
public TransferService getTransferService() {
return this.graph.getTransferService();
}
/** {@link Graph#updateTransitFeedValidity(CalendarServiceData, DataImportIssueStore)} */
public void updateTransitFeedValidity(CalendarServiceData data, DataImportIssueStore issueStore) {
this.graph.updateTransitFeedValidity(data, issueStore);
}
/** {@link Graph#transitFeedCovers(Instant)} */
public boolean transitFeedCovers(Instant time) {
return this.graph.transitFeedCovers(time);
}
/** {@link Graph#getBundle()} */
public GraphBundle getBundle() {
return this.graph.getBundle();
}
/** {@link Graph#setBundle(GraphBundle)} */
public void setBundle(GraphBundle bundle) {
this.graph.setBundle(bundle);
}
/** {@link Graph#countVertices()} */
public int countVertices() {
return this.graph.countVertices();
}
/** {@link Graph#countEdges()} */
public int countEdges() {
return this.graph.countEdges();
}
// /** {@link Graph#index()} */
// public void index() {this.graph.index();}
/** {@link Graph#getCalendarDataService()} */
public CalendarServiceData getCalendarDataService() {
return this.graph.getCalendarDataService();
}
/** {@link Graph#clearCachedCalenderService()} */
public void clearCachedCalenderService() {
this.graph.clearCachedCalenderService();
}
/** {@link Graph#getStreetIndex()} */
public StreetVertexIndex getStreetIndex() {
return this.graph.getStreetIndex();
}
/** {@link Graph#getLinker()} */
public VertexLinker getLinker() {
return this.graph.getLinker();
}
/** {@link Graph#getOrCreateServiceIdForDate(ServiceDate)} */
public FeedScopedId getOrCreateServiceIdForDate(ServiceDate serviceDate) {
return this.graph.getOrCreateServiceIdForDate(serviceDate);
}
/** {@link Graph#removeEdgelessVertices()} */
public int removeEdgelessVertices() {
return this.graph.removeEdgelessVertices();
}
/** {@link Graph#getTimeZone()} */
public TimeZone getTimeZone() {
return this.graph.getTimeZone();
}
/** {@link Graph#clearTimeZone()} */
public void clearTimeZone() {
this.graph.clearTimeZone();
}
/** {@link Graph#calculateEnvelope()} */
public void calculateEnvelope() {
this.graph.calculateEnvelope();
}
/** {@link Graph#calculateConvexHull()} */
public void calculateConvexHull() {
this.graph.calculateConvexHull();
}
/** {@link Graph#getConvexHull()} */
public Geometry getConvexHull() {
return this.graph.getConvexHull();
}
/** {@link Graph#expandToInclude(double, double)} ()} */
public void expandToInclude(double x, double y) {
this.graph.expandToInclude(x, y);
}
/** {@link Graph#getEnvelope()} */
public WorldEnvelope getEnvelope() {
return this.graph.getEnvelope();
}
/** {@link Graph#calculateTransitCenter()} */
public void calculateTransitCenter() {
this.graph.calculateTransitCenter();
}
/** {@link Graph#getCenter()} */
public Optional<Coordinate> getCenter() {
return this.graph.getCenter();
}
/** {@link Graph#getTransitServiceStarts()} */
public long getTransitServiceStarts() {
return this.graph.getTransitServiceStarts();
}
/** {@link Graph#getTransitServiceEnds()} */
public long getTransitServiceEnds() {
return this.graph.getTransitServiceEnds();
}
/** {@link Graph#getDistanceBetweenElevationSamples()} */
public double getDistanceBetweenElevationSamples() {
return this.graph.getDistanceBetweenElevationSamples();
}
/** {@link Graph#setDistanceBetweenElevationSamples(double)} */
public void setDistanceBetweenElevationSamples(double distanceBetweenElevationSamples) {
this.graph.setDistanceBetweenElevationSamples(distanceBetweenElevationSamples);
}
/** {@link Graph#getTransitAlertService()} */
public TransitAlertService getTransitAlertService() {
return this.graph.getTransitAlertService();
}
public RealtimeVehiclePositionService getVehiclePositionService() {
return this.graph.getVehiclePositionService();
}
/** {@link Graph#getStopVerticesById(FeedScopedId)} */
public Set<Vertex> getStopVerticesById(FeedScopedId id) {
return this.graph.getStopVerticesById(id);
}
/** {@link Graph#getServicesRunningForDate(ServiceDate)} */
public BitSet getServicesRunningForDate(ServiceDate date) {
return this.graph.getServicesRunningForDate(date);
}
/** {@link Graph#getVehicleRentalStationService()} */
public VehicleRentalStationService getVehicleRentalStationService() {
return this.graph.getVehicleRentalStationService();
}
/** {@link Graph#getVehicleParkingService()} */
public VehicleParkingService getVehicleParkingService() {
return this.graph.getVehicleParkingService();
}
/** {@link Graph#getDrivingDirection()} */
public DrivingDirection getDrivingDirection() {
return this.graph.getDrivingDirection();
}
/** {@link Graph#setDrivingDirection(DrivingDirection)} */
public void setDrivingDirection(DrivingDirection drivingDirection) {
this.graph.setDrivingDirection(drivingDirection);
}
/** {@link Graph#getIntersectionTraversalModel()} */
public IntersectionTraversalCostModel getIntersectionTraversalModel() {
return this.graph.getIntersectionTraversalModel();
}
/** {@link Graph#setIntersectionTraversalCostModel(IntersectionTraversalCostModel)} */
public void setIntersectionTraversalCostModel(
IntersectionTraversalCostModel intersectionTraversalCostModel
) {
this.graph.setIntersectionTraversalCostModel(intersectionTraversalCostModel);
}
/** {@link GraphIndex#getStopVertexForStop()} */
public Map<Stop, TransitStopVertex> getStopVertexForStop() {
return this.graphIndex.getStopVertexForStop();
}
/** {@link GraphIndex#getStopSpatialIndex()} */
public HashGridSpatialIndex<TransitStopVertex> getStopSpatialIndex() {
return this.graphIndex.getStopSpatialIndex();
}
/** {@link GraphIndex#getServiceCodesRunningForDate()} */
public Map<ServiceDate, TIntSet> getServiceCodesRunningForDate() {
return this.graphIndex.getServiceCodesRunningForDate();
}
/** {@link GraphIndex#getFlexIndex()} */
public FlexIndex getFlexIndex() {
return this.graphIndex.getFlexIndex();
}
/** {@link GraphFinder#findClosestStops(double, double, double)} */
public List<NearbyStop> findClosestStops(double lat, double lon, double radiusMeters) {
return this.graphFinder.findClosestStops(lat, lon, radiusMeters);
}
/**
* {@link GraphFinder#findClosestPlaces(double, double, double, int, List, List, List, List, List,
* RoutingService, TransitService)}
*/
public List<PlaceAtDistance> findClosestPlaces(
double lat,
double lon,
double radiusMeters,
int maxResults,
List<TransitMode> filterByModes,
List<PlaceType> filterByPlaceTypes,
List<FeedScopedId> filterByStops,
List<FeedScopedId> filterByRoutes,
List<String> filterByBikeRentalStations,
List<String> filterByBikeParks,
List<String> filterByCarParks,
RoutingService routingService,
TransitService transitService
) {
return this.graphFinder.findClosestPlaces(
lat,
lon,
radiusMeters,
maxResults,
filterByModes,
filterByPlaceTypes,
filterByStops,
filterByRoutes,
filterByBikeRentalStations,
routingService,
transitService
);
}
}