mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-04-19 08:55:15 +00:00
English translation EMS
This commit is contained in:
parent
9edc2d20d3
commit
35142fafbd
@ -385,7 +385,7 @@ class optimization_problem:
|
|||||||
else:
|
else:
|
||||||
ems.set_ev_charge_hours(np.full(self.prediction_hours, 0))
|
ems.set_ev_charge_hours(np.full(self.prediction_hours, 0))
|
||||||
|
|
||||||
return ems.simuliere(start_hour)
|
return ems.simulate(start_hour)
|
||||||
|
|
||||||
def evaluate(
|
def evaluate(
|
||||||
self,
|
self,
|
||||||
@ -439,21 +439,23 @@ class optimization_problem:
|
|||||||
individual.extra_data = ( # type: ignore[attr-defined]
|
individual.extra_data = ( # type: ignore[attr-defined]
|
||||||
o["Gesamtbilanz_Euro"],
|
o["Gesamtbilanz_Euro"],
|
||||||
o["Gesamt_Verluste"],
|
o["Gesamt_Verluste"],
|
||||||
parameters.eauto.min_soc_prozent - ems.eauto.ladezustand_in_prozent()
|
parameters.eauto.min_soc_prozent - ems.ev.ladezustand_in_prozent()
|
||||||
if parameters.eauto and ems.eauto
|
if parameters.eauto and ems.ev
|
||||||
else 0,
|
else 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Adjust total balance with battery value and penalties for unmet SOC
|
# Adjust total balance with battery value and penalties for unmet SOC
|
||||||
restwert_akku = ems.akku.aktueller_energieinhalt() * parameters.ems.preis_euro_pro_wh_akku
|
restwert_akku = (
|
||||||
|
ems.battery.aktueller_energieinhalt() * parameters.ems.preis_euro_pro_wh_akku
|
||||||
|
)
|
||||||
gesamtbilanz += -restwert_akku
|
gesamtbilanz += -restwert_akku
|
||||||
|
|
||||||
if self.optimize_ev:
|
if self.optimize_ev:
|
||||||
gesamtbilanz += max(
|
gesamtbilanz += max(
|
||||||
0,
|
0,
|
||||||
(
|
(
|
||||||
parameters.eauto.min_soc_prozent - ems.eauto.ladezustand_in_prozent()
|
parameters.eauto.min_soc_prozent - ems.ev.ladezustand_in_prozent()
|
||||||
if parameters.eauto and ems.eauto
|
if parameters.eauto and ems.ev
|
||||||
else 0
|
else 0
|
||||||
)
|
)
|
||||||
* self.strafe,
|
* self.strafe,
|
||||||
@ -558,8 +560,8 @@ class optimization_problem:
|
|||||||
ems = EnergieManagementSystem(
|
ems = EnergieManagementSystem(
|
||||||
self._config.eos,
|
self._config.eos,
|
||||||
parameters.ems,
|
parameters.ems,
|
||||||
wechselrichter=wr,
|
inverter=wr,
|
||||||
eauto=eauto,
|
ev=eauto,
|
||||||
home_appliance=dishwasher,
|
home_appliance=dishwasher,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -615,7 +617,7 @@ class optimization_problem:
|
|||||||
"discharge_allowed": discharge,
|
"discharge_allowed": discharge,
|
||||||
"eautocharge_hours_float": eautocharge_hours_float,
|
"eautocharge_hours_float": eautocharge_hours_float,
|
||||||
"result": SimulationResult(**o),
|
"result": SimulationResult(**o),
|
||||||
"eauto_obj": ems.eauto,
|
"eauto_obj": ems.ev,
|
||||||
"start_solution": start_solution,
|
"start_solution": start_solution,
|
||||||
"washingstart": washingstart_int,
|
"washingstart": washingstart_int,
|
||||||
}
|
}
|
||||||
|
@ -104,28 +104,30 @@ class EnergieManagementSystem:
|
|||||||
self,
|
self,
|
||||||
config: EOSConfig,
|
config: EOSConfig,
|
||||||
parameters: EnergieManagementSystemParameters,
|
parameters: EnergieManagementSystemParameters,
|
||||||
wechselrichter: Wechselrichter,
|
inverter: Wechselrichter,
|
||||||
eauto: Optional[PVAkku] = None,
|
ev: Optional[PVAkku] = None,
|
||||||
home_appliance: Optional[HomeAppliance] = None,
|
home_appliance: Optional[HomeAppliance] = None,
|
||||||
):
|
):
|
||||||
self.akku = wechselrichter.akku
|
self.battery = inverter.akku
|
||||||
self.gesamtlast = np.array(parameters.gesamtlast, float)
|
self.load_energy_array = np.array(parameters.gesamtlast, float)
|
||||||
self.pv_prognose_wh = np.array(parameters.pv_prognose_wh, float)
|
self.pv_prediction_wh = np.array(parameters.pv_prognose_wh, float)
|
||||||
self.strompreis_euro_pro_wh = np.array(parameters.strompreis_euro_pro_wh, float)
|
self.elect_price_hourly = np.array(parameters.strompreis_euro_pro_wh, float)
|
||||||
self.einspeiseverguetung_euro_pro_wh_arr = (
|
self.elect_revenue_per_hour_arr = (
|
||||||
parameters.einspeiseverguetung_euro_pro_wh
|
parameters.einspeiseverguetung_euro_pro_wh
|
||||||
if isinstance(parameters.einspeiseverguetung_euro_pro_wh, list)
|
if isinstance(parameters.einspeiseverguetung_euro_pro_wh, list)
|
||||||
else np.full(len(self.gesamtlast), parameters.einspeiseverguetung_euro_pro_wh, float)
|
else np.full(
|
||||||
|
len(self.load_energy_array), parameters.einspeiseverguetung_euro_pro_wh, float
|
||||||
)
|
)
|
||||||
self.eauto = eauto
|
)
|
||||||
|
self.ev = ev
|
||||||
self.home_appliance = home_appliance
|
self.home_appliance = home_appliance
|
||||||
self.wechselrichter = wechselrichter
|
self.inverter = inverter
|
||||||
self.ac_charge_hours = np.full(config.prediction_hours, 0)
|
self.ac_charge_hours = np.full(config.prediction_hours, 0)
|
||||||
self.dc_charge_hours = np.full(config.prediction_hours, 1)
|
self.dc_charge_hours = np.full(config.prediction_hours, 1)
|
||||||
self.ev_charge_hours = np.full(config.prediction_hours, 0)
|
self.ev_charge_hours = np.full(config.prediction_hours, 0)
|
||||||
|
|
||||||
def set_akku_discharge_hours(self, ds: np.ndarray) -> None:
|
def set_akku_discharge_hours(self, ds: np.ndarray) -> None:
|
||||||
self.akku.set_discharge_per_hour(ds)
|
self.battery.set_discharge_per_hour(ds)
|
||||||
|
|
||||||
def set_akku_ac_charge_hours(self, ds: np.ndarray) -> None:
|
def set_akku_ac_charge_hours(self, ds: np.ndarray) -> None:
|
||||||
self.ac_charge_hours = ds
|
self.ac_charge_hours = ds
|
||||||
@ -141,28 +143,27 @@ class EnergieManagementSystem:
|
|||||||
self.home_appliance.set_starting_time(start_hour, global_start_hour=global_start_hour)
|
self.home_appliance.set_starting_time(start_hour, global_start_hour=global_start_hour)
|
||||||
|
|
||||||
def reset(self) -> None:
|
def reset(self) -> None:
|
||||||
if self.eauto:
|
if self.ev:
|
||||||
self.eauto.reset()
|
self.ev.reset()
|
||||||
self.akku.reset()
|
self.battery.reset()
|
||||||
|
|
||||||
def simuliere_ab_jetzt(self) -> dict[str, Any]:
|
def simulate_start_now(self) -> dict[str, Any]:
|
||||||
jetzt = datetime.now()
|
start_hour = datetime.now().hour
|
||||||
start_stunde = jetzt.hour
|
return self.simulate(start_hour)
|
||||||
return self.simuliere(start_stunde)
|
|
||||||
|
|
||||||
def simuliere(self, start_hour: int) -> dict[str, Any]:
|
def simulate(self, start_hour: int) -> dict[str, Any]:
|
||||||
"""hour.
|
"""hour.
|
||||||
|
|
||||||
akku_soc_pro_stunde begin of the hour, initial hour state!
|
akku_soc_pro_stunde begin of the hour, initial hour state!
|
||||||
last_wh_pro_stunde integral of last hour (end state)
|
last_wh_pro_stunde integral of last hour (end state)
|
||||||
"""
|
"""
|
||||||
lastkurve_wh = self.gesamtlast
|
load_energy_array = self.load_energy_array
|
||||||
assert (
|
assert (
|
||||||
len(lastkurve_wh) == len(self.pv_prognose_wh) == len(self.strompreis_euro_pro_wh)
|
len(load_energy_array) == len(self.pv_prediction_wh) == len(self.elect_price_hourly)
|
||||||
), f"Array sizes do not match: Load Curve = {len(lastkurve_wh)}, PV Forecast = {len(self.pv_prognose_wh)}, Electricity Price = {len(self.strompreis_euro_pro_wh)}"
|
), f"Array sizes do not match: Load Curve = {len(load_energy_array)}, PV Forecast = {len(self.pv_prediction_wh)}, Electricity Price = {len(self.elect_price_hourly)}"
|
||||||
|
|
||||||
# Optimized total hours calculation
|
# Optimized total hours calculation
|
||||||
end_hour = len(lastkurve_wh)
|
end_hour = len(load_energy_array)
|
||||||
total_hours = end_hour - start_hour
|
total_hours = end_hour - start_hour
|
||||||
|
|
||||||
# Pre-allocate arrays for the results, optimized for speed
|
# Pre-allocate arrays for the results, optimized for speed
|
||||||
@ -178,21 +179,21 @@ class EnergieManagementSystem:
|
|||||||
electricity_price_per_hour = np.full((total_hours), np.nan)
|
electricity_price_per_hour = np.full((total_hours), np.nan)
|
||||||
|
|
||||||
# Set initial state
|
# Set initial state
|
||||||
soc_per_hour[0] = self.akku.ladezustand_in_prozent()
|
soc_per_hour[0] = self.battery.ladezustand_in_prozent()
|
||||||
if self.eauto:
|
if self.ev:
|
||||||
soc_ev_per_hour[0] = self.eauto.ladezustand_in_prozent()
|
soc_ev_per_hour[0] = self.ev.ladezustand_in_prozent()
|
||||||
|
|
||||||
# All States
|
# All States
|
||||||
for hour in range(start_hour, end_hour):
|
for hour in range(start_hour, end_hour):
|
||||||
hour_since_now = hour - start_hour
|
hour_since_now = hour - start_hour
|
||||||
|
|
||||||
# save begin states
|
# save begin states
|
||||||
soc_per_hour[hour_since_now] = self.akku.ladezustand_in_prozent()
|
soc_per_hour[hour_since_now] = self.battery.ladezustand_in_prozent()
|
||||||
if self.eauto:
|
if self.ev:
|
||||||
soc_ev_per_hour[hour_since_now] = self.eauto.ladezustand_in_prozent()
|
soc_ev_per_hour[hour_since_now] = self.ev.ladezustand_in_prozent()
|
||||||
|
|
||||||
# Accumulate loads and PV generation
|
# Accumulate loads and PV generation
|
||||||
consumption = self.gesamtlast[hour]
|
consumption = self.load_energy_array[hour]
|
||||||
losses_wh_per_hour[hour_since_now] = 0.0
|
losses_wh_per_hour[hour_since_now] = 0.0
|
||||||
if self.home_appliance:
|
if self.home_appliance:
|
||||||
ha_load = self.home_appliance.get_load_for_hour(hour)
|
ha_load = self.home_appliance.get_load_for_hour(hour)
|
||||||
@ -200,24 +201,24 @@ class EnergieManagementSystem:
|
|||||||
home_appliance_wh_per_hour[hour_since_now] = ha_load
|
home_appliance_wh_per_hour[hour_since_now] = ha_load
|
||||||
|
|
||||||
# E-Auto handling
|
# E-Auto handling
|
||||||
if self.eauto and self.ev_charge_hours[hour] > 0:
|
if self.ev and self.ev_charge_hours[hour] > 0:
|
||||||
loaded_energy_ev, verluste_eauto = self.eauto.energie_laden(
|
loaded_energy_ev, verluste_eauto = self.ev.energie_laden(
|
||||||
None, hour, relative_power=self.ev_charge_hours[hour]
|
None, hour, relative_power=self.ev_charge_hours[hour]
|
||||||
)
|
)
|
||||||
consumption += loaded_energy_ev
|
consumption += loaded_energy_ev
|
||||||
losses_wh_per_hour[hour_since_now] += verluste_eauto
|
losses_wh_per_hour[hour_since_now] += verluste_eauto
|
||||||
|
|
||||||
# Process inverter logic
|
# Process inverter logic
|
||||||
energy_produced = self.pv_prognose_wh[hour]
|
energy_produced = self.pv_prediction_wh[hour]
|
||||||
self.akku.set_charge_allowed_for_hour(self.dc_charge_hours[hour], hour)
|
self.battery.set_charge_allowed_for_hour(self.dc_charge_hours[hour], hour)
|
||||||
energy_feedin_grid_actual, energy_consumption_grid_actual, losses, eigenverbrauch = (
|
energy_feedin_grid_actual, energy_consumption_grid_actual, losses, eigenverbrauch = (
|
||||||
self.wechselrichter.energie_verarbeiten(energy_produced, consumption, hour)
|
self.inverter.energie_verarbeiten(energy_produced, consumption, hour)
|
||||||
)
|
)
|
||||||
|
|
||||||
# AC PV Battery Charge
|
# AC PV Battery Charge
|
||||||
if self.ac_charge_hours[hour] > 0.0:
|
if self.ac_charge_hours[hour] > 0.0:
|
||||||
self.akku.set_charge_allowed_for_hour(1, hour)
|
self.battery.set_charge_allowed_for_hour(1, hour)
|
||||||
battery_charged_energy_actual, battery_losses_actual = self.akku.energie_laden(
|
battery_charged_energy_actual, battery_losses_actual = self.battery.energie_laden(
|
||||||
None, hour, relative_power=self.ac_charge_hours[hour]
|
None, hour, relative_power=self.ac_charge_hours[hour]
|
||||||
)
|
)
|
||||||
# print(stunde, " ", geladene_menge, " ",self.ac_charge_hours[stunde]," ",self.akku.ladezustand_in_prozent())
|
# print(stunde, " ", geladene_menge, " ",self.ac_charge_hours[stunde]," ",self.akku.ladezustand_in_prozent())
|
||||||
@ -231,13 +232,13 @@ class EnergieManagementSystem:
|
|||||||
consumption_energy_per_hour[hour_since_now] = energy_consumption_grid_actual
|
consumption_energy_per_hour[hour_since_now] = energy_consumption_grid_actual
|
||||||
losses_wh_per_hour[hour_since_now] += losses
|
losses_wh_per_hour[hour_since_now] += losses
|
||||||
loads_energy_per_hour[hour_since_now] = consumption
|
loads_energy_per_hour[hour_since_now] = consumption
|
||||||
electricity_price_per_hour[hour_since_now] = self.strompreis_euro_pro_wh[hour]
|
electricity_price_per_hour[hour_since_now] = self.elect_price_hourly[hour]
|
||||||
# Financial calculations
|
# Financial calculations
|
||||||
costs_per_hour[hour_since_now] = (
|
costs_per_hour[hour_since_now] = (
|
||||||
energy_consumption_grid_actual * self.strompreis_euro_pro_wh[hour]
|
energy_consumption_grid_actual * self.elect_price_hourly[hour]
|
||||||
)
|
)
|
||||||
revenue_per_hour[hour_since_now] = (
|
revenue_per_hour[hour_since_now] = (
|
||||||
energy_feedin_grid_actual * self.einspeiseverguetung_euro_pro_wh_arr[hour]
|
energy_feedin_grid_actual * self.elect_revenue_per_hour_arr[hour]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Total cost and return
|
# Total cost and return
|
||||||
|
@ -230,8 +230,8 @@ def create_ems_instance(tmp_config: AppConfig) -> EnergieManagementSystem:
|
|||||||
preis_euro_pro_wh_akku=preis_euro_pro_wh_akku,
|
preis_euro_pro_wh_akku=preis_euro_pro_wh_akku,
|
||||||
gesamtlast=gesamtlast,
|
gesamtlast=gesamtlast,
|
||||||
),
|
),
|
||||||
wechselrichter=wechselrichter,
|
inverter=wechselrichter,
|
||||||
eauto=eauto,
|
ev=eauto,
|
||||||
home_appliance=home_appliance,
|
home_appliance=home_appliance,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ def test_simulation(create_ems_instance):
|
|||||||
|
|
||||||
# Simulate starting from hour 1 (this value can be adjusted)
|
# Simulate starting from hour 1 (this value can be adjusted)
|
||||||
|
|
||||||
result = ems.simuliere(start_hour=start_hour)
|
result = ems.simulate(start_hour=start_hour)
|
||||||
|
|
||||||
# visualisiere_ergebnisse(
|
# visualisiere_ergebnisse(
|
||||||
# ems.gesamtlast,
|
# ems.gesamtlast,
|
||||||
|
@ -134,8 +134,8 @@ def create_ems_instance(tmp_config: AppConfig) -> EnergieManagementSystem:
|
|||||||
preis_euro_pro_wh_akku=0,
|
preis_euro_pro_wh_akku=0,
|
||||||
gesamtlast=gesamtlast,
|
gesamtlast=gesamtlast,
|
||||||
),
|
),
|
||||||
wechselrichter=wechselrichter,
|
inverter=wechselrichter,
|
||||||
eauto=eauto,
|
ev=eauto,
|
||||||
home_appliance=home_appliance,
|
home_appliance=home_appliance,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ def test_simulation(create_ems_instance):
|
|||||||
ems = create_ems_instance
|
ems = create_ems_instance
|
||||||
|
|
||||||
# Simulate starting from hour 0 (this value can be adjusted)
|
# Simulate starting from hour 0 (this value can be adjusted)
|
||||||
result = ems.simuliere(start_hour=start_hour)
|
result = ems.simulate(start_hour=start_hour)
|
||||||
|
|
||||||
# --- Pls do not remove! ---
|
# --- Pls do not remove! ---
|
||||||
# visualisiere_ergebnisse(
|
# visualisiere_ergebnisse(
|
||||||
|
@ -62,8 +62,8 @@ def test_optimize(
|
|||||||
start_hour = 10
|
start_hour = 10
|
||||||
|
|
||||||
# Activate with pytest --full-run
|
# Activate with pytest --full-run
|
||||||
# if ngen > 10 and not is_full_run:
|
if ngen > 10 and not is_full_run:
|
||||||
# pytest.skip()
|
pytest.skip()
|
||||||
|
|
||||||
visualize_filename = str((DIR_TESTDATA / f"new_{fn_out}").with_suffix(".pdf"))
|
visualize_filename = str((DIR_TESTDATA / f"new_{fn_out}").with_suffix(".pdf"))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user