Skip to content

Support perfect-segment (horizontal/vertical) curve intersections in Equilibrium#162

Draft
alexanderthclark wants to merge 1 commit into
mainfrom
codex/refactor-equilibrium-segment-rejection-handling
Draft

Support perfect-segment (horizontal/vertical) curve intersections in Equilibrium#162
alexanderthclark wants to merge 1 commit into
mainfrom
codex/refactor-equilibrium-segment-rejection-handling

Conversation

@alexanderthclark
Copy link
Copy Markdown
Owner

Motivation

  • Equilibrium previously rejected any demand or supply with perfectly elastic/​inelastic segments at construction (Equilibrium.__init__) which prevented valid intersections from being computed; the goal is to handle common perfect-segment combinations instead of blocking them.
  • The change moves special-case handling into the intersection logic so Equilibrium._compute/_find_intersection can return a deterministic (p, q) when the geometry uniquely pins an outcome.
  • When economic indeterminacy (price pinned but quantity not) or genuinely unsupported pairings occur, the model should raise clear, specific errors rather than a blanket rejection.

Description

  • Removed the unconditional perfect-segment rejection from Equilibrium.__init__ so curves with perfect segments may be used.
  • Added a helper Equilibrium._solve_with_perfect_segments(dcurve, scurve) that inspects piece combinations and handles: horizontal vs regular, vertical vs regular, and horizontal vs vertical cases, collecting candidate (p,q) solutions and returning a unique deterministic pair when possible.
  • Wired the helper into Equilibrium._find_intersection to run before the regular piecewise intersection loop and preserved the affine fallback behavior for ordinary cases.
  • Introduced distinct error messages for failure modes: "economically indeterminate quantity at fixed price" for price-equal horizontal pairs and "unsupported combination: ..." for other unhandled perfect-segment pairings or multiple distinct perfect-segment intersections.
  • Made domain validation in _valid_in_domain orientation-safe by using min/max on piece domains so intersections validate correctly regardless of domain ordering.
  • Updated tests in tests/test_horizontal_curves.py to reflect supported perfect-segment outcomes and the new indeterminate error case.

Testing

  • Ran pytest -q tests/test_horizontal_curves.py tests/test_equilibrium.py tests/test_world_price.py and all tests passed (15 passed).
  • The updated horizontal-curve tests exercise horizontal vs regular and horizontal vs horizontal indeterminacy and passed.

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant