Miscellaneous Functions

Module contains miscellaneous functions used for reading data, printing logo etc.

miscellaneous_func.check_footpath(footpath_dict: dict)None[source]

Check if the footpaths are transitively close. Prints error if not.

Parameters

footpath_dict – Pre-processed dict- format {from_stop_id: [(to_stop_id, footpath_time)]}

Returns

None

Examples

>>> check_footpath(footpath_dict)
miscellaneous_func.check_nonoverlap(stoptimes_dict: dict, stops_dict: dict)set[source]

Check for non overlapping trips in stoptimes_dict. If found, it reduces the timestamp of the earlier trip by 1 second. This process is repeated until overlapping trips=null. Note 1 second is taken to avoid creation of new overlapping trips due to timestamp correction.

Parameters
  • stoptimes_dict (dict) – preprocessed dict. Format {route_id: [[trip_1], [trip_2]]}.

  • stops_dict (dict) – preprocessed dict. Format {route_id: [ids of stops in the route]}.

Returns

set of routes with overlapping trips.

Return type

overlap (set)

Examples

>>> overlap = check_nonoverlap(stoptimes_dict, stops_dict)
miscellaneous_func.get_full_trans(NETWORK_NAME: str, time_limit)None[source]

Make the footpath graph transitively close and saves it in the form of transfer_dict Note: time_limit=”full” means consider all footpaths

Parameters
  • NETWORK_NAME (str) – Network NETWORK_NAME

  • time_limit (str/int) – maximum footpath duration to be considered (before footpath graph is made transitively closed)

Returns

None

Examples

>>> get_full_trans('anaheim', 180)
miscellaneous_func.get_random_od(routes_by_stop_dict: dict, NETWORK_NAME: str)None[source]

Generate Random OD pairs.

Parameters
  • routes_by_stop_dict (dict) – preprocessed dict. Format {stop_id: [id of routes passing through stop]}.

  • NETWORK_NAME (str) – Network NETWORK_NAME

Returns

None

Examples

>>> get_random_od(routes_by_stop_dict, 'anaheim')
miscellaneous_func.load_CSA(NETWORK_NAME: str)[source]

Loads the connection list for CSA

Parameters

NETWORK_NAME (str) – name of the network

Returns

list of tuples. format: [(from stop, to stop, from time, to time, trip id)].

Return type

connections_list (list)

Examples

>>> connections_list = load_CSA('anaheim')
miscellaneous_func.load_TBTR(NETWORK_NAME: str)tuple[source]

Loads the trip-transfer dict for TBTR

Parameters

NETWORK_NAME (str) – name of the network

Returns

keys: id of trip we are transferring from, value: {stop number: list of tuples trip_set (set): set of trip ids from which trip-transfers are available.

Return type

trip_transfer_dict (nested dict)

Examples

>>> trip_transfer_dict, trip_set = load_TBTR('anaheim')
miscellaneous_func.load_TE_graph(NETWORK_NAME: str, stop_times_file)tuple[source]

Loads the Time expanded Graph

Parameters
  • NETWORK_NAME (str) – name of the network

  • stop_times_file (pandas.dataframe) – stop_times.txt file in GTFS.

Returns

NetworkX graph object. Time exapnded graph stops_group: pandas.groupby object. stopevent_mapping (dict): mapping dictionary. Format: {(stop id, arrival time): new node id}

Return type

G

Examples

>>> G, stops_group, stopevent_mapping = load_TE_graph('anaheim', stop_times_file)

Prints the logo

Parameters

None

Returns

None

miscellaneous_func.print_network_details(transfers_file, trips_file, stops_file)None[source]

Prints the network details like number of routes, trips, stops, footpath

Parameters
  • transfers_file (pandas.dataframe) – dataframe with transfers (footpath) details.

  • trips_file (pandas.dataframe) – dataframe with trip details.

  • stops_file (pandas.dataframe) – dataframe with stop details.

Returns

None

miscellaneous_func.print_query_parameters(NETWORK_NAME: str, SOURCE: int, DESTINATION, D_TIME, MAX_TRANSFER: int, WALKING_FROM_SOURCE: int, variant: int, no_of_partitions=None, weighting_scheme=None, partitioning_algorithm=None)None[source]

Prints the input parameters related to the shortest path query

Parameters
  • SOURCE (int) – stop-id DESTINATION stop

  • DESTINATION (int/list) – stop-id SOURCE stop. For Onetomany algorithms, this is a list.

  • D_TIME (pandas.datetime) – Departure time

  • MAX_TRANSFER (int) – Max transfer limit

  • WALKING_FROM_SOURCE (int) – 1 or 0. 1 means walking from SOURCE is allowed.

  • variant (int) – variant of the algorithm. 0 for normal version, 1 for range version, 2 for One-To-Many version, 3 for Hyper version

  • no_of_partitions (int) – number of partitions network has been divided into

  • weighting_scheme (str) – which weighing scheme has been used to generate partitions.

  • partitioning_algorithm (str) – which algorithm has been used to generate partitions.

Returns

None

Examples

>>> overlap = print_query_parameters('anaheim', 36, 52, pd.to_datetime('2022-06-30 06:30:00'), 4, 1, 0, None, None, None)
miscellaneous_func.read_nested_partitions(stop_times_file, NETWORK_NAME: str, no_of_partitions: int, weighting_scheme: str)tuple[source]

Read fill-ins in case of nested partitioning.

Parameters
  • stop_times_file (pandas.dataframe) – dataframe with stoptimes details

  • NETWORK_NAME (str) – name of the network no_of_partitions (int): number of partitions network has been divided into.

  • weighting_scheme (str) – which weighing scheme has been used to generate partitions.

Returns

key: stop-id (int), value: stop-cell id (int). Note: if stop-cell id of -1 denotes cut stop. route_groups (dict): key: tuple of all possible combinations of stop cell id, value: set of route ids belonging to the stop cell combination cut_trips (set): set of trip ids that are part of fill-in. trip_groups (dict): key: tuple of all possible combinations of stop cell id, value: set of trip ids belonging to the stop cell combination

Return type

stop_out (dict)

miscellaneous_func.read_partitions(stop_times_file, NETWORK_NAME: str, no_of_partitions: int, weighting_scheme: str, partitioning_algorithm: str)tuple[source]

Reads the fill-in information.

Parameters
  • stop_times_file (pandas.dataframe) – dataframe with stoptimes details

  • NETWORK_NAME (str) – name of the network no_of_partitions (int): number of partitions network has been divided into.

  • weighting_scheme (str) – which weighing scheme has been used to generate partitions.

  • partitioning_algorithm (str) – which algorithm has been used to generate partitions. Currently supported arguments are hmetis or kahypar.

Returns

key: stop-id (int), value: stop-cell id (int). Note: if stop-cell id of -1 denotes cut stop. route_groups (dict): key: tuple of all possible combinations of stop cell id, value: set of route ids belonging to the stop cell combination cut_trips (set): set of trip ids that are part of fill-in. trip_groups (dict): key: tuple of all possible combinations of stop cell id, value: set of trip ids belonging to the stop cell combination

Return type

stop_out (dict)

miscellaneous_func.read_testcase(NETWORK_NAME: str)tuple[source]

Reads the GTFS network and preprocessed dict. If the dicts are not present, dict_builder_functions are called to construct them.

Parameters

NETWORK_NAME (str) – name of the network

Returns

stops.txt file in GTFS. trips_file (pandas.dataframe): trips.txt file in GTFS. stop_times_file (pandas.dataframe): stop_times.txt file in GTFS. transfers_file (pandas.dataframe): dataframe with transfers (footpath) details. stops_dict (dict): keys: route_id, values: list of stop id in the route_id. Format-> dict[route_id] = [stop_id] stoptimes_dict (dict): keys: route ID, values: list of trips in the increasing order of start time. Format-> dict[route_ID] = [trip_1, trip_2] where trip_1 = [(stop id, arrival time), (stop id, arrival time)] footpath_dict (dict): keys: from stop_id, values: list of tuples of form (to stop id, footpath duration). Format-> dict[stop_id]=[(stop_id, footpath_duration)] route_by_stop_dict_new (dict): keys: stop_id, values: list of routes passing through the stop_id. Format-> dict[stop_id] = [route_id] idx_by_route_stop_dict (dict): preprocessed dict. Format {(route id, stop id): stop index in route}.

Return type

stops_file (pandas.dataframe)

Examples

>>> NETWORK_NAME = './anaheim'
>>> read_testcase('NETWORK_NAME')