From d26da461e1888089802f5400ca2d6faad2458ed6 Mon Sep 17 00:00:00 2001 From: Matt Richards Date: Tue, 10 Mar 2026 20:52:55 +1100 Subject: [PATCH] ENH: add trip scheduling choice explicit chunking --- .../abm/models/trip_scheduling_choice.py | 10 +++++++-- .../test_misc/test_trip_scheduling_choice.py | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/activitysim/abm/models/trip_scheduling_choice.py b/activitysim/abm/models/trip_scheduling_choice.py index 81d908ef1..0b73cd6cc 100644 --- a/activitysim/abm/models/trip_scheduling_choice.py +++ b/activitysim/abm/models/trip_scheduling_choice.py @@ -276,7 +276,9 @@ def run_trip_scheduling_choice( choosers, chunk_trace_label, chunk_sizer, - ) in chunk.adaptive_chunked_choosers(state, indirect_tours, trace_label): + ) in chunk.adaptive_chunked_choosers( + state, indirect_tours, trace_label, explicit_chunk_size=model_settings.explicit_chunk + ): # Sort the choosers and get the schedule alternatives choosers = choosers.sort_index() schedules = generate_schedule_alternatives(choosers).sort_index() @@ -350,7 +352,11 @@ class TripSchedulingChoiceSettings(LogitComponentSettings, extra="forbid"): Settings for the `trip_scheduling_choice` component. """ - pass + explicit_chunk: float = 0 + """ + If > 0, use this chunk size instead of adaptive chunking. + If less than 1, use this fraction of the total number of rows. + """ @workflow.step diff --git a/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py b/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py index 6823a5b12..6db004b43 100644 --- a/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py +++ b/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py @@ -4,6 +4,7 @@ import os from pathlib import Path +from pandas.testing import assert_frame_equal from activitysim.abm.models import trip_scheduling_choice as tsc from activitysim.abm.tables.skims import skim_dict @@ -285,3 +286,24 @@ def test_run_trip_scheduling_choice(model_spec, tours, skims, locals_dict): # check that tours with no inbound stops have zero inbound duration assert out_tours[tsc.IB_DURATION].mask(in_tours[tsc.HAS_IB_STOPS], 0).sum() == 0 + + # confirm explicit chunking is supported and doesn't affect results + model_settings_explicit_chunk = tsc.TripSchedulingChoiceSettings( + **{ + "SPEC": "placeholder.csv", + "compute_settings": { + "protect_columns": ["origin", "destination", "schedule_id"] + }, + } + ) + out_tours_chunked = tsc.run_trip_scheduling_choice( + state, + model_spec, + tours, + skims, + locals_dict, + trace_label="PyTest Trip Scheduling", + model_settings=model_settings_explicit_chunk, + ) + assert_frame_equal(out_tours, out_tours_chunked) +