Skip to content

Vehicle type model REQUIRE_DATA_FOR_ALL_ALTS needs to be True #789

@i-am-sijia

Description

@i-am-sijia

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.

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:

  1. Delete the first row of the config/vehicle_type_data.csv
  2. Run the existing prototype_mtc_extended model
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working/bug f

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions