fxi bA81 infeasable
This commit is contained in:
@@ -59,7 +59,7 @@ NEG_SELL_CURTAIL_PENALTY_CZK_KWH = 1.0
|
||||
NEG_SELL_PV_CHARGE_REWARD_CZK_KWH = 0.8
|
||||
# Měkký tlak: v okně sell<0 dobít na soc_max (ne zastavit na ~94 % kvůli curtail).
|
||||
NEG_SELL_SOC_UNDERFILL_PENALTY_CZK_PER_WH = 0.35
|
||||
PLANNER_BUILD_TAG = "2026-05-24-evening-export-v4"
|
||||
PLANNER_BUILD_TAG = "2026-05-24-ba81-pv-b-export-v5"
|
||||
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
|
||||
@@ -802,6 +802,40 @@ def _evening_peak_export_indices(
|
||||
return out
|
||||
|
||||
|
||||
def _evening_battery_export_push_indices(
|
||||
slots: list[PlanningSlot],
|
||||
*,
|
||||
profitable_export_ts: set[int],
|
||||
degrad_czk_kwh: float,
|
||||
evening_start_hour: int = 17,
|
||||
max_slots_per_day: int = 3,
|
||||
) -> list[int]:
|
||||
"""
|
||||
Tvrdý push ge_bat jen u několika nejlepších večerních slotů/den (profitable ∩ peak).
|
||||
Jinak součet ge_bat × z_export přes celý peak pásmo může překročit dostupné SoC → Infeasible.
|
||||
"""
|
||||
peak_ts = _evening_peak_export_indices(
|
||||
slots,
|
||||
degrad_czk_kwh=degrad_czk_kwh,
|
||||
evening_start_hour=evening_start_hour,
|
||||
)
|
||||
by_day: dict = {}
|
||||
for t in peak_ts:
|
||||
if t not in profitable_export_ts:
|
||||
continue
|
||||
d = _prague_calendar_date(slots[t])
|
||||
by_day.setdefault(d, []).append(t)
|
||||
out: list[int] = []
|
||||
for d in sorted(by_day.keys()):
|
||||
ranked = sorted(
|
||||
by_day[d],
|
||||
key=lambda i: float(slots[i].sell_price),
|
||||
reverse=True,
|
||||
)
|
||||
out.extend(ranked[:max_slots_per_day])
|
||||
return sorted(out)
|
||||
|
||||
|
||||
def _pv_forced_vent_export_allowed(
|
||||
t: int,
|
||||
*,
|
||||
@@ -1138,9 +1172,6 @@ def solve_dispatch(
|
||||
fixed_tariff=fixed_tariff_like_pre,
|
||||
):
|
||||
profitable_export_ts_pre.add(_t)
|
||||
elif slots[_t].allow_discharge_export:
|
||||
# SQL maska (R__063) už vybrala slot — neblokovat push/shortfall kvůli acq.
|
||||
profitable_export_ts_pre.add(_t)
|
||||
if first_neg_sell_idx is not None and first_neg_sell_idx > 0 and floor_pct is not None:
|
||||
# Kotva na ranním peaku (ne na posledním slotu před sell<0) — jinak dump až v 07:30.
|
||||
if (
|
||||
@@ -1413,7 +1444,12 @@ def solve_dispatch(
|
||||
export_push_w,
|
||||
float(battery.max_discharge_power_w) * 0.5,
|
||||
)
|
||||
for t_peak in evening_peak_export_ts:
|
||||
evening_push_ts = _evening_battery_export_push_indices(
|
||||
slots,
|
||||
profitable_export_ts=profitable_export_ts,
|
||||
degrad_czk_kwh=float(degradation_cost_effective),
|
||||
)
|
||||
for t_peak in evening_push_ts:
|
||||
if t_peak not in discharge_export_slots:
|
||||
continue
|
||||
prob += ge_bat[t_peak] >= evening_export_push_w * z_export[t_peak]
|
||||
@@ -1768,15 +1804,19 @@ def solve_dispatch(
|
||||
and sell_t < 0
|
||||
and not fixed_tariff_like_pre
|
||||
)
|
||||
if (
|
||||
# BA81 (fixní tarif + pole B): ge_pv==0 z pv_store by znemožnilo odvést nelimitovatelný
|
||||
# výkon B (plná baterie po sell<0). Místo toho jen strop na pv_b.
|
||||
fixed_pv_b_export_cap = (
|
||||
fixed_tariff_like_pre
|
||||
and sell_t < 0
|
||||
and t in charge_slots
|
||||
):
|
||||
and float(s.pv_b_forecast_w) > 0
|
||||
and not getattr(grid, "block_export_on_negative_sell", False)
|
||||
)
|
||||
if fixed_pv_b_export_cap:
|
||||
prob += ge_pv[t] <= max(0.0, float(s.pv_b_forecast_w))
|
||||
if (
|
||||
not allow_pre_neg_pv_export
|
||||
and not skip_pv_store_block
|
||||
and not fixed_pv_b_export_cap
|
||||
and sell_t < pv_store_val
|
||||
and not _pv_forced_vent_export_allowed(
|
||||
t,
|
||||
|
||||
@@ -1222,7 +1222,7 @@ class NegativeSellPvChargeTests(unittest.TestCase):
|
||||
50.0,
|
||||
operating_mode="AUTO",
|
||||
)
|
||||
self.assertEqual(snap.get("planner_build_tag"), "2026-05-24-evening-export-v4")
|
||||
self.assertEqual(snap.get("planner_build_tag"), "2026-05-24-ba81-pv-b-export-v5")
|
||||
self.assertGreater(
|
||||
results[0].battery_setpoint_w,
|
||||
5_500,
|
||||
@@ -1292,6 +1292,83 @@ class NegativeSellPvChargeTests(unittest.TestCase):
|
||||
self.assertLess(r0.grid_setpoint_w, 0, "očekáván export do sítě")
|
||||
self.assertEqual(r0.export_mode, "BATTERY_SELL")
|
||||
|
||||
def test_fixed_tariff_post_neg_pv_b_full_soc_feasible(self) -> None:
|
||||
"""BA81: plná baterie + sell<0 + odpoledne pv_b — ge_pv==0 z pv_store dříve dělalo Infeasible."""
|
||||
slots = [
|
||||
PlanningSlot(
|
||||
interval_start=datetime(2026, 5, 24, 6, 0, tzinfo=timezone.utc)
|
||||
+ timedelta(minutes=15 * i),
|
||||
buy_price=3.088,
|
||||
sell_price=-0.8,
|
||||
pv_a_forecast_w=12_000,
|
||||
pv_b_forecast_w=0,
|
||||
load_baseline_w=500,
|
||||
ev1_connected=False,
|
||||
ev2_connected=False,
|
||||
allow_charge=True,
|
||||
allow_discharge_export=False,
|
||||
charge_acquisition_buy_czk_kwh=3.61,
|
||||
)
|
||||
for i in range(6)
|
||||
]
|
||||
slots.append(
|
||||
PlanningSlot(
|
||||
interval_start=datetime(2026, 5, 24, 12, 0, tzinfo=timezone.utc),
|
||||
buy_price=3.088,
|
||||
sell_price=3.2,
|
||||
pv_a_forecast_w=0,
|
||||
pv_b_forecast_w=2_500,
|
||||
load_baseline_w=500,
|
||||
ev1_connected=False,
|
||||
ev2_connected=False,
|
||||
allow_charge=False,
|
||||
allow_discharge_export=False,
|
||||
charge_acquisition_buy_czk_kwh=3.61,
|
||||
future_sell_opportunity_czk_kwh=3.76,
|
||||
)
|
||||
)
|
||||
battery = _battery(uc_wh=12_500.0, terminal_soc_value_factor=0.0)
|
||||
battery.max_charge_power_w = 6_250
|
||||
battery.max_discharge_power_w = 6_250
|
||||
battery.degradation_cost_czk_kwh = 0.3
|
||||
battery.planner_daytime_charge_target_enabled = False
|
||||
hp = SimpleNamespace(
|
||||
rated_heating_power_w=0,
|
||||
tuv_min_temp_c=45.0,
|
||||
tuv_target_temp_c=55.0,
|
||||
)
|
||||
grid = SimpleNamespace(
|
||||
max_import_power_w=17_000,
|
||||
max_export_power_w=16_000,
|
||||
block_export_on_negative_sell=False,
|
||||
)
|
||||
vehicles = [
|
||||
SimpleNamespace(
|
||||
max_charge_power_w=0,
|
||||
battery_capacity_kwh=1.0,
|
||||
default_target_soc_pct=80.0,
|
||||
),
|
||||
SimpleNamespace(
|
||||
max_charge_power_w=0,
|
||||
battery_capacity_kwh=1.0,
|
||||
default_target_soc_pct=80.0,
|
||||
),
|
||||
]
|
||||
soc0 = 0.95 * battery.usable_capacity_wh
|
||||
results, _ms, snap = solve_dispatch(
|
||||
slots,
|
||||
battery,
|
||||
hp,
|
||||
grid,
|
||||
[None, None],
|
||||
vehicles,
|
||||
soc0,
|
||||
50.0,
|
||||
operating_mode="AUTO",
|
||||
)
|
||||
self.assertEqual(snap.get("planner_build_tag"), "2026-05-24-ba81-pv-b-export-v5")
|
||||
self.assertEqual(len(results), len(slots))
|
||||
|
||||
|
||||
class AutoPvSurplusExportTests(unittest.TestCase):
|
||||
"""Plná baterie + vysoká FVE: export přebytku (ge_pv), ne curtailment, bez SELL."""
|
||||
|
||||
Reference in New Issue
Block a user