uz lepsi ale nabije v zaporu jen na 92%, odstranena nejaka konstanta
Some checks failed
CI and deploy / migration-check (push) Failing after 12s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-05-23 23:41:52 +02:00
parent 7ff2abc7e0
commit ce571a93fa
4 changed files with 70 additions and 16 deletions

View File

@@ -57,9 +57,7 @@ PV_CHARGE_SHORTFALL_PENALTY_CZK_KWH = 120.0
NEG_SELL_CURTAIL_PENALTY_CZK_KWH = 1.0
# Odměna v objective za FVE→baterie při sell<0 (doplňuje shortfall; BA81 fixed tarif).
NEG_SELL_PV_CHARGE_REWARD_CZK_KWH = 0.8
# Cíl SoC v okně záporného výkupu (podíl soc_max) — safety_soc_target z SQL jde jen k ~50 %.
NEG_SELL_CHARGE_SOC_FRAC_OF_MAX = 0.92
PLANNER_BUILD_TAG = "2026-05-24-neg-sell-v2"
PLANNER_BUILD_TAG = "2026-05-24-neg-sell-v3"
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
@@ -1096,6 +1094,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)
last_neg_sell_by_prague_date: dict[object, int] = {}
for t_ln, st_ln in enumerate(slots):
if float(st_ln.sell_price) < 0:
last_neg_sell_by_prague_date[_prague_calendar_date(st_ln)] = t_ln
t_pre_neg_peak = _pre_neg_peak_sell_idx(slots, first_neg_sell_idx)
morning_pre_neg_export_ts = _morning_pre_neg_export_indices(
slots,
@@ -1143,6 +1145,7 @@ def solve_dispatch(
safety_pen_czk_per_wh: list[float] = []
safety_vars: list[Optional[pulp.LpVariable]] = []
safety_active: list[bool] = []
post_neg_pv_topup: list[bool] = []
high_sell_slot: list[bool] = []
for t in range(T):
sft = slots[t].safety_soc_target_wh if daytime_en else None
@@ -1156,15 +1159,29 @@ def solve_dispatch(
fs = float(slots[t].future_sell_opportunity_czk_kwh or slots[t].sell_price)
bv = max(fb, fs) - float(degradation_cost_effective)
bv = max(0.0, min(5.0, bv))
st_d = _prague_calendar_date(slots[t])
ln_neg = last_neg_sell_by_prague_date.get(st_d)
pv_topup_after_neg = bool(
om == "AUTO"
and ln_neg is not None
and t > ln_neg
and float(slots[t].sell_price) >= 0.0
and bool(slots[t].is_daytime_pv_surplus_slot)
and not hs
)
post_neg_pv_topup.append(pv_topup_after_neg)
# Safety deficit penalizujeme jen v PV surplus slotech, a ne ve high-sell špičce.
# Záměr: safety není obecná „nabij co nejdřív“ motivace; je to preference využít přebytek PV.
active = bool(
sft is not None
and (
bool(slots[t].is_daytime_pv_surplus_slot)
or (planner_v2 and float(slots[t].buy_price) < 0.0)
(
sft is not None
and (
bool(slots[t].is_daytime_pv_surplus_slot)
or (planner_v2 and float(slots[t].buy_price) < 0.0)
)
and not hs
)
and not hs
or pv_topup_after_neg
)
safety_active.append(active)
safety_pen_czk_per_wh.append(bv / 1000.0 if active else 0.0)
@@ -1222,6 +1239,22 @@ def solve_dispatch(
cap_w = float(min(pv_surplus_w, battery.max_charge_power_w))
sf_pv = pulp.LpVariable(f"pv_charge_shortfall_{t}", 0, cap_w)
pv_charge_shortfall.append((t, sf_pv, cap_w))
for t in range(T):
if not post_neg_pv_topup[t]:
continue
if float(slots[t].sell_price) < 0:
continue
pv_surplus_w = max(
0.0,
float(slots[t].pv_a_forecast_w)
+ float(slots[t].pv_b_forecast_w)
- float(slots[t].load_baseline_w),
)
if pv_surplus_w <= 500:
continue
cap_w = float(min(pv_surplus_w, battery.max_charge_power_w))
sf_pv = pulp.LpVariable(f"post_neg_pv_shortfall_{t}", 0, cap_w)
pv_charge_shortfall.append((t, sf_pv, cap_w))
# --- Účelová funkce (jen OTE sloty; terminal SoC shadow price na konci horizontu) ---
# Kanály: gi×buy, ge_pv×sell, ge_bat×sell, +ge_bat×acquisition (export bat. jen v discharge slotách).
@@ -1415,17 +1448,18 @@ def solve_dispatch(
sv = safety_vars[t]
tgt_s = slots[t].safety_soc_target_wh if daytime_en else None
if sv is not None and tgt_s is not None:
eff_tgt_s = float(tgt_s)
if sv is not None:
eff_tgt_s = float(tgt_s) if tgt_s is not None else float(min_soc_wh)
if (
om == "AUTO"
and float(s.sell_price) < 0.0
and t in charge_slots
):
eff_tgt_s = max(
eff_tgt_s,
float(battery.soc_max_wh) * NEG_SELL_CHARGE_SOC_FRAC_OF_MAX,
)
# 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))
elif post_neg_pv_topup[t]:
# Po konci sell<0: dobit z FVE na plno, pak teprve export (kladný sell, ne večerní peak).
eff_tgt_s = max(eff_tgt_s, float(battery.soc_max_wh))
prob += sv >= eff_tgt_s - soc[t]
# ev_via_bat kryto z discharge