Skip to content

Fix for simulation-based shadow pricing segmentation - #1083

Open
i-am-sijia wants to merge 4 commits into
ActivitySim:mainfrom
wsp-sag:shadow-pricing-simu-fix
Open

i-am-sijia wants to merge 4 commits into
ActivitySim:mainfrom
wsp-sag:shadow-pricing-simu-fix

Conversation

@i-am-sijia

@i-am-sijia i-am-sijia commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

Addressing #1082 with option 2 ...

Summary generated by Copilot (reviewed):

This pull request refactors how chooser segments are handled in the shadow pricing logic, making the configuration more flexible and robust. It uses CHOOSER_SEGMENT_COLUMN_NAME from the location choice model setting for chooser segmentation to keep shadow-pricing resampling consistent with segment_ids in location choice settings, adds better error handling for misconfigurations, and introduces new tests to cover these scenarios.

Shadow Pricing Configuration Improvements:

  • Removed the hardcoded SEGMENT_TO_NAME mapping from both the module-level dictionary and the ShadowPriceSettings class.
  • The ShadowPriceCalculator now uses the CHOOSER_SEGMENT_COLUMN_NAME from location choice model settings to determine the chooser segment column dynamically.

Error Handling Enhancements:

  • In update_shadow_prices, added explicit checks to raise a SystemConfigurationError if the configured chooser segment column is missing from persons_merged, or if there is no overlap between SEGMENT_IDS values and the values present in the chooser segment column.

Testing Improvements:

  • Added new unit tests to verify that shadow pricing works with customized chooser segments (e.g., a string column) and that misconfigurations (such as non-overlapping segment values) are properly detected and raise clear errors.
  • Updated test fixtures to include string-valued chooser segment columns for more comprehensive coverage.

@jpn--

jpn-- commented Aug 27, 2026

Copy link
Copy Markdown
Member

As discussed in engineering 8/27, this needs a unit test. @i-am-sijia will tackle this.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Validation includes ineligible persons, and removing a previously supported setting breaks existing configurations.

2 open findings
What changed in this PR

Updates simulation-based shadow pricing to use each location model’s configured chooser segmentation.

Changes:

  • Uses CHOOSER_SEGMENT_COLUMN_NAME for resampling.
  • Adds configuration validation and custom-segment tests.
File Description
activitysim/​abm/​tables/​shadow_pricing.py Refactors segmentation and adds validation.
activitysim/​abm/​test/​test_misc/​test_shadow_pricing_simulate.py Tests string segments and non-overlapping values.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 129 to 130
WRITE_ITERATION_CHOICES: bool = False


# Fail fast on obvious misconfiguration instead of silently sampling no one.
segment_values = set(self.segment_ids.values())
chooser_values = set(persons_merged[segment_name].dropna().unique())

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants