mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-12-14 07:46:18 +00:00
Optimierung Entladezustand Akku
This commit is contained in:
68
test.py
68
test.py
@@ -9,8 +9,9 @@ from modules.class_strompreis import *
|
||||
from pprint import pprint
|
||||
import matplotlib.pyplot as plt
|
||||
from modules.visualize import *
|
||||
|
||||
|
||||
from deap import base, creator, tools, algorithms
|
||||
import numpy as np
|
||||
import random
|
||||
|
||||
|
||||
date = "2024-02-16"
|
||||
@@ -18,7 +19,17 @@ akku_size = 1000 # Wh
|
||||
year_energy = 2000*1000 #Wh
|
||||
einspeiseverguetung_cent_pro_wh = np.full(24, 7/1000.0)
|
||||
|
||||
|
||||
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
|
||||
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 = EnergieManagementSystem(akku, specific_date_load, pv_forecast, specific_date_prices, einspeiseverguetung_cent_pro_wh)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user