Optimization Module

Functions to optimize the distributions of participants into groups.

optimize_rideshares.get_time_of_year(time)

Calculates the time as a float in hours, given a datetime object.

Parameters:

time (datetime) – The datetime object to be converted.

Returns:

The time in hours, represented as a float.

Return type:

float

Note

This function assumes that the input datetime object has attributes for day, hour, minute, and second. The output is not an exact month representation, it’s a representation of time in hours converted to an approximate month scale.

Raises:
  • AttributeError – If the input datetime object doesn’t have day, hour, minute,

  • and second attributes.

optimize_rideshares.optimize(df, kind='arrival', max_time_difference=0.5, max_people_per_car=3)

Optimizes shared rides for participants based on airport arrival or departures times using a hierarchical clustering algorithm.

Parameters:
  • df (pandas.DataFrame) – Input DataFrame which needs to be processed.

  • kind (str, optional) – Specifies the column to consider for optimization. Must be either ‘arrival’ or ‘departure’. Defaults to ‘arrival’.

  • max_time_difference (float, optional) – The maximum difference in departure time between participants for grouping in the hierarchical clustering. Defaults to 0.5.

  • max_people_per_car (int, optional) – The maximum number of people that can be grouped in a car. Defaults to 3.

Returns:

DataFrame with a new column indicating the ride groups.

Return type:

pandas.DataFrame

Raises:

AssertionError – If the kind parameter is not ‘arrival’ or ‘departure’.

Note

‘arrival’ and ‘departure’ refers to the “date_time_of_airport_arrival” and “date_time_of_hotel_departure” columns of the DataFrame respectively.