Raptor Functions¶
Module contains function related to RAPTOR, rRAPTOR, One-To-Many rRAPTOR, HypRAPTOR
-
Algorithms.RAPTOR.raptor_functions.
check_stop_validity
(stops, SOURCE: int, DESTINATION: int) → None[source]¶ Check if the entered SOURCE and DESTINATION stop id are present in stop list or not.
- Parameters
stops – GTFS stops.txt
SOURCE (int) – stop id of source stop.
DESTINATION (int) – stop id of destination stop.
- Returns
None
Examples
>>> output = check_stop_validity(stops, 20775, 1482)
-
Algorithms.RAPTOR.raptor_functions.
get_latest_trip_new
(stoptimes_dict: dict, route: int, arrival_time_at_pi, pi_index: int, change_time) → tuple[source]¶ Get latest trip after a certain timestamp from the given stop of a route.
- Parameters
stoptimes_dict (dict) – preprocessed dict. Format {route_id: [[trip_1], [trip_2]]}.
route (int) – id of route.
arrival_time_at_pi (pandas.datetime) – arrival time at stop pi.
pi_index (int) – index of the stop from which route was boarded.
change_time (pandas.datetime) – change time at stop (set to 0).
- Returns
trip index, trip else:
-1,-1 (e.g. when there is no trip after the given timestamp)
- Return type
If a trip exists
Examples
>>> output = get_latest_trip_new(stoptimes_dict, 1000, pd.to_datetime('2019-06-10 17:40:00'), 0, pd.to_timedelta(0, unit='seconds'))
-
Algorithms.RAPTOR.raptor_functions.
initialize_raptor
(routes_by_stop_dict: dict, SOURCE: int, MAX_TRANSFER: int) → tuple[source]¶ Initialize values for RAPTOR.
- Parameters
routes_by_stop_dict (dict) – preprocessed dict. Format {stop_id: [id of routes passing through stop]}.
SOURCE (int) – stop id of source stop.
MAX_TRANSFER (int) – maximum transfer limit.
- Returns
deque to store marked stop. marked_stop_dict (dict): Binary variable indicating if a stop is marked. Keys: stop Id, value: 0 or 1. label (dict): nested dict to maintain label. Format {round : {stop_id: pandas.datetime}}. pi_label (dict): Nested dict used for backtracking labels. Format {round : {stop_id: pointer_label}} if stop is reached by walking, pointer_label= (‘walking’, from stop id, to stop id, time, arrival time)}} else pointer_label= (trip boarding time, boarding_point, stop id, arr_by_trip, trip id) star_label (dict): dict to maintain best arrival label {stop id: pandas.datetime}. inf_time (pandas.datetime): Variable indicating infinite time (pandas.datetime).
- Return type
marked_stop (deque)
Examples
>>> output = initialize_raptor(routes_by_stop_dict, 20775, 4)
-
Algorithms.RAPTOR.raptor_functions.
post_processing
(DESTINATION: int, pi_label: dict, PRINT_ITINERARY: int, label: dict) → tuple[source]¶ - Post processing for std_RAPTOR. Currently supported functionality:
Rounds in which DESTINATION is reached
Trips for covering pareto optimal set
Pareto optimal timestamps.
- Parameters
DESTINATION (int) – stop id of destination stop.
pi_label (dict) – Nested dict used for backtracking. Primary keys: Round, Secondary keys: stop id. Format- {round : {stop_id: pointer_label}}
PRINT_ITINERARY (int) – 1 or 0. 1 means print complete path.
label (dict) – nested dict to maintain label. Format {round : {stop_id: pandas.datetime}}.
- Returns
list of rounds in which DESTINATION is reached. Format - [int] trip_set (list): list of trips ids required to cover optimal journeys. Format - [char] rap_out (list): list of pareto-optimal arrival timestamps. Format = [(pandas.datetime)]
- Return type
rounds_inwhich_desti_reached (list)
Examples
>>> output = post_processing(1482, pi_label, 1, label)
-
Algorithms.RAPTOR.raptor_functions.
post_processing_onetomany_rraptor
(DESTINATION_LIST: list, pi_label: dict, PRINT_ITINERARY: int, label: dict, OPTIMIZED: int) → list[source]¶ - post processing for Ont-To-Many rRAPTOR. Currently supported functionality:
Print the output
Routes required for covering pareto-optimal set.
Trips required for covering pareto-optimal set.
- Parameters
DESTINATION_LIST (list) – list of stop ids of destination stop.
pi_label (dict) – Nested dict used for backtracking. Primary keys: Round, Secondary keys: stop id. Format- {round : {stop_id: pointer_label}}
PRINT_ITINERARY (int) – 1 or 0. 1 means print complete path.
label (dict) – nested dict to maintain label. Format {round : {stop_id: pandas.datetime}}.
OPTIMIZED (int) – 1 or 0. 1 means collect trips and 0 means collect routes.
- Returns
final_trips (list): list of trips required to cover all pareto-optimal journeys. format - [trip_id] elif OPTIMIZED==0:
final_routes (list): list of routes required to cover all pareto-optimal journeys. format - [route_id]
- Return type
if OPTIMIZED==1
Examples
>>> output = post_processing_onetomany_rraptor([1482], pi_label, 1, label, 0)
-
Algorithms.RAPTOR.raptor_functions.
post_processing_rraptor
(DESTINATION: int, pi_label: dict, PRINT_ITINERARY: int, label: dict, OPTIMIZED: int) → list[source]¶ - Full post processing for rRAPTOR. Currently supported functionality:
Print the output
Routes required for covering pareto-optimal journeys.
Trips required for covering pareto-optimal journeys.
- Parameters
DESTINATION (int) – stop id of destination stop.
pi_label (dict) – Nested dict used for backtracking. Primary keys: Round, Secondary keys: stop id. Format- {round : {stop_id: pointer_label}}
PRINT_ITINERARY (int) – 1 or 0. 1 means print complete path.
label (dict) – nested dict to maintain label. Format {round : {stop_id: pandas.datetime}}.
OPTIMIZED (int) – 1 or 0. 1 means collect trips and 0 means collect routes.
- Returns
final_trips (list): List of trips required to cover all pareto-optimal journeys. Format - [trip_id] elif OPTIMIZED==0:
final_routes (list): List of routes required to cover all pareto-optimal journeys. Format - [route_id]
- Return type
if OPTIMIZED==1
Examples
>>> output = post_processing_onetomany_rraptor([1482], pi_label, 1, label, 0)