TBTR Functions¶
Module contains function related to TBTR, rTBTR, One-To-Many rTBTR, HypTBTR
-
Algorithms.TBTR.TBTR_functions.
enqueue
(connection_list: list, nextround: int, predecessor_label: tuple, R_t: dict, Q: list, stoptimes_dict: dict) → None[source]¶ Main enqueue function used in TBTR to add trips segments to next round and update first reached stop of each trip.
- Parameters
connection_list (list) – list of connections to be added. Format: [(to_trip_id, to_trip_id_stop_index)].
nextround (int) – next round/transfer number to which trip-segments are added.
predecessor_label (tuple) – used for backtracking journey ( To be developed ).
R_t (dict) – dict with keys as trip id. Format {trip_id : first reached stop}.
Q (list) – list of trips segments.
stoptimes_dict (dict) – preprocessed dict. Format {route_id: [[trip_1], [trip_2]]}.
- Returns
None
-
Algorithms.TBTR.TBTR_functions.
enqueue_range
(connection_list: list, nextround: int, predecessor_label: tuple, R_t: dict, Q: list, stoptimes_dict: dict, MAX_TRANSFER: int) → None[source]¶ Adds trips-segments to next round and update R_t. Used in range queries
- Parameters
connection_list (list) – list of connections to be added. Format: [(to_trip_id, to_trip_id_stop_index)].
nextround (int) – next round/transfer number to which trip-segments are added
predecessor_label (tuple) – predecessor_label for backtracking journey ( To be developed ).
R_t (nested dict) – Nested_Dict with primary keys as trip id and secondary keys as number of transfers. Format {trip_id: {[round]: first reached stop}}
Q (list) – list of trips segments
stoptimes_dict (dict) – preprocessed dict. Format {route_id: [[trip_1], [trip_2]]}.
MAX_TRANSFER (int) – maximum transfer limit.
Returns: None
-
Algorithms.TBTR.TBTR_functions.
initialize_from_desti
(routes_by_stop_dict: dict, stops_dict: dict, DESTINATION: int, footpath_dict: dict, idx_by_route_stop_dict: dict) → dict[source]¶ Initialize routes/footpath to leading to destination stop.
- Parameters
routes_by_stop_dict (dict) – preprocessed dict. Format {stop_id: [id of routes passing through stop]}.
stops_dict (dict) – preprocessed dict. Format {route_id: [ids of stops in the route]}.
DESTINATION (int) – stop id of destination stop.
footpath_dict (dict) – preprocessed dict. Format {from_stop_id: [(to_stop_id, footpath_time)]}.
idx_by_route_stop_dict (dict) – preprocessed dict. Format {(route id, stop id): stop index in route}.
- Returns
A dict to track routes/leading to destination stop. Format {route_id: (from_stop_idx, travel time, stop id)}
- Return type
L (dict)
Examples
>>> output = initialize_from_desti(routes_by_stop_dict, stops_dict, 1482, footpath_dict, idx_by_route_stop_dict) >>> print(output)
-
Algorithms.TBTR.TBTR_functions.
initialize_from_desti_onemany
(routes_by_stop_dict: dict, stops_dict: dict, DESTINATION_LIST: list, footpath_dict: dict, idx_by_route_stop_dict: dict) → dict[source]¶ Initialize routes/footpath to leading to destination stop in case of one-to-many rTBTR
- Parameters
routes_by_stop_dict (dict) – preprocessed dict. Format {stop_id: [id of routes passing through stop]}.
stops_dict (dict) – preprocessed dict. Format {route_id: [ids of stops in the route]}.
DESTINATION_LIST (list) – list of stop ids of destination stop.
footpath_dict (dict) – preprocessed dict. Format {from_stop_id: [(to_stop_id, footpath_time)]}.
idx_by_route_stop_dict (dict) – preprocessed dict. Format {(route id, stop id): stop index in route}.
- Returns
A dict to track routes/leading to destination stops. Key: route_id, value: {destination_stop_id: [(from_stop_idx, travel time, stop id)]}
- Return type
L (nested dict)
Examples
>>> output = initialize_from_desti_onemany(routes_by_stop_dict, stops_dict, [1482], footpath_dict, idx_by_route_stop_dict) >>> print(output)
-
Algorithms.TBTR.TBTR_functions.
initialize_from_source
(footpath_dict: dict, SOURCE: int, routes_by_stop_dict: dict, stops_dict: dict, stoptimes_dict: dict, D_TIME, MAX_TRANSFER: int, WALKING_FROM_SOURCE: int, idx_by_route_stop_dict: dict) → tuple[source]¶ Initialize trips segments from source stop.
- Parameters
footpath_dict (dict) – preprocessed dict. Format {from_stop_id: [(to_stop_id, footpath_time)]}.
SOURCE (int) – stop id of source stop.
routes_by_stop_dict (dict) – preprocessed dict. Format {stop_id: [id of routes passing through stop]}.
stops_dict (dict) – preprocessed dict. Format {route_id: [ids of stops in the route]}.
stoptimes_dict (dict) – preprocessed dict. Format {route_id: [[trip_1], [trip_2]]}.
D_TIME (pandas.datetime) – departure time.
MAX_TRANSFER (int) – maximum transfer limit.
WALKING_FROM_SOURCE (int) – 1 or 0. 1 means walking from SOURCE is allowed.
idx_by_route_stop_dict (dict) – preprocessed dict. Format {(route id, stop id): stop index in route}.
- Returns
dict to store first reached stop of every trip. Format {trip_id: first reached stop} Q (list): list of trips segments
- Return type
R_t (dict)
Examples
>>> output = initialize_from_source(footpath_dict, 20775, routes_by_stop_dict, stops_dict, stoptimes_dict, pd.to_datetime('2019-06-10 00:00:00'), 4, 1, idx_by_route_stop_dict) >>> print(output)
-
Algorithms.TBTR.TBTR_functions.
initialize_from_source_range
(dep_details: list, MAX_TRANSFER: int, stoptimes_dict: dict, R_t: dict) → list[source]¶ Initialize trips segments from source in rTBTR
- Parameters
dep_details (list) – list of format [trip id, departure time, source index]
MAX_TRANSFER (int) – maximum transfer limit.
stoptimes_dict (dict) – preprocessed dict. Format {route_id: [[trip_1], [trip_2]]}.
R_t (nested dict) – Nested_Dict with primary keys as trip id and secondary keys as number of transfers. Format {trip_id: {[round]: first reached stop}}
- Returns
list of trips segments
- Return type
Q (list)
-
Algorithms.TBTR.TBTR_functions.
initialize_onemany
(MAX_TRANSFER: int, DESTINATION_LIST: list) → tuple[source]¶ Initialize values for one-to-many TBTR.
- Parameters
MAX_TRANSFER (int) – maximum transfer limit.
DESTINATION_LIST (list) – list of stop ids of destination stop.
- Returns
dict to store arrival timestamps. Keys: number of transfer, Values: arrival time. inf_time (pandas.datetime): Variable indicating infinite time.
- Return type
J (dict)
Examples
>>> output = initialize_onemany(4, [1482]) >>> print(output)
-
Algorithms.TBTR.TBTR_functions.
initialize_tbtr
(MAX_TRANSFER: int) → dict[source]¶ Initialize values for TBTR.
- Returns
dict to store arrival timestamps. Keys: number of transfer, Values: arrival time. inf_time (pandas.datetime): Variable indicating infinite time.
- Return type
J (dict)
Examples
>>> output = initialize_tbtr(4) >>> print(output)
-
Algorithms.TBTR.TBTR_functions.
post_process
(J: dict, Q: list, DESTINATION: int, SOURCE: int, footpath_dict: dict, stops_dict: dict, stoptimes_dict: dict, PRINT_ITINERARY: int, D_TIME, MAX_TRANSFER: int, trip_transfer_dict: dict) → list[source]¶ Contains post-processing features for TBTR. Currently supported functionality:
Collect pareto-optimal arrival timestamps.
- Parameters
J (dict) – dict to store arrival timestamps. Keys: number of transfer, Values: arrival time
Q (list) – list of trips segments.
DESTINATION (int) – stop id of destination stop.
SOURCE (int) – stop id of source stop.
footpath_dict (dict) – preprocessed dict. Format {from_stop_id: [(to_stop_id, footpath_time)]}.
stops_dict (dict) – preprocessed dict. Format {route_id: [ids of stops in the route]}.
stoptimes_dict (dict) – preprocessed dict. Format {route_id: [[trip_1], [trip_2]]}.
PRINT_ITINERARY (int) – 1 or 0. 1 means print complete path.
D_TIME (pandas.datetime) – departure time.
MAX_TRANSFER (int) – maximum transfer limit.
trip_transfer_dict (nested dict) – keys: id of trip we are transferring from, value: {stop number: list of tuples
- Returns
pareto-optimal arrival timestamps.
- Return type
TBTR_out (list)
-
Algorithms.TBTR.TBTR_functions.
post_process_range
(J: dict, Q: list, rounds_desti_reached: list, PRINT_ITINERARY: int, DESTINATION: int, SOURCE: int, footpath_dict: dict, stops_dict: dict, stoptimes_dict: dict, d_time, MAX_TRANSFER: int, trip_transfer_dict: dict) → set[source]¶ Contains all the post-processing features for rTBTR. Currently supported functionality:
Collect list of trips needed to cover pareto-optimal journeys.
- Parameters
J (dict) – dict to store arrival timestamps. Keys: number of transfer, Values: arrival time
Q (list) – list of trips segments.
rounds_desti_reached (list) – Rounds in which DESTINATION is reached.
PRINT_ITINERARY (int) – 1 or 0. 1 means print complete path.
DESTINATION (int) – stop id of destination stop.
SOURCE (int) – stop id of source stop.
footpath_dict (dict) – preprocessed dict. Format {from_stop_id: [(to_stop_id, footpath_time)]}.
stops_dict (dict) – preprocessed dict. Format {route_id: [ids of stops in the route]}.
stoptimes_dict (dict) – preprocessed dict. Format {route_id: [[trip_1], [trip_2]]}.
D_TIME (pandas.datetime) – departure time.
MAX_TRANSFER (int) – maximum transfer limit.
trip_transfer_dict (nested dict) – keys: id of trip we are transferring from, value: {stop number: list of tuples
- Returns
trips needed to cover pareto-optimal journeys.
- Return type
necessory_trips (set)
-
Algorithms.TBTR.TBTR_functions.
post_process_range_onemany
(J: dict, Q: list, rounds_desti_reached: list, PRINT_ITINERARY: int, desti: int, SOURCE: int, footpath_dict: dict, stops_dict: dict, stoptimes_dict: dict, d_time, MAX_TRANSFER: int, trip_transfer_dict: dict) → set[source]¶ Contains all the post-processing features for One-To-Many rTBTR. Currently supported functionality:
Collect list of trips needed to cover pareto-optimal journeys.
- Parameters
J (dict) – dict to store arrival timestamps. Keys: number of transfer, Values: arrival time
Q (list) – list of trips segments.
rounds_desti_reached (list) – Rounds in which DESTINATION is reached.
PRINT_ITINERARY (int) – 1 or 0. 1 means print complete path.
desti (int) – stop id of destination stop.
SOURCE (int) – stop id of source stop.
footpath_dict (dict) – preprocessed dict. Format {from_stop_id: [(to_stop_id, footpath_time)]}.
stops_dict (dict) – preprocessed dict. Format {route_id: [ids of stops in the route]}.
stoptimes_dict (dict) – preprocessed dict. Format {route_id: [[trip_1], [trip_2]]}.
d_time (pandas.datetime) – departure time.
MAX_TRANSFER (int) – maximum transfer limit.
trip_transfer_dict (nested dict) – keys: id of trip we are transferring from, value: {stop number: list of tuples
- Returns
Trips needed to cover pareto-optimal journeys.
- Return type
TBTR_out (set)
-
Algorithms.TBTR.TBTR_functions.
update_label
(label, no_of_transfer: int, predecessor_label: tuple, J: dict, MAX_TRANSFER: int) → dict[source]¶ Updates and returns destination pareto set.
- Parameters
label (pandas.datetime) – optimal arrival time .
no_of_transfer (int) – number of transfer.
predecessor_label (tuple) – predecessor_label for backtracking (To be developed)
J (dict) – dict to store arrival timestamps. Keys: number of transfer, Values: arrival time
MAX_TRANSFER (int) – maximum transfer limit.
- Returns
dict to store arrival timestamps. Keys: number of transfer, Values: arrival time
- Return type
J (dict)