prevent edges with null travel-time
This commit is contained in:
parent
45ee290085
commit
93736fdf17
|
|
@ -13,6 +13,8 @@ from collections import defaultdict
|
|||
|
||||
import networkx as nx
|
||||
|
||||
from metrosim.exceptions import MetroInputError
|
||||
|
||||
|
||||
class PTNetwork(nx.MultiDiGraph):
|
||||
"""Class representing a public-transit network.
|
||||
|
|
@ -113,10 +115,10 @@ class PTNetwork(nx.MultiDiGraph):
|
|||
print('Warning: Discarded {} stop-times with invalid pickup or '
|
||||
'dropoff'.format(invalid_stop_types))
|
||||
|
||||
null_travel_times = 0
|
||||
for trip_id, stop_times in legs_dict.items():
|
||||
# Sort stop_times by increasing stop_sequence.
|
||||
stop_times = sorted(
|
||||
stop_times, key=lambda x: int(x['stop_sequence']))
|
||||
stop_times = sorted(stop_times, key=lambda x: x['departure_time'])
|
||||
first_departure = _parse_time(stop_times[0]['departure_time'])
|
||||
last_arrival = _parse_time(stop_times[-1]['arrival_time'])
|
||||
if first_departure > to_time or last_arrival < from_time:
|
||||
|
|
@ -125,6 +127,13 @@ class PTNetwork(nx.MultiDiGraph):
|
|||
for prev_stop, next_stop in zip(stop_times[:-1], stop_times[1:]):
|
||||
dep_time = _parse_time(prev_stop['departure_time'])
|
||||
arr_time = _parse_time(next_stop['arrival_time'])
|
||||
if dep_time == arr_time:
|
||||
null_travel_times += 1
|
||||
arr_time += timedelta(seconds=1)
|
||||
if dep_time > arr_time:
|
||||
msg = (
|
||||
'Invalid trip (non-positive travel-time): {}')
|
||||
raise MetroInputError(msg.format(trip_id))
|
||||
route_id = self.trips[trip_id]['route_id']
|
||||
self.add_edge(
|
||||
prev_stop['stop_id'],
|
||||
|
|
@ -137,6 +146,10 @@ class PTNetwork(nx.MultiDiGraph):
|
|||
type=self.routes[route_id]['type'],
|
||||
)
|
||||
|
||||
if null_travel_times:
|
||||
print('Warning: Increased the travel-time of {} stop-times with '
|
||||
'null travel-time'.format(null_travel_times))
|
||||
|
||||
def _add_valid_routes(self, reader, routes):
|
||||
"""Add route data to the PT network.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue