x
Some checks failed
CI and deploy / migration-check (push) Failing after 11s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-05-25 02:41:36 +02:00
parent a1270dcda3
commit 0a0668000b
4 changed files with 36 additions and 30 deletions

View File

@@ -64,7 +64,7 @@ NEG_SELL_PV_B_VENT_PENALTY_CZK_KWH = 4.0
# Výboj baterie při sell<0 jen těsně před extrémně záporným buy (round-trip arbitráž).
EXTREME_BUY_DUMP_PREWINDOW_SLOTS = 12
NEG_SELL_BAT_DUMP_SHORTFALL_PENALTY_CZK_KWH = 80.0
PLANNER_BUILD_TAG = "2026-05-28-morning-hold-soc-v21"
PLANNER_BUILD_TAG = "2026-05-28-morning-hold-soc-v21b"
CORRECTION_WINDOW_H = 1 # hodina zpět pro výpočet korekčního faktoru
CORRECTION_MIN_CLAMP = 0.5 # spodní limit korekčního faktoru
CORRECTION_MAX_CLAMP = 1.5 # horní limit korekčního faktoru
@@ -1262,6 +1262,10 @@ def solve_dispatch(
# Kotva: poslední slot před prvním sell<0 by měl končit u planner floor (pokud relaxace existuje).
# Slack penalizujeme v objective; samotné omezení přidáme až po definici soc.
first_neg_sell_idx, pre_neg_export_last_t = _pre_negative_sell_export_window(slots)
first_neg_buy_idx = next(
(t for t, s in enumerate(slots) if float(s.buy_price) < 0.0),
None,
)
last_neg_sell_by_prague_date: dict[object, int] = {}
for t_ln, st_ln in enumerate(slots):
if float(st_ln.sell_price) < 0:
@@ -1402,16 +1406,13 @@ def solve_dispatch(
))
sf = pulp.LpVariable(f"export_shortfall_{t}", 0, cap_w)
peak_export_shortfall.append((t, sf, cap_w))
first_neg_buy_idx_pen = next(
(t for t, s in enumerate(slots) if float(s.buy_price) < 0.0), None
)
for t in range(T):
if float(slots[t].sell_price) >= 0:
continue
if t not in charge_slots:
continue
# Před buy<0: nepenalizovat / netlačit PV→bat (jinak 98 % v 09:15 a export v sell<0).
if first_neg_buy_idx_pen is not None and t < first_neg_buy_idx_pen:
if first_neg_buy_idx is not None and t < first_neg_buy_idx:
continue
pv_surplus_w = max(
0.0,
@@ -1445,7 +1446,7 @@ def solve_dispatch(
continue
if t not in charge_slots:
continue
if first_neg_buy_idx_pen is not None and t < first_neg_buy_idx_pen:
if first_neg_buy_idx is not None and t < first_neg_buy_idx:
continue
pv_surplus_w = max(
0.0,
@@ -1697,6 +1698,7 @@ def solve_dispatch(
om == "AUTO"
and float(s.sell_price) < 0.0
and t in charge_slots
and (first_neg_buy_idx is None or t >= first_neg_buy_idx)
):
# Záporný výkup: dobít na planner soc_max (typicky 95100 %), ne jen SQL safety ~50 %.
eff_tgt_s = max(eff_tgt_s, float(battery.soc_max_wh))
@@ -1781,15 +1783,24 @@ def solve_dispatch(
prob += ge_pv[t] == 0
elif not purchase_fixed_pre:
# Spot (home-01): ge_pv=0 dokud není plná baterie; pak jen ventil pole B (ne celý surplus).
soc_prev_neg = current_soc_wh if t == 0 else soc[t - 1]
w_pv_b_vent = pulp.LpVariable(f"w_pv_b_vent_neg_{t}", cat=pulp.LpBinary)
m_soc_neg = float(battery.soc_max_wh)
prob += soc_prev_neg >= (
m_soc_neg
- soc_headroom_wh
- m_soc_neg * (1 - w_pv_b_vent)
# Před buy<0 + bc_pv=0: přebytek pole B musí jít do sítě (ge_pv≤pv_b), jinak Infeasible.
before_first_neg_buy = (
first_neg_buy_idx is not None and t < first_neg_buy_idx
)
prob += ge_pv[t] <= float(s.pv_b_forecast_w) * w_pv_b_vent
if before_first_neg_buy and float(s.pv_b_forecast_w) > 0:
prob += ge_pv[t] <= float(s.pv_b_forecast_w)
else:
soc_prev_neg = current_soc_wh if t == 0 else soc[t - 1]
w_pv_b_vent = pulp.LpVariable(
f"w_pv_b_vent_neg_{t}", cat=pulp.LpBinary
)
m_soc_neg = float(battery.soc_max_wh)
prob += soc_prev_neg >= (
m_soc_neg
- soc_headroom_wh
- m_soc_neg * (1 - w_pv_b_vent)
)
prob += ge_pv[t] <= float(s.pv_b_forecast_w) * w_pv_b_vent
soc_prev_expr = current_soc_wh if t == 0 else soc[t - 1]
arb_t = arb_floor_series[t]
@@ -1920,9 +1931,6 @@ def solve_dispatch(
prob += bd[t] == 0
# Slot pre-selection (z DB fn_load_planning_slots_full → allow_*)
first_neg_buy_idx_main = next(
(t for t, s in enumerate(slots) if float(s.buy_price) < 0.0), None
)
if om == "AUTO":
for t in range(T):
s = slots[t]
@@ -1942,7 +1950,7 @@ def solve_dispatch(
):
prob += bc_gi[t] == 0
before_neg_buy = (
first_neg_buy_idx_main is not None and t < first_neg_buy_idx_main
first_neg_buy_idx is not None and t < first_neg_buy_idx
)
if before_neg_buy and sell_t_pre < 0.0 and pv_surplus_w > 0:
# Ranní sell<0 před buy<0: PV do sítě/curtail, ne do baterie (kapacita na import).