-
Notifications
You must be signed in to change notification settings - Fork 118
Description
Describe the bug
The vehicle type choice model creates alts_wide and alts_long tables, and they need to be in the same length and order, because this line of code assumes that for the final mapping of choices:
| choices["vehicle_type"] = choices["vehicle_type"].map(dict(enumerate(alts))) |
However, the section of code below drops alternatives from alts_wide if there are alternatives that do not exist in the input VEHICLE_TYPE_DATA_FILE and if the optional REQUIRE_DATA_FOR_ALL_ALTS does not get defined or is set to False.
activitysim/activitysim/abm/models/vehicle_type_choice.py
Lines 217 to 224 in a8e755f
| if model_settings.get("REQUIRE_DATA_FOR_ALL_ALTS", False): | |
| # fail if alternative does not have an associated record in the data | |
| assert ( | |
| len(missing_alts) == 0 | |
| ), f"missing vehicle data for alternatives:\n {missing_alts}" | |
| else: | |
| # eliminate alternatives if no vehicle type data | |
| alts_wide = alts_wide[alts_wide._merge != "left_only"] |
This will make the alts_wide inconsistent with the alts_long, and make the final mapping of choices incorrect.
The model will still run, but the result will be incorrect.
To Reproduce
Steps to reproduce the behavior:
- Delete the first row of the config/vehicle_type_data.csv
- Run the existing prototype_mtc_extended model
- The model will run, but it creates different result for vehicle type
Expected behavior
The model should fail if there are alternatives that do not exist in the vehicle type data. REQUIRE_DATA_FOR_ALL_ALTS should not be optional or and should be True. The IF condition on Line 217 can be replaced by the assert.