Skip to content

Fix add_tiny_price_slope for flat prices to reliably break ties in LP optimizer#1991

Draft
Copilot wants to merge 2 commits intofeat/multi-commodityfrom
copilot/sub-pr-1946
Draft

Fix add_tiny_price_slope for flat prices to reliably break ties in LP optimizer#1991
Copilot wants to merge 2 commits intofeat/multi-commodityfrom
copilot/sub-pr-1946

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

With constant energy prices, the tie-breaking slope added by add_tiny_price_slope was too small for the LP solver to distinguish early from late charging, causing charging to scatter across time slots instead of front-loading as expected.

Root cause

When price_spread == 0, the fallback penalty was a fixed absolute value max_penalty = d = 1e-4 (0.0001 EUR/MWh). At 100 EUR/MWh flat prices this creates a total slope of 0.0001 EUR/MWh across the scheduling window — within HiGHS's numerical tolerance, so the solver treated all time slots as equivalent.

Fix

Scale the fallback by the actual price level instead of a fixed constant:

# Before
else:
    max_penalty = d  # always 1e-4, too small for e.g. 100 EUR/MWh flat prices

# After
else:
    max_penalty = max(abs(prices[col_name].mean()), 1.0) * d  # 0.01 EUR/MWh at 100 EUR/MWh

This produces a 100× larger slope (0.01 EUR/MWh) for typical energy prices, reliably above LP solver tolerance.

Test assertions added

test_two_flexible_assets_with_commodity now verifies the expected early-charging behaviour and electricity costs:

  • Battery (20 kW cap, SOC 20→80 kWh, η=0.95): draws 60/0.95 ≈ 63.16 kWh → 3 full slots at 20 kW + partial slot, cost ≈ 6.316 EUR
  • Heat pump (10 kW cap, SOC 10→40 kWh, η=0.95): draws 30/0.95 ≈ 31.58 kWh → 3 full slots at 10 kW + partial slot, cost ≈ 3.158 EUR
  • Both devices: zero power in slots 4–23

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…arly-charging assertions

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on multi-commodity support in device scheduler PR Fix add_tiny_price_slope for flat prices to reliably break ties in LP optimizer Feb 26, 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