Skip to content

Commit

Permalink
Trip destination alts preprocessor for both sample and simulate steps (
Browse files Browse the repository at this point in the history
…#869)

* trip_destination alts preprocessor

* non_hh_veh cat, drop unused cols for alts

* blacken

* adding missed alts columns used in xborder model

* remove unneeded addition to categorical

* revert change to drop size terms

* creating separate sample and simulate preprocessors

---------

Co-authored-by: Jeffrey Newman <[email protected]>
  • Loading branch information
dhensle and jpn-- authored May 14, 2024
1 parent 1cb48c7 commit 564c476
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions activitysim/abm/models/trip_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class TripDestinationSettings(LocationComponentSettings, extra="forbid"):
PRIMARY_DEST: str = "tour_leg_dest" # must be created in preprocessor
REDUNDANT_TOURS_MERGED_CHOOSER_COLUMNS: list[str] | None = None
preprocessor: PreprocessorSettings | None = None
alts_preprocessor: PreprocessorSettings | None = None
alts_preprocessor_sample: PreprocessorSettings | None = None
alts_preprocessor_simulate: PreprocessorSettings | None = None
CLEANUP: bool
fail_some_trips_for_testing: bool = False
"""This setting is used by testing code to force failed trip_destination."""
Expand Down Expand Up @@ -202,6 +203,15 @@ def _destination_sample(

log_alt_losers = state.settings.log_alt_losers

if model_settings.alts_preprocessor_sample:
expressions.assign_columns(
state,
df=alternatives,
model_settings=model_settings.alts_preprocessor_sample,
locals_dict=locals_dict,
trace_label=tracing.extend_trace_label(trace_label, "alts"),
)

choices = interaction_sample(
state,
choosers=trips,
Expand Down Expand Up @@ -936,6 +946,15 @@ def trip_destination_simulate(
)
locals_dict.update(skims)

if model_settings.alts_preprocessor_simulate:
expressions.assign_columns(
state,
df=destination_sample,
model_settings=model_settings.alts_preprocessor_simulate,
locals_dict=locals_dict,
trace_label=tracing.extend_trace_label(trace_label, "alts"),
)

log_alt_losers = state.settings.log_alt_losers
destinations = interaction_sample_simulate(
state,
Expand Down Expand Up @@ -1246,7 +1265,6 @@ def run_trip_destination(
state.filesystem, model_settings_file_name
)
preprocessor_settings = model_settings.preprocessor
alts_preprocessor_settings = model_settings.alts_preprocessor
logsum_settings = state.filesystem.read_model_settings(
model_settings.LOGSUM_SETTINGS
)
Expand Down Expand Up @@ -1369,15 +1387,6 @@ def run_trip_destination(
trace_label=nth_trace_label,
)

if alts_preprocessor_settings:
expressions.assign_columns(
state,
df=alternatives,
model_settings=alts_preprocessor_settings,
locals_dict=locals_dict,
trace_label=tracing.extend_trace_label(nth_trace_label, "alts"),
)

if isinstance(
nth_trips["trip_period"].dtype, pd.api.types.CategoricalDtype
):
Expand Down

0 comments on commit 564c476

Please sign in to comment.