dalsi snaha o fix
Some checks failed
CI and deploy / migration-check (push) Failing after 19s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-05-22 23:05:45 +02:00
parent 0c4de4e5b9
commit f157c10480
3 changed files with 92 additions and 10 deletions

View File

@@ -633,6 +633,20 @@ def _pv_store_value_czk_kwh(slot: PlanningSlot, min_spread: float) -> float:
return future - min_spread
def _horizon_fixed_tariff_like(slots: list[PlanningSlot]) -> bool:
"""
Fixní nákup (KV1): buy v horizontu je prakticky konstantní.
U spotu (home-01) nesmí expensive_import používat charge_acquisition — jinak
buy > ~1 Kč označí téměř všechny sloty jako drahé (gi=0 pro dům) → Infeasible.
"""
buys = [float(s.buy_price) for s in slots if float(s.buy_price) >= 0.0]
if not buys:
return False
if len(buys) == 1:
return True
return max(buys) - min(buys) < 0.25
def _pre_negative_sell_export_window(
slots: list[PlanningSlot],
) -> tuple[int | None, int | None]:
@@ -747,10 +761,12 @@ def solve_dispatch(
operating_mode: str = "AUTO",
charge_commitment_prev_w: Optional[list[Optional[float]]] = None,
planner_version: str | None = None,
relaxed_expensive_import: bool = False,
) -> tuple[list[DispatchResult], int, dict[str, Any]]:
"""
LP solver pro dispatch optimalizaci.
Vrátí (výsledky, solver_duration_ms, solver_debug_snapshot).
relaxed_expensive_import: nouzový režim po Infeasible — síť smí krmit baseload v drahých slotech.
"""
T = len(slots)
if T < 1:
@@ -1364,15 +1380,19 @@ def solve_dispatch(
):
prob += ge_pv[t] == 0
# Drahý nákup: dům + TČ z baterie (ne import ze sítě); síť jen EV (+ případně TČ).
# Spot: buy > min horizontu. Fixní tarif (KV1): buy > charge_acquisition (jinak je vše „stejně drahé“).
expensive_import_slot = buy_t > ref_buy_horizon + min_spread or (
buy_t > charge_acquisition_czk_kwh + min_spread
)
# Spot (home-01): buy > min ne-záporného buy v horizontu.
# Fixní tarif (KV1): navíc buy > charge_acquisition (konstantní buy ≈ ref).
expensive_import_slot = buy_t > ref_buy_horizon + min_spread
if _horizon_fixed_tariff_like(slots):
expensive_import_slot = expensive_import_slot or (
buy_t > charge_acquisition_czk_kwh + min_spread
)
if expensive_import_slot and t not in charge_slots:
# Síť jen pro EV + skutečný výkon TČ v tomto slotu (hp[t]), ne celý dům.
prob += gi[t] <= ev_cap_t + hp[t]
if om == "AUTO":
# Bazál + TČ z baterie/FVE; hp[t] může být 0 — nesmí se použít hp_rated (infeasible).
# Strict: síť jen EV+TČ; baseload z baterie/FVE. Relaxed: síť smí krmit baseload (nouzový režim).
prob += gi[t] <= ev_cap_t + hp[t] + (
float(s.load_baseline_w) if relaxed_expensive_import else 0.0
)
if not relaxed_expensive_import and om == "AUTO":
prob += (
bd[t] + pv_ld[t]
>= float(s.load_baseline_w) + hp[t]
@@ -1434,7 +1454,27 @@ def solve_dispatch(
status = prob.solve(solver)
duration_ms = int((time.monotonic() - t_start) * 1000)
if pulp.LpStatus[status] != 'Optimal':
if pulp.LpStatus[status] != "Optimal":
if not relaxed_expensive_import:
logger.warning(
"solve_dispatch Infeasible, retry with relaxed_expensive_import "
"(grid may supply baseload in expensive slots)"
)
return solve_dispatch(
slots,
battery,
heat_pump,
grid,
ev_sessions,
vehicles,
current_soc_wh,
current_tuv_temp_c,
tuv_delta_stats=tuv_delta_stats,
operating_mode=operating_mode,
charge_commitment_prev_w=charge_commitment_prev_w,
planner_version=planner_version,
relaxed_expensive_import=True,
)
raise RuntimeError(f"Solver: {pulp.LpStatus[status]}")
# --- Post-processing ---
@@ -1597,6 +1637,7 @@ def solve_dispatch(
"planner_charge_commitment_penalty_czk_kwh": float(commit_pen),
},
"load_first_enabled": om == "AUTO",
"relaxed_expensive_import": relaxed_expensive_import,
"charge_acquisition_buy_czk_kwh": charge_acquisition_czk_kwh,
"charge_acquisition_cutoff_at": (
slots[0].charge_acquisition_cutoff_at.isoformat()