From 85395076be60dead8aec26ac05211332142fe190 Mon Sep 17 00:00:00 2001 From: Andreas Date: Fri, 20 Dec 2024 17:07:57 +0100 Subject: [PATCH] Small penalty when EV 100% and charge >0 --- src/akkudoktoreos/optimization/genetic.py | 14 ++++++++------ src/akkudoktoreos/server/fastapi_server.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/akkudoktoreos/optimization/genetic.py b/src/akkudoktoreos/optimization/genetic.py index 590a18a..daea94d 100644 --- a/src/akkudoktoreos/optimization/genetic.py +++ b/src/akkudoktoreos/optimization/genetic.py @@ -7,7 +7,7 @@ from deap import algorithms, base, creator, tools from pydantic import BaseModel, Field, field_validator, model_validator from typing_extensions import Self from pathlib import Path - +import sys from akkudoktoreos.config import AppConfig from akkudoktoreos.devices.battery import ( EAutoParameters, @@ -344,6 +344,7 @@ class optimization_problem: ems.set_ev_charge_hours(np.array(eautocharge_hours_float)) else: ems.set_ev_charge_hours(np.full(self.prediction_hours, 0)) + return ems.simuliere(start_hour) def evaluate( @@ -370,11 +371,12 @@ class optimization_problem: # 0.01 for i in range(start_hour, self.prediction_hours) if discharge_hours_bin[i] == 0.0 # ) - # Penalty for not meeting the minimum SOC (State of Charge) requirement - # if parameters.eauto_min_soc_prozent - ems.eauto.ladezustand_in_prozent() <= 0.0 and self.optimize_ev: - # gesamtbilanz += sum( - # self.strafe for ladeleistung in eautocharge_hours_index if ladeleistung != 0.0 - # ) + # Penalty for charging EV, with battery full + len_soc = len(o["EAuto_SoC_pro_Stunde"]) + eautocharge_hours = np.array(eautocharge_hours_index) + relevant_indices = eautocharge_hours[-len_soc:] + mask = (o["EAuto_SoC_pro_Stunde"] == 100) & (relevant_indices != 0) + gesamtbilanz += np.sum(mask) * 0.01 individual.extra_data = ( # type: ignore[attr-defined] o["Gesamtbilanz_Euro"], diff --git a/src/akkudoktoreos/server/fastapi_server.py b/src/akkudoktoreos/server/fastapi_server.py index 8b7f9e5..c68967c 100755 --- a/src/akkudoktoreos/server/fastapi_server.py +++ b/src/akkudoktoreos/server/fastapi_server.py @@ -48,7 +48,7 @@ app = FastAPI( working_dir = get_working_dir() # copy config to working directory. Make this a CLI option later config = load_config(working_dir, True) -opt_class = optimization_problem(config, verbose=False) +opt_class = optimization_problem(config, verbose=True) server_dir = Path(__file__).parent.resolve()