Skip to content

Credit a unit's own salvage and retirement in switch times, logs and services - #511

Merged
derrynknife merged 1 commit into
devfrom
build/own-end-switch
Nov 21, 2026
Merged

derrynknife merged 1 commit into
devfrom
build/own-end-switch

Conversation

@derrynknife

Copy link
Copy Markdown
Owner

Summary

best_switch_time, plan_vs_actual and a service's task_value used to refuse a unit's own retire_at and salvage. They now credit them, as expected_npv and npv_distribution already do:

  • best_switch_time scans switch times up to the retirement and adds the salvage to every run of every candidate. The candidates share a seed, so the choice of switch time is unchanged. The result gains salvage, undiscounted_salvage and retire_at, as NPVDistribution has.
  • plan_vs_actual values the plan, and the rest from today, up to the retirement, crediting the salvage there through expected_npv. A salvage by age is taken from the unit's state today. The salvage is listed among what a log does not record. A now past the retirement is refused, and the message names the fix.
  • task_value with Services runs each side to the plan's retirement and credits the salvage in the period it falls in. No service is done after the retirement, and a note says how many were dropped.

Nothing calls _npv.refuse_own_end any more, so it is removed, and _require_priceable loses its flag. A salvage by age in simulated runs, and one unit retiring inside a larger diagram, are still refused, and the messages say what to give instead.

Type of change

  • New feature

Checklist

  • Tests added (test_npv_runs_own_end.py). Each new result is checked against the same calculation without the unit's own end, run from the same seed, plus the salvage: best_switch_time candidate by candidate, plan_vs_actual's plan, rest and revalued NPVs, and the service's two sides.
  • black, isort, flake8 and mypy on the changed files
  • analysis_routes updated: the refusals are gone from both routes; the catalogue's "a plan valued alone" case passes
  • Maintenance README (UC-65) and CHANGELOG.md updated
  • Monte-Carlo tests seeded

Notes for reviewers

Tests run: plan alone, plan vs actual, switch-time diagram, schedule services, NPV distribution, schedule value and result objects (307 passed, 1 skipped). After the last edits, the own-end tests, switch-time tests, plan-alone tests and the routes case were run again (225 passed). Results without the unit's own end are unchanged.


Generated by Claude Code

…services

best_switch_time, plan_vs_actual and a service's task_value refused a
unit's own salvage or retirement. best_switch_time now scans up to the
retirement and credits every candidate's runs the salvage, reporting
it as npv_distribution does; plan_vs_actual values the plan and the
rest from today to the retirement, the salvage credited there as
expected_npv credits it, and lists the salvage among what a log does
not record; task_value runs each side to its plan's retirement,
credits its salvage in the period it falls in, and does no service
after it. With nothing left refusing them, the refusal goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
@derrynknife
derrynknife merged commit 48b2037 into dev Nov 21, 2026
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.

2 participants