From 45a6377b601a6a25cade3f69d80b545ee73cef67 Mon Sep 17 00:00:00 2001 From: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com> Date: Sun, 15 Nov 2026 14:01:25 +0100 Subject: [PATCH] fix(genetic): keep a deadline from capping the DAILY appliance estimate The tail estimate queried its probe appliance with the configured deadline. A deadline inside the control horizon then left no start on the following days: with BEST_EFFORT the 48 h tail held one run and logged "deadline can not be met" twice per run, with STRICT it held no appliance load. The deadline only limits the run it was set for, so the probe leaves it out. Additional changes Test the tail load with a deadline inside the control horizon for both deadline policies Refs: #1495 Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 Assisted-by: Claude Code (claude-opus-5-5) --- .../optimization/genetic/genetic.py | 5 +- tests/test_geneticcompletetail.py | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/akkudoktoreos/optimization/genetic/genetic.py b/src/akkudoktoreos/optimization/genetic/genetic.py index 8c4ac081..c9ccc59f 100644 --- a/src/akkudoktoreos/optimization/genetic/genetic.py +++ b/src/akkudoktoreos/optimization/genetic/genetic.py @@ -1377,9 +1377,10 @@ class GeneticOptimization(OptimizationBase): # The configured appliance only spans the control horizon, so its # window logic cannot see the tail. Query a throwaway copy sized to # the estimated range instead; it shares the same parameters, so the - # time windows, earliest start and deadline bounds all still apply. + # time windows and the earliest start still apply. A deadline only + # limits the run it was set for and must not cap the following days. probe = HomeAppliance( - parameters=appliance.parameters, + parameters=appliance.parameters.model_copy(update={"deadline_datetime": None}), optimization_hours=self._genetic_cfg.horizon_hours, prediction_hours=end_slot, slot_duration_h=self.slot_duration_h, diff --git a/tests/test_geneticcompletetail.py b/tests/test_geneticcompletetail.py index cf707aab..eea3d776 100644 --- a/tests/test_geneticcompletetail.py +++ b/tests/test_geneticcompletetail.py @@ -5,6 +5,7 @@ from unittest.mock import patch import numpy as np import pandas as pd import pytest +from loguru import logger from akkudoktoreos.config.config import SettingsEOSDefaults from akkudoktoreos.core.coreabc import get_ems @@ -597,3 +598,60 @@ def test_daily_appliance_run_in_progress_counts_for_its_day_in_estimate(config_e expected_first_day = 0.0 if running else 3000.0 assert float(np.sum(first_day)) == pytest.approx(expected_first_day) assert float(np.sum(two_days)) == pytest.approx(expected_first_day + 3000.0) + + +@pytest.mark.parametrize("policy", ["BEST_EFFORT", "STRICT"]) +def test_daily_appliance_deadline_does_not_cap_tail(config_eos, policy): + """#1495: a deadline inside the control horizon does not limit the following days. + + The run starts 22:00, so the control horizon holds one night run before the + deadline and the 48 h tail two more nights. The tail must hold both, and + estimating it must not log a missed deadline. + """ + opt, params = setup_run(config_eos, start_hour=22, hours=72 + 22) + params.home_appliances = [ + HomeApplianceParameters.model_validate( + dict( + device_id="water_heater", + consumption_wh=3000, + duration_h=2, + num_cycles=1, + schedule_mode="DAILY", + deadline_datetime="2026-09-06T08:00:00", + deadline_policy=policy, + time_windows={ + "windows": [{"start_time": "00:00", "duration": "5 hours", "value": 0}] + }, + ) + ) + ] + + def choose(*args, **kwargs): + genome = opt.create_individual() + genome[:] = [0] * len(genome) + return genome, {} + + messages: list[str] = [] + sink = logger.add(lambda message: messages.append(str(message)), level="WARNING") + try: + with ( + patch.object(opt, "optimize", side_effect=choose), + patch( + "akkudoktoreos.optimization.genetic.genetic.build_tail_value_curve", + wraps=build_tail_value_curve, + ) as builder, + ): + opt.optimize_ems(params) + finally: + logger.remove(sink) + + tail_load = builder.call_args.kwargs["load_wh"] + slot0 = opt._slot0_datetime + tail_days = { + str(slot0.add(hours=opt.control_end_slot + index).date()) + for index, energy in enumerate(tail_load) + if energy > 0 + } + assert tail_days == {"2026-09-07", "2026-09-08"} + assert float(np.sum(tail_load)) == pytest.approx(6000) + assert not [message for message in messages if "can not be met" in message]