Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trip Destination Alternatives Preprocessor #865

Merged
merged 5 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions activitysim/abm/models/trip_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ 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
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 @@ -1245,6 +1246,7 @@ 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 @@ -1334,8 +1336,6 @@ def run_trip_destination(
# returns a series of size_terms for each chooser's dest_zone_id and purpose with chooser index
size_term_matrix = DataFrameMatrix(alternatives)

# don't need size terms in alternatives, just zone_id index
alternatives = alternatives.drop(alternatives.columns, axis=1)
alternatives.index.name = model_settings.ALT_DEST_COL_NAME

sample_list = []
Expand Down Expand Up @@ -1369,6 +1369,15 @@ 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
2 changes: 2 additions & 0 deletions activitysim/abm/models/vehicle_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def vehicle_allocation(
choices.loc[choices["alt_choice"] == alt, "choice"] = choosers.loc[
choices["alt_choice"] == alt, alt
]

# set choice for non-household vehicle option
choices.loc[
choices["alt_choice"] == alts_from_spec[-1], "choice"
] = alts_from_spec[-1]
Expand Down
9 changes: 9 additions & 0 deletions activitysim/core/interaction_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ def _interaction_sample(
sharrow_enabled=sharrow_enabled,
)

alternatives = util.drop_unused_columns(
alternatives,
spec,
locals_d,
custom_chooser=None,
sharrow_enabled=sharrow_enabled,
additional_columns=["tdd", "origin_destination"],
)

if sharrow_enabled:
(
interaction_utilities,
Expand Down
9 changes: 9 additions & 0 deletions activitysim/core/interaction_sample_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ def _interaction_sample_simulate(
sharrow_enabled=sharrow_enabled,
)

alternatives = util.drop_unused_columns(
alternatives,
spec,
locals_d,
custom_chooser=None,
sharrow_enabled=sharrow_enabled,
additional_columns=["tdd", "origin_destination"],
)

interaction_df = alternatives.join(choosers, how="left", rsuffix="_chooser")
logger.info(
f"{trace_label} end merging choosers and alternatives to create interaction_df"
Expand Down
Loading