Skip to content

Replace DP per-period grid search with closed-form breakpoint enumeration (Approach 1 of #276) #282

Description

@johanzander

Summary

Follow-up from #276 (see design doc docs/superpowers/specs/2026-07-12-dp-continuous-action-reformulation-design.md,
PR #281). That investigation empirically confirmed the DP's per-period
reward+continuation objective is piecewise-linear in the continuous power
action, and recommended trying the smaller "Approach 1" fix before
committing to the larger exact-piecewise-linear-V redesign (Approach 2).

What to implement

In _best_action_at_continuous_state (core/bess/dp_battery_algorithm.py),
replace the per-period grid search over power_levels with breakpoint
enumeration:

  1. Discharge: since the objective is piecewise-linear, its optimum
    always lands on a breakpoint or a domain boundary. Evaluate the
    candidate set: physical discharge power bounds, the
    BATTERY_EXPORT_THRESHOLD_KWH crossing (a real jump discontinuity —
    must be modeled explicitly, not smoothed over), and V_next's existing
    grid breakpoints (reachable via _interpolate_value's known grid
    spacing) — instead of ~30 discharge power levels.
  2. Charge (STORE): no search needed at all. The design doc's Finding 4
    showed the actual energy stored during any power > POWER_TOLERANCE_KW
    depends only on max_charge_power_kw, solar surplus, and available
    room — not on the chosen power value. Evaluate one STORE action
    instead of ~30 identical-reward grid points.
  3. IDLE remains a single evaluated action, as today.

This should be both more accurate (closes most of #275's residual
interpolation-error gap, per the design doc's measured 0.03–0.10 SEK
single-period gaps) and cheaper (fewer candidate points evaluated per
cell than today's ~61-level grid), unlike Option B's tradeoff (finer grid
= more expensive).

Validation required before merge

Out of scope

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions