Skip to content

Commit

Permalink
Merge pull request #806 from dhensle/veh_type_optimization
Browse files Browse the repository at this point in the history
Vehicle Type Optimization
  • Loading branch information
jpn-- authored Feb 20, 2024
2 parents 03a6720 + 73d89ba commit 10d105a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions activitysim/abm/models/vehicle_type_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,17 @@ def iterate_vehicle_type_choice(
list(set(alts)) + [""], ordered=False
)

# alts preprocessor
alts_preprocessor_settings = model_settings.alts_preprocessor
if alts_preprocessor_settings:
expressions.assign_columns(
state,
df=alts_wide,
model_settings=alts_preprocessor_settings,
locals_dict=locals_dict,
trace_label=trace_label,
)

# - preparing choosers for iterating
vehicles_merged["already_owned_veh"] = ""
vehicles_merged["already_owned_veh"] = vehicles_merged["already_owned_veh"].astype(
Expand Down Expand Up @@ -438,6 +449,12 @@ def iterate_vehicle_type_choice(
len(choosers),
)

# filter columns of alts and choosers
if len(model_settings.COLS_TO_INCLUDE_IN_CHOOSER_TABLE) > 0:
choosers = choosers[model_settings.COLS_TO_INCLUDE_IN_CHOOSER_TABLE]
if len(model_settings.COLS_TO_INCLUDE_IN_ALTS_TABLE) > 0:
alts_wide = alts_wide[model_settings.COLS_TO_INCLUDE_IN_ALTS_TABLE]

# if there were so many alts that they had to be created programmatically,
# by combining categorical variables, then the utility expressions should make
# use of interaction terms to accommodate alt-specific coefficients and constants
Expand Down Expand Up @@ -542,11 +559,17 @@ class VehicleTypeChoiceSettings(LogitComponentSettings):
PROBS_SPEC: str | None = None
combinatorial_alts: dict | None = None
preprocessor: PreprocessorSettings | None = None
alts_preprocessor: PreprocessorSettings | None = None
SIMULATION_TYPE: Literal[
"simple_simulate", "interaction_simulate"
] = "interaction_simulate"
COLS_TO_INCLUDE_IN_VEHICLE_TABLE: list[str] = []

COLS_TO_INCLUDE_IN_CHOOSER_TABLE: list[str] = []
"""Columns to include in the chooser table for use in utility calculations."""
COLS_TO_INCLUDE_IN_ALTS_TABLE: list[str] = []
"""Columns to include in the alternatives table for use in utility calculations."""

annotate_households: PreprocessorSettings | None = None
annotate_persons: PreprocessorSettings | None = None
annotate_vehicles: PreprocessorSettings | None = None
Expand Down

0 comments on commit 10d105a

Please sign in to comment.