fix solveru
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-ba81-pv-b-export-v5"
|
||||
PLANNER_BUILD_TAG = "2026-05-24-ba81-gen-cutoff-v6"
|
||||
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
|
||||
@@ -1607,11 +1607,12 @@ def solve_dispatch(
|
||||
)
|
||||
if block_pv_export_neg_sell:
|
||||
prob += ge_pv[t] == 0
|
||||
# Tvrdý zákaz celého vývozu (GEN / fixní nákup bez pole B).
|
||||
# Tvrdý zákaz vývozu jen při block_export_on_negative_sell (KV1).
|
||||
# GEN cut-off (z_gen_cutoff) nesmí vynutit ge==0 — jinak nelze odvést pole B při plné baterii (BA81).
|
||||
block_neg_sell_export = bool(
|
||||
getattr(grid, "block_export_on_negative_sell", False)
|
||||
)
|
||||
if z_gen_cutoff is not None or block_neg_sell_export:
|
||||
if block_neg_sell_export:
|
||||
prob += ge[t] == 0
|
||||
prob += ge_pv[t] == 0
|
||||
prob += ge_bat[t] == 0
|
||||
@@ -1812,7 +1813,10 @@ def solve_dispatch(
|
||||
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 z_gen_cutoff is not None:
|
||||
prob += ge_pv[t] <= float(s.pv_b_forecast_w) * (1 - z_gen_cutoff[t])
|
||||
else:
|
||||
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
|
||||
|
||||
@@ -1222,7 +1222,7 @@ class NegativeSellPvChargeTests(unittest.TestCase):
|
||||
50.0,
|
||||
operating_mode="AUTO",
|
||||
)
|
||||
self.assertEqual(snap.get("planner_build_tag"), "2026-05-24-ba81-pv-b-export-v5")
|
||||
self.assertEqual(snap.get("planner_build_tag"), "2026-05-24-ba81-gen-cutoff-v6")
|
||||
self.assertGreater(
|
||||
results[0].battery_setpoint_w,
|
||||
5_500,
|
||||
@@ -1366,7 +1366,71 @@ class NegativeSellPvChargeTests(unittest.TestCase):
|
||||
50.0,
|
||||
operating_mode="AUTO",
|
||||
)
|
||||
self.assertEqual(snap.get("planner_build_tag"), "2026-05-24-ba81-pv-b-export-v5")
|
||||
self.assertEqual(snap.get("planner_build_tag"), "2026-05-24-ba81-gen-cutoff-v6")
|
||||
self.assertEqual(len(results), len(slots))
|
||||
|
||||
def test_gen_cutoff_full_soc_neg_sell_with_pv_b_feasible(self) -> None:
|
||||
"""BA81: 100 % SoC + sell<0 + GEN cut-off — dříve ge==0 → Infeasible."""
|
||||
slots = [
|
||||
PlanningSlot(
|
||||
interval_start=datetime(2026, 5, 24, 9, 0, tzinfo=timezone.utc)
|
||||
+ timedelta(minutes=15 * i),
|
||||
buy_price=3.088,
|
||||
sell_price=-1.5,
|
||||
pv_a_forecast_w=8_000,
|
||||
pv_b_forecast_w=2_800,
|
||||
load_baseline_w=500,
|
||||
ev1_connected=False,
|
||||
ev2_connected=False,
|
||||
allow_charge=True,
|
||||
allow_discharge_export=False,
|
||||
charge_acquisition_buy_czk_kwh=3.61,
|
||||
is_daytime_pv_surplus_slot=True,
|
||||
safety_soc_target_wh=6_250.0,
|
||||
)
|
||||
for i in range(8)
|
||||
]
|
||||
battery = _battery(uc_wh=12_500.0, terminal_soc_value_factor=0.0)
|
||||
battery.soc_max_wh = 12_500.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 = True
|
||||
hp = SimpleNamespace(
|
||||
rated_heating_power_w=0,
|
||||
tuv_min_temp_c=0.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,
|
||||
deye_gen_microinverter_cutoff_enabled=True,
|
||||
)
|
||||
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,
|
||||
),
|
||||
]
|
||||
results, _ms, snap = solve_dispatch(
|
||||
slots,
|
||||
battery,
|
||||
hp,
|
||||
grid,
|
||||
[None, None],
|
||||
vehicles,
|
||||
12_500.0,
|
||||
55.0,
|
||||
operating_mode="AUTO",
|
||||
)
|
||||
self.assertEqual(snap.get("planner_build_tag"), "2026-05-24-ba81-gen-cutoff-v6")
|
||||
self.assertEqual(len(results), len(slots))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user