mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-04-19 08:55:15 +00:00
Optimierung Entladezustand Akku
This commit is contained in:
parent
de1143b984
commit
427570ccb2
@ -1,14 +1,26 @@
|
|||||||
|
import numpy as np
|
||||||
class PVAkku:
|
class PVAkku:
|
||||||
def __init__(self, kapazitaet_wh):
|
def __init__(self, kapazitaet_wh):
|
||||||
# Kapazität des Akkus in Wh
|
# Kapazität des Akkus in Wh
|
||||||
self.kapazitaet_wh = kapazitaet_wh
|
self.kapazitaet_wh = kapazitaet_wh
|
||||||
# Initialer Ladezustand des Akkus in Wh
|
# Initialer Ladezustand des Akkus in Wh
|
||||||
self.soc_wh = 0
|
self.soc_wh = 0
|
||||||
|
self.discharge_array = np.full(24, 1)
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self.soc_wh = 0
|
||||||
|
self.discharge_array = np.full(24, 1)
|
||||||
|
|
||||||
|
def set_discharge_per_hour(self, discharge_array):
|
||||||
|
assert(len(discharge_array) == 24)
|
||||||
|
self.discharge_array = discharge_array
|
||||||
|
|
||||||
def ladezustand_in_prozent(self):
|
def ladezustand_in_prozent(self):
|
||||||
return (self.soc_wh / self.kapazitaet_wh) * 100
|
return (self.soc_wh / self.kapazitaet_wh) * 100
|
||||||
|
|
||||||
def energie_abgeben(self, wh):
|
def energie_abgeben(self, wh, hour):
|
||||||
|
if self.discharge_array[hour] == 0:
|
||||||
|
return 0.0
|
||||||
if self.soc_wh >= wh:
|
if self.soc_wh >= wh:
|
||||||
self.soc_wh -= wh
|
self.soc_wh -= wh
|
||||||
return wh
|
return wh
|
||||||
|
@ -39,6 +39,12 @@ class EnergieManagementSystem:
|
|||||||
self.pv_prognose_wh = pv_prognose_wh
|
self.pv_prognose_wh = pv_prognose_wh
|
||||||
self.strompreis_cent_pro_wh = strompreis_cent_pro_wh # Strompreis in Cent pro Wh
|
self.strompreis_cent_pro_wh = strompreis_cent_pro_wh # Strompreis in Cent pro Wh
|
||||||
self.einspeiseverguetung_cent_pro_wh = einspeiseverguetung_cent_pro_wh # Einspeisevergütung in Cent pro Wh
|
self.einspeiseverguetung_cent_pro_wh = einspeiseverguetung_cent_pro_wh # Einspeisevergütung in Cent pro Wh
|
||||||
|
def set_akku_discharge_hours(self, ds):
|
||||||
|
self.akku.set_discharge_per_hour(ds)
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self.akku.reset()
|
||||||
|
|
||||||
def simuliere(self):
|
def simuliere(self):
|
||||||
eigenverbrauch_wh_pro_stunde = []
|
eigenverbrauch_wh_pro_stunde = []
|
||||||
netzeinspeisung_wh_pro_stunde = []
|
netzeinspeisung_wh_pro_stunde = []
|
||||||
@ -67,7 +73,7 @@ class EnergieManagementSystem:
|
|||||||
else:
|
else:
|
||||||
netzeinspeisung_wh_pro_stunde.append(0.0)
|
netzeinspeisung_wh_pro_stunde.append(0.0)
|
||||||
benötigte_energie = verbrauch - erzeugung
|
benötigte_energie = verbrauch - erzeugung
|
||||||
aus_akku = self.akku.energie_abgeben(benötigte_energie)
|
aus_akku = self.akku.energie_abgeben(benötigte_energie, stunde)
|
||||||
stündlicher_netzbezug_wh = benötigte_energie - aus_akku
|
stündlicher_netzbezug_wh = benötigte_energie - aus_akku
|
||||||
netzbezug_wh_pro_stunde.append(stündlicher_netzbezug_wh)
|
netzbezug_wh_pro_stunde.append(stündlicher_netzbezug_wh)
|
||||||
eigenverbrauch_wh_pro_stunde.append(erzeugung)
|
eigenverbrauch_wh_pro_stunde.append(erzeugung)
|
||||||
@ -86,7 +92,10 @@ class EnergieManagementSystem:
|
|||||||
'Kosten_Euro_pro_Stunde': kosten_euro_pro_stunde,
|
'Kosten_Euro_pro_Stunde': kosten_euro_pro_stunde,
|
||||||
'akku_soc_pro_stunde': akku_soc_pro_stunde,
|
'akku_soc_pro_stunde': akku_soc_pro_stunde,
|
||||||
'Einnahmen_Euro_pro_Stunde': einnahmen_euro_pro_stunde,
|
'Einnahmen_Euro_pro_Stunde': einnahmen_euro_pro_stunde,
|
||||||
'Gesamtkosten_Euro': gesamtkosten_euro
|
'Gesamtbilanz_Euro': gesamtkosten_euro,
|
||||||
|
'Gesamteinnahmen_Euro': sum(einnahmen_euro_pro_stunde),
|
||||||
|
'Gesamtkosten_Euro': sum(kosten_euro_pro_stunde)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# def simuliere(self):
|
# def simuliere(self):
|
||||||
|
@ -57,7 +57,12 @@ def visualisiere_ergebnisse(last, pv_forecast, strompreise, ergebnisse):
|
|||||||
# Zusammenfassende Finanzen
|
# Zusammenfassende Finanzen
|
||||||
plt.subplot(3, 2, 3)
|
plt.subplot(3, 2, 3)
|
||||||
gesamtkosten = ergebnisse['Gesamtkosten_Euro']
|
gesamtkosten = ergebnisse['Gesamtkosten_Euro']
|
||||||
plt.bar('Gesamtkosten', gesamtkosten, color='red' if gesamtkosten > 0 else 'green')
|
gesamteinnahmen = ergebnisse['Gesamteinnahmen_Euro']
|
||||||
|
gesamtbilanz = ergebnisse['Gesamtbilanz_Euro']
|
||||||
|
plt.bar('GesamtKosten', gesamtkosten, color='red' if gesamtkosten > 0 else 'green')
|
||||||
|
plt.bar('GesamtEinnahmen', gesamteinnahmen, color='red' if gesamtkosten > 0 else 'green')
|
||||||
|
plt.bar('GesamtBilanz', gesamtbilanz, color='red' if gesamtkosten > 0 else 'green')
|
||||||
|
|
||||||
plt.title('Gesamtkosten')
|
plt.title('Gesamtkosten')
|
||||||
plt.ylabel('Euro')
|
plt.ylabel('Euro')
|
||||||
|
|
||||||
@ -67,3 +72,4 @@ def visualisiere_ergebnisse(last, pv_forecast, strompreise, ergebnisse):
|
|||||||
|
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
68
test.py
68
test.py
@ -9,8 +9,9 @@ from modules.class_strompreis import *
|
|||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from modules.visualize import *
|
from modules.visualize import *
|
||||||
|
from deap import base, creator, tools, algorithms
|
||||||
|
import numpy as np
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
date = "2024-02-16"
|
date = "2024-02-16"
|
||||||
@ -18,7 +19,17 @@ akku_size = 1000 # Wh
|
|||||||
year_energy = 2000*1000 #Wh
|
year_energy = 2000*1000 #Wh
|
||||||
einspeiseverguetung_cent_pro_wh = np.full(24, 7/1000.0)
|
einspeiseverguetung_cent_pro_wh = np.full(24, 7/1000.0)
|
||||||
|
|
||||||
|
|
||||||
akku = PVAkku(akku_size)
|
akku = PVAkku(akku_size)
|
||||||
|
discharge_array = np.full(24,1)
|
||||||
|
# discharge_array[12] = 0
|
||||||
|
# discharge_array[13] = 0
|
||||||
|
# discharge_array[14] = 0
|
||||||
|
# discharge_array[15] = 0
|
||||||
|
# discharge_array[16] = 0
|
||||||
|
# discharge_array[17] = 0
|
||||||
|
# discharge_array[18] = 1
|
||||||
|
# akku.set_discharge_per_hour(discharge_array)
|
||||||
|
|
||||||
# Load Forecast
|
# Load Forecast
|
||||||
lf = LoadForecast(filepath=r'load_profiles.npz', year_energy=year_energy)
|
lf = LoadForecast(filepath=r'load_profiles.npz', year_energy=year_energy)
|
||||||
@ -40,7 +51,58 @@ specific_date_prices = price_forecast.get_prices_for_date(date)
|
|||||||
# EMS / Stromzähler Bilanz
|
# EMS / Stromzähler Bilanz
|
||||||
ems = EnergieManagementSystem(akku, specific_date_load, pv_forecast, specific_date_prices, einspeiseverguetung_cent_pro_wh)
|
ems = EnergieManagementSystem(akku, specific_date_load, pv_forecast, specific_date_prices, einspeiseverguetung_cent_pro_wh)
|
||||||
o = ems.simuliere()
|
o = ems.simuliere()
|
||||||
pprint(o)
|
pprint(o["Gesamtbilanz_Euro"])
|
||||||
|
|
||||||
|
|
||||||
|
# Optimierung
|
||||||
|
|
||||||
|
# Fitness-Funktion (muss Ihre EnergieManagementSystem-Logik integrieren)
|
||||||
|
def evaluate(individual):
|
||||||
|
# Hier müssen Sie Ihre Logik einbauen, um die Gesamtbilanz zu berechnen
|
||||||
|
# basierend auf dem gegebenen `individual` (discharge_array)
|
||||||
|
#akku.set_discharge_per_hour(individual)
|
||||||
|
ems.reset()
|
||||||
|
ems.set_akku_discharge_hours(individual)
|
||||||
|
o = ems.simuliere()
|
||||||
|
gesamtbilanz = o["Gesamtbilanz_Euro"]
|
||||||
|
#print(individual, " ",gesamtbilanz)
|
||||||
|
return (gesamtbilanz,)
|
||||||
|
|
||||||
|
# Werkzeug-Setup
|
||||||
|
creator.create("FitnessMin", base.Fitness, weights=(-1.0,))
|
||||||
|
creator.create("Individual", list, fitness=creator.FitnessMin)
|
||||||
|
|
||||||
|
toolbox = base.Toolbox()
|
||||||
|
toolbox.register("attr_bool", random.randint, 0, 1)
|
||||||
|
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_bool, 24)
|
||||||
|
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
|
||||||
|
|
||||||
|
toolbox.register("evaluate", evaluate)
|
||||||
|
toolbox.register("mate", tools.cxTwoPoint)
|
||||||
|
toolbox.register("mutate", tools.mutFlipBit, indpb=0.05)
|
||||||
|
toolbox.register("select", tools.selTournament, tournsize=3)
|
||||||
|
|
||||||
|
# Genetischer Algorithmus
|
||||||
|
def optimize():
|
||||||
|
population = toolbox.population(n=100)
|
||||||
|
hof = tools.HallOfFame(1)
|
||||||
|
|
||||||
|
stats = tools.Statistics(lambda ind: ind.fitness.values)
|
||||||
|
stats.register("avg", np.mean)
|
||||||
|
stats.register("min", np.min)
|
||||||
|
stats.register("max", np.max)
|
||||||
|
|
||||||
|
algorithms.eaSimple(population, toolbox, cxpb=0.5, mutpb=0.2, ngen=100,
|
||||||
|
stats=stats, halloffame=hof, verbose=True)
|
||||||
|
return hof[0]
|
||||||
|
|
||||||
|
best_solution = optimize()
|
||||||
|
print("Beste Lösung:", best_solution)
|
||||||
|
|
||||||
|
ems.set_akku_discharge_hours(best_solution)
|
||||||
|
o = ems.simuliere()
|
||||||
|
pprint(o["Gesamtbilanz_Euro"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
visualisiere_ergebnisse(specific_date_load, pv_forecast, specific_date_prices, o)
|
visualisiere_ergebnisse(specific_date_load, pv_forecast, specific_date_prices, o)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user