chjo2
This commit is contained in:
@@ -55,6 +55,11 @@ PEAK_EXPORT_SHORTFALL_PENALTY_CZK_KWH = 40.0
|
||||
PV_CHARGE_SHORTFALL_PENALTY_CZK_KWH = 120.0
|
||||
# Curtailment při sell<0 + allow_charge: nesmí být téměř zdarma oproti nabíjení (BA81).
|
||||
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"
|
||||
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
|
||||
@@ -1021,19 +1026,19 @@ def solve_dispatch(
|
||||
charge_slots |= {
|
||||
t for t, s in enumerate(slots) if float(s.buy_price) < 0.0
|
||||
}
|
||||
if bool(getattr(grid, "block_export_on_negative_sell", False)):
|
||||
charge_slots |= {
|
||||
t
|
||||
for t, s in enumerate(slots)
|
||||
if float(s.sell_price) < 0.0
|
||||
and max(
|
||||
0,
|
||||
int(s.pv_a_forecast_w)
|
||||
+ int(s.pv_b_forecast_w)
|
||||
- int(s.load_baseline_w),
|
||||
)
|
||||
> 0
|
||||
}
|
||||
# Stejně jako R__063 (sell<0 + PV přebytek): shortfall/curtail penalizace i bez block_export.
|
||||
charge_slots |= {
|
||||
t
|
||||
for t, s in enumerate(slots)
|
||||
if float(s.sell_price) < 0.0
|
||||
and max(
|
||||
0,
|
||||
int(s.pv_a_forecast_w)
|
||||
+ int(s.pv_b_forecast_w)
|
||||
- int(s.load_baseline_w),
|
||||
)
|
||||
> 500
|
||||
}
|
||||
discharge_export_slots = {
|
||||
t for t, s in enumerate(slots) if s.allow_discharge_export
|
||||
}
|
||||
@@ -1248,6 +1253,18 @@ def solve_dispatch(
|
||||
if om == "AUTO" and t in discharge_export_slots
|
||||
else 0
|
||||
)
|
||||
- (
|
||||
bc_pv[t]
|
||||
* NEG_SELL_PV_CHARGE_REWARD_CZK_KWH
|
||||
* INTERVAL_H
|
||||
/ 1000
|
||||
if (
|
||||
om == "AUTO"
|
||||
and float(slots[t].sell_price) < 0.0
|
||||
and t in charge_slots
|
||||
)
|
||||
else 0
|
||||
)
|
||||
+ pulp.lpSum(
|
||||
ev_direct[e][t] * slots[t].buy_price * INTERVAL_H / 1000
|
||||
+ ev_via_bat[e][t] * slots[t].buy_price * EV_ROUNDTRIP_FACTOR * INTERVAL_H / 1000
|
||||
@@ -1399,7 +1416,17 @@ 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:
|
||||
prob += sv >= float(tgt_s) - soc[t]
|
||||
eff_tgt_s = float(tgt_s)
|
||||
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,
|
||||
)
|
||||
prob += sv >= eff_tgt_s - soc[t]
|
||||
|
||||
# ev_via_bat kryto z discharge
|
||||
prob += pulp.lpSum(ev_via_bat[e][t] for e in range(EV)) <= bd[t]
|
||||
@@ -1646,7 +1673,14 @@ def solve_dispatch(
|
||||
float(s.pv_b_forecast_w) > 0
|
||||
and not getattr(grid, "block_export_on_negative_sell", False)
|
||||
and sell_t < 0
|
||||
and not fixed_tariff_like_pre
|
||||
)
|
||||
if (
|
||||
fixed_tariff_like_pre
|
||||
and sell_t < 0
|
||||
and t in charge_slots
|
||||
):
|
||||
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
|
||||
@@ -1904,6 +1938,7 @@ def solve_dispatch(
|
||||
night0 = slots[0]
|
||||
solver_snapshot: dict[str, Any] = {
|
||||
"version": 1,
|
||||
"planner_build_tag": PLANNER_BUILD_TAG,
|
||||
"inputs": {
|
||||
"current_soc_wh": float(current_soc_wh),
|
||||
"operating_mode": operating_mode,
|
||||
|
||||
@@ -1159,6 +1159,76 @@ class NegativeSellPvChargeTests(unittest.TestCase):
|
||||
"nabíjení má dominovat nad curtailmentem",
|
||||
)
|
||||
|
||||
def test_negative_sell_charges_from_plateau_soc_without_allow_charge_mask(self) -> None:
|
||||
"""BA81: allow_charge=false z DB nesmí vypnout shortfall — charge_slots z sell<0 + PV."""
|
||||
base = datetime(2026, 5, 24, 4, 15, tzinfo=timezone.utc)
|
||||
slots: list[PlanningSlot] = []
|
||||
for i in range(6):
|
||||
h = 6 + (i * 15) // 60
|
||||
m = (i * 15) % 60
|
||||
hour_f = max(0.0, min(1.0, (h + m / 60.0 - 6.0) / 14.0))
|
||||
safety = 3750.0 + 2500.0 * hour_f
|
||||
slots.append(
|
||||
PlanningSlot(
|
||||
interval_start=base + timedelta(minutes=15 * i),
|
||||
buy_price=3.088,
|
||||
sell_price=-0.3,
|
||||
pv_a_forecast_w=9000,
|
||||
pv_b_forecast_w=800,
|
||||
load_baseline_w=150,
|
||||
ev1_connected=False,
|
||||
ev2_connected=False,
|
||||
allow_charge=False,
|
||||
allow_discharge_export=False,
|
||||
safety_soc_target_wh=safety,
|
||||
is_daytime_pv_surplus_slot=True,
|
||||
future_sell_opportunity_czk_kwh=3.7,
|
||||
)
|
||||
)
|
||||
battery = _battery(uc_wh=12_500.0, terminal_soc_value_factor=0.2)
|
||||
battery.max_charge_power_w = 6_250
|
||||
battery.max_discharge_power_w = 6_250
|
||||
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.508 * 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-neg-sell-v2")
|
||||
self.assertGreater(
|
||||
results[0].battery_setpoint_w,
|
||||
5_500,
|
||||
f"od ~51 % SoC má první neg slot nabíjet max, got {[r.battery_setpoint_w for r in results]}",
|
||||
)
|
||||
|
||||
|
||||
class AutoPvSurplusExportTests(unittest.TestCase):
|
||||
"""Plná baterie + vysoká FVE: export přebytku (ge_pv), ne curtailment, bez SELL."""
|
||||
|
||||
Reference in New Issue
Block a user