Trip Scheduling Choice#

This model uses a logit-based formulation to determine potential trip windows for the three main components of a tour.

  • Outbound Leg: The time from leaving the origin location to the time second to last outbound stop.

  • Main Leg: The time window from the last outbound stop through the main tour destination to the first inbound stop.

  • Inbound Leg: The time window from the first inbound stop to the tour origin location.

Structure#

  • Configuration File: trip_scheduling_choice.yaml

  • Core Table: tours

  • Result Field: outbound_duration, main_leg_duration, inbound_duration

Configuration#

settings activitysim.abm.models.trip_scheduling_choice.TripSchedulingChoiceSettings#

Bases: PydanticReadable

Settings for the trip_scheduling_choice component.

Fields:
field PREPROCESSOR: PreprocessorSettings | None = None#

Setting for the preprocessor.

field SPECIFICATION: str [Required]#

file name of specification file

Examples#

Implementation#

activitysim.abm.models.trip_scheduling_choice.trip_scheduling_choice(state: State, trips: DataFrame, tours: DataFrame, skim_dict: SkimDict | SkimDataset, model_settings: Optional[TripSchedulingChoiceSettings] = None, model_settings_file_name: str = 'trip_scheduling_choice.yaml', trace_label: str = 'trip_scheduling_choice') None#
activitysim.abm.models.trip_scheduling_choice.generate_schedule_alternatives(tours)#

For a set of tours, build out the potential schedule alternatives for the main leg, outbound leg, and inbound leg. This process handles the change in three steps.

Definitions:
  • Main Leg: The time from last outbound stop to the first inbound stop.

    If the tour does not include any intermediate stops this will represent the full tour duration.

  • Outbound Leg: The time from the tour origin to the last outbound stop

  • Inbound Leg: The time from the first inbound stop to the tour origin

  1. For tours with no intermediate stops, it simple asserts a main leg duration equal to the tour duration.

  2. For tours with an intermediate stop on one of the legs, calculate all possible time combinations that are allowed in the duration

  3. For tours with an intermediate stop on both legs, calculate all possible time combinations that are allowed in the tour duration

Parameters:

tours – pd.Dataframe: Must include a field for tour duration and boolean fields indicating intermediate inbound or outbound stops.

Returns:

pd.Dataframe: Potential time duration windows.

activitysim.abm.models.trip_scheduling_choice.no_stops_patterns(tours)#

Asserts the tours with no intermediate stops have a main leg duration equal to the tour duration and set inbound and outbound windows equal to zero. :param tours: pd.Dataframe: Tours with no intermediate stops. :return: pd.Dataframe: Main leg duration, outbound leg duration, and inbound leg duration

activitysim.abm.models.trip_scheduling_choice.stop_one_way_only_patterns(tours, travel_duration_col='duration')#

Calculates potential time windows for tours with a single leg with intermediate stops. It calculates all possibilities for the main leg and one tour leg to sum to the tour duration. The other leg is asserted with a duration of zero. :param tours: pd.Dataframe: Tours with no intermediate stops. :return: pd.Dataframe: Main leg duration, outbound leg duration, and inbound leg duration

The return dataframe is indexed to the tour input index

activitysim.abm.models.trip_scheduling_choice.stop_two_way_only_patterns(tours, travel_duration_col='duration')#

Calculates potential time windows for tours with intermediate stops on both legs. It calculates all possibilities for the main leg and both tour legs to sum to the tour duration. :param tours: pd.Dataframe: Tours with no intermediate stops. :return: pd.Dataframe: Main leg duration, outbound leg duration, and inbound leg duration

The return dataframe is indexed to the tour input index

activitysim.abm.models.trip_scheduling_choice.get_pattern_index_and_arrays(tour_indexes, durations, one_way=True)#

A helper method to quickly calculate all of the potential time windows for a given set of tour indexes and durations. :param tour_indexes: List of tour indexes :param durations: List of tour durations :param one_way: If True, calculate windows for only one tour leg. If False,

calculate tour windows for both legs

Returns:

np.array: Tour indexes repeated for valid pattern np.array: array with a column for main tour leg, outbound leg, and inbound leg np.array: array with the number of patterns for each tour

activitysim.abm.models.trip_scheduling_choice.get_spec_for_segment(state: State, model_settings: TripSchedulingChoiceSettings, segment: str)#

Read in the model spec :param model_settings: model settings file :param segment: which segment of the spec file do you want to read :return: array of utility equations