dalsi ladeni
This commit is contained in:
@@ -1095,16 +1095,31 @@ def solve_dispatch(
|
||||
0.0,
|
||||
float(s.pv_a_forecast_w) + float(s.pv_b_forecast_w) - load_t,
|
||||
)
|
||||
# Mezi-slotová arbitráž: ráno prodat FVE (sell > acquisition), odpoledne levně
|
||||
# nabít ze sítě — necpát přebytek do baterie jen protože sell < buy ve stejném slotu.
|
||||
cross_slot_pv_export = (
|
||||
t not in charge_slots
|
||||
and pv_surplus_w > 0
|
||||
and sell_t >= charge_acquisition_czk_kwh + min_spread
|
||||
and any(ts in charge_slots for ts in range(t + 1, T))
|
||||
)
|
||||
# Ztrátový export FVE (sell ≪ buy): zakázat jen pokud jde energii do baterie.
|
||||
# Výjimky: plná baterie (ventil), neriťitelné pv_b s přebytkem.
|
||||
# Výjimky: plná baterie (ventil), neriťitelné pv_b s přebytkem, cross-slot výše.
|
||||
if sell_t < buy_t - min_spread:
|
||||
block_loss_pv_export = not (
|
||||
float(s.pv_b_forecast_w) > 0 and pv_surplus_w > 0
|
||||
)
|
||||
if t == 0 and current_soc_wh >= float(battery.soc_max_wh) - soc_headroom_wh:
|
||||
block_loss_pv_export = False
|
||||
if cross_slot_pv_export:
|
||||
block_loss_pv_export = False
|
||||
if block_loss_pv_export:
|
||||
prob += ge_pv[t] == 0
|
||||
if cross_slot_pv_export:
|
||||
prob += bc[t] == 0
|
||||
prob += ge_pv[t] >= min(
|
||||
pv_surplus_w, float(grid.max_export_power_w)
|
||||
)
|
||||
# Drahý nákup oproti horizontu: import jen na load + EV + TČ, ne na grid-nabíjení.
|
||||
if buy_t >= 0 and buy_t > ref_buy_horizon + min_spread:
|
||||
prob += gi[t] <= load_t + ev_cap_t + hp_rated_w
|
||||
|
||||
@@ -1420,6 +1420,79 @@ class ChargeAcquisitionArbitrageTests(unittest.TestCase):
|
||||
)
|
||||
self.assertLess(evening.battery_setpoint_w, -500)
|
||||
|
||||
def test_morning_pv_export_when_sell_above_acquisition_and_later_grid_charge(self) -> None:
|
||||
"""Ráno sell>acquisition a sell<buy, později levné grid CHARGE — FVE→síť, ne do bat."""
|
||||
base = datetime(2026, 5, 22, 3, 0, tzinfo=timezone.utc)
|
||||
morning = PlanningSlot(
|
||||
interval_start=base,
|
||||
buy_price=5.2,
|
||||
sell_price=3.4,
|
||||
pv_a_forecast_w=2000,
|
||||
pv_b_forecast_w=0,
|
||||
load_baseline_w=600,
|
||||
ev1_connected=False,
|
||||
ev2_connected=False,
|
||||
allow_charge=False,
|
||||
allow_discharge_export=False,
|
||||
charge_acquisition_buy_czk_kwh=0.55,
|
||||
)
|
||||
cheap = PlanningSlot(
|
||||
interval_start=base + timedelta(minutes=15),
|
||||
buy_price=0.55,
|
||||
sell_price=-0.2,
|
||||
pv_a_forecast_w=5000,
|
||||
pv_b_forecast_w=0,
|
||||
load_baseline_w=1800,
|
||||
ev1_connected=False,
|
||||
ev2_connected=False,
|
||||
allow_charge=True,
|
||||
allow_discharge_export=False,
|
||||
charge_acquisition_buy_czk_kwh=0.55,
|
||||
)
|
||||
evening = PlanningSlot(
|
||||
interval_start=base + timedelta(minutes=30),
|
||||
buy_price=7.0,
|
||||
sell_price=5.0,
|
||||
pv_a_forecast_w=0,
|
||||
pv_b_forecast_w=0,
|
||||
load_baseline_w=2500,
|
||||
ev1_connected=False,
|
||||
ev2_connected=False,
|
||||
allow_charge=False,
|
||||
allow_discharge_export=True,
|
||||
charge_acquisition_buy_czk_kwh=0.55,
|
||||
)
|
||||
slots = [morning, cheap, evening]
|
||||
battery = _battery(uc_wh=64_000.0, min_pct=12.0, arb_pct=20.0)
|
||||
battery.max_charge_power_w = 18_000
|
||||
battery.max_discharge_power_w = 18_000
|
||||
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=13_500)
|
||||
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.25 * battery.usable_capacity_wh
|
||||
results, _ms, _ = solve_dispatch(
|
||||
slots,
|
||||
battery,
|
||||
hp,
|
||||
grid,
|
||||
[None, None],
|
||||
vehicles,
|
||||
soc0,
|
||||
50.0,
|
||||
operating_mode="AUTO",
|
||||
)
|
||||
am = results[0]
|
||||
self.assertLess(
|
||||
am.grid_setpoint_w,
|
||||
-100,
|
||||
"morning PV surplus should export when later cheap grid charge exists",
|
||||
)
|
||||
self.assertIn(am.export_mode, ("PV_SURPLUS", "BATTERY_SELL"))
|
||||
self.assertLessEqual(am.battery_setpoint_w, 100)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user