mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-06-28 00:46:53 +00:00
Violinenplot zur Optimierung / Zielfunktionalen
Worst / Best Case im Vergleich (bei Erfüllung der Nebenbedingungen)
This commit is contained in:
parent
be5a99f86a
commit
b037b6dcfc
@ -110,16 +110,17 @@ class optimization_problem:
|
|||||||
final_soc = ems.eauto.ladezustand_in_prozent() # Nimmt den SoC am Ende des Optimierungszeitraums
|
final_soc = ems.eauto.ladezustand_in_prozent() # Nimmt den SoC am Ende des Optimierungszeitraums
|
||||||
|
|
||||||
|
|
||||||
|
eauto_roi = max(0,(parameter['eauto_min_soc']-ems.eauto.ladezustand_in_prozent()) )
|
||||||
|
|
||||||
|
individual.extra_data = (o["Gesamtbilanz_Euro"],o["Gesamt_Verluste"], eauto_roi )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
strafe = 0.0
|
strafe = 0.0
|
||||||
if worst_case:
|
strafe = max(0,(parameter['eauto_min_soc']-ems.eauto.ladezustand_in_prozent()) * self.strafe )
|
||||||
strafe = abs(parameter['eauto_min_soc']-ems.eauto.ladezustand_in_prozent()) * self.strafe
|
gesamtbilanz += strafe
|
||||||
gesamtbilanz += strafe
|
gesamtbilanz += o["Gesamt_Verluste"]/1000.0
|
||||||
|
|
||||||
gesamtbilanz -= o["Gesamt_Verluste"]/1000.0
|
|
||||||
else:
|
|
||||||
strafe = max(0,(parameter['eauto_min_soc']-ems.eauto.ladezustand_in_prozent()) * self.strafe )
|
|
||||||
gesamtbilanz += strafe
|
|
||||||
gesamtbilanz += o["Gesamt_Verluste"]/1000.0
|
|
||||||
return (gesamtbilanz,)
|
return (gesamtbilanz,)
|
||||||
|
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ class optimization_problem:
|
|||||||
|
|
||||||
# Genetischer Algorithmus
|
# Genetischer Algorithmus
|
||||||
def optimize(self,start_solution=None):
|
def optimize(self,start_solution=None):
|
||||||
population = self.toolbox.population(n=100)
|
population = self.toolbox.population(n=300)
|
||||||
hof = tools.HallOfFame(1)
|
hof = tools.HallOfFame(1)
|
||||||
|
|
||||||
stats = tools.Statistics(lambda ind: ind.fitness.values)
|
stats = tools.Statistics(lambda ind: ind.fitness.values)
|
||||||
@ -141,9 +142,19 @@ class optimization_problem:
|
|||||||
if start_solution is not None and start_solution != -1:
|
if start_solution is not None and start_solution != -1:
|
||||||
population.insert(0, creator.Individual(start_solution))
|
population.insert(0, creator.Individual(start_solution))
|
||||||
|
|
||||||
#algorithms.eaMuPlusLambda(population, self.toolbox, 100, 200, cxpb=0.3, mutpb=0.3, ngen=500, stats=stats, halloffame=hof, verbose=True)
|
#algorithms.eaMuPlusLambda(population, self.toolbox, 100, 200, cxpb=0.4, mutpb=0.5, ngen=500, stats=stats, halloffame=hof, verbose=True)
|
||||||
algorithms.eaSimple(population, self.toolbox, cxpb=0.8, mutpb=0.8, ngen=400, stats=stats, halloffame=hof, verbose=True)
|
algorithms.eaSimple(population, self.toolbox, cxpb=0.4, mutpb=0.4, ngen=400, stats=stats, halloffame=hof, verbose=True)
|
||||||
return hof[0]
|
|
||||||
|
member = {"bilanz":[],"verluste":[],"nebenbedingung":[]}
|
||||||
|
for ind in population:
|
||||||
|
if hasattr(ind, 'extra_data'):
|
||||||
|
extra_value1, extra_value2,extra_value3 = ind.extra_data
|
||||||
|
member["bilanz"].append(extra_value1)
|
||||||
|
member["verluste"].append(extra_value2)
|
||||||
|
member["nebenbedingung"].append(extra_value3)
|
||||||
|
|
||||||
|
|
||||||
|
return hof[0], member
|
||||||
|
|
||||||
|
|
||||||
def optimierung_ems(self,parameter=None, start_hour=None,worst_case=False):
|
def optimierung_ems(self,parameter=None, start_hour=None,worst_case=False):
|
||||||
@ -240,7 +251,7 @@ class optimization_problem:
|
|||||||
return self.evaluate(individual, ems, parameter,start_hour,worst_case)
|
return self.evaluate(individual, ems, parameter,start_hour,worst_case)
|
||||||
|
|
||||||
self.toolbox.register("evaluate", evaluate_wrapper)
|
self.toolbox.register("evaluate", evaluate_wrapper)
|
||||||
start_solution = self.optimize(start_params)
|
start_solution, extra_data = self.optimize(start_params)
|
||||||
best_solution = start_solution
|
best_solution = start_solution
|
||||||
o = self.evaluate_inner(best_solution, ems,start_hour)
|
o = self.evaluate_inner(best_solution, ems,start_hour)
|
||||||
eauto = ems.eauto.to_dict()
|
eauto = ems.eauto.to_dict()
|
||||||
@ -256,13 +267,8 @@ class optimization_problem:
|
|||||||
|
|
||||||
|
|
||||||
print(o)
|
print(o)
|
||||||
if worst_case:
|
visualisiere_ergebnisse(gesamtlast, pv_forecast, specific_date_prices, o,best_solution[0::2],best_solution[1::2] , temperature_forecast, start_hour, self.prediction_hours,einspeiseverguetung_euro_pro_wh,extra_data=extra_data)
|
||||||
visualisiere_ergebnisse(gesamtlast, pv_forecast, specific_date_prices, o,best_solution[0::2],best_solution[1::2] , temperature_forecast, start_hour, self.prediction_hours,einspeiseverguetung_euro_pro_wh,filename="visualisierungsergebnisse_worst.pdf")
|
os.system("scp visualisierungsergebnisse.pdf andreas@192.168.1.135:")
|
||||||
os.system("scp visualisierungsergebnisse_worst.pdf andreas@192.168.1.135:")
|
|
||||||
else:
|
|
||||||
visualisiere_ergebnisse(gesamtlast, pv_forecast, specific_date_prices, o,best_solution[0::2],best_solution[1::2] , temperature_forecast, start_hour, self.prediction_hours,einspeiseverguetung_euro_pro_wh)
|
|
||||||
|
|
||||||
os.system("scp visualisierungsergebnisse.pdf andreas@192.168.1.135:")
|
|
||||||
|
|
||||||
#print(eauto)
|
#print(eauto)
|
||||||
return {"discharge_hours_bin":discharge_hours_bin, "eautocharge_hours_float":eautocharge_hours_float ,"result":o ,"eauto_obj":eauto,"start_solution":best_solution,"spuelstart":spuelstart_int}
|
return {"discharge_hours_bin":discharge_hours_bin, "eautocharge_hours_float":eautocharge_hours_float ,"result":o ,"eauto_obj":eauto,"start_solution":best_solution,"spuelstart":spuelstart_int}
|
||||||
|
@ -9,7 +9,7 @@ from matplotlib.backends.backend_pdf import PdfPages
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def visualisiere_ergebnisse(gesamtlast, pv_forecast, strompreise, ergebnisse, discharge_hours, laden_moeglich, temperature, start_hour, prediction_hours,einspeiseverguetung_euro_pro_wh, filename="visualisierungsergebnisse.pdf"):
|
def visualisiere_ergebnisse(gesamtlast, pv_forecast, strompreise, ergebnisse, discharge_hours, laden_moeglich, temperature, start_hour, prediction_hours,einspeiseverguetung_euro_pro_wh, filename="visualisierungsergebnisse.pdf", extra_data=None):
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
# 24h
|
# 24h
|
||||||
@ -118,6 +118,7 @@ def visualisiere_ergebnisse(gesamtlast, pv_forecast, strompreise, ergebnisse, d
|
|||||||
ax1 = plt.subplot(3, 2, 3)
|
ax1 = plt.subplot(3, 2, 3)
|
||||||
for hour, value in enumerate(discharge_hours):
|
for hour, value in enumerate(discharge_hours):
|
||||||
#if value == 1:
|
#if value == 1:
|
||||||
|
print(hour)
|
||||||
ax1.axvspan(hour, hour+1, color='red',ymax=value, alpha=0.3, label='Entlademöglichkeit' if hour == 0 else "")
|
ax1.axvspan(hour, hour+1, color='red',ymax=value, alpha=0.3, label='Entlademöglichkeit' if hour == 0 else "")
|
||||||
for hour, value in enumerate(laden_moeglich):
|
for hour, value in enumerate(laden_moeglich):
|
||||||
#if value == 1:
|
#if value == 1:
|
||||||
@ -168,6 +169,58 @@ def visualisiere_ergebnisse(gesamtlast, pv_forecast, strompreise, ergebnisse, d
|
|||||||
plt.close() # Schließt die Figure
|
plt.close() # Schließt die Figure
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
plt.figure(figsize=(14, 10))
|
||||||
|
plt.subplot(1, 2, 1)
|
||||||
|
f1 = np.array(extra_data["verluste"])
|
||||||
|
f2 = np.array(extra_data["bilanz"])
|
||||||
|
n1 = np.array(extra_data["nebenbedingung"])
|
||||||
|
scatter = plt.scatter(f1, f2, c=n1, cmap='viridis')
|
||||||
|
|
||||||
|
# Farblegende hinzufügen
|
||||||
|
plt.colorbar(scatter, label='Nebenbedingung')
|
||||||
|
|
||||||
|
pdf.savefig() # Speichert die komplette Figure im PDF
|
||||||
|
plt.close() # Schließt die Figure
|
||||||
|
|
||||||
|
|
||||||
|
plt.figure(figsize=(14, 10))
|
||||||
|
filtered_verluste = np.array([v for v, n in zip(extra_data["verluste"], extra_data["nebenbedingung"]) if n < 0.01])
|
||||||
|
filtered_bilanz = np.array([b for b, n in zip(extra_data["bilanz"], extra_data["nebenbedingung"]) if n< 0.01])
|
||||||
|
|
||||||
|
beste_verluste = min(filtered_verluste)
|
||||||
|
schlechteste_verluste = max(filtered_verluste)
|
||||||
|
beste_bilanz = min(filtered_bilanz)
|
||||||
|
schlechteste_bilanz = max(filtered_bilanz)
|
||||||
|
|
||||||
|
data = [filtered_verluste, filtered_bilanz]
|
||||||
|
labels = ['Verluste', 'Bilanz']
|
||||||
|
# Plot-Erstellung
|
||||||
|
fig, axs = plt.subplots(1, 2, figsize=(10, 6), sharey=False) # Zwei Subplots, getrennte y-Achsen
|
||||||
|
|
||||||
|
# Erster Boxplot für Verluste
|
||||||
|
#axs[0].boxplot(data[0])
|
||||||
|
axs[0].violinplot(data[0],
|
||||||
|
showmeans=True,
|
||||||
|
showmedians=True)
|
||||||
|
axs[0].set_title('Verluste')
|
||||||
|
axs[0].set_xticklabels(['Verluste'])
|
||||||
|
|
||||||
|
# Zweiter Boxplot für Bilanz
|
||||||
|
axs[1].violinplot(data[1],
|
||||||
|
showmeans=True,
|
||||||
|
showmedians=True)
|
||||||
|
axs[1].set_title('Bilanz')
|
||||||
|
axs[1].set_xticklabels(['Bilanz'])
|
||||||
|
|
||||||
|
# Feinabstimmung
|
||||||
|
plt.tight_layout()
|
||||||
|
|
||||||
|
|
||||||
|
pdf.savefig() # Speichert den aktuellen Figure-State im PDF
|
||||||
|
plt.close()
|
||||||
|
|
||||||
# plt.figure(figsize=(14, 10))
|
# plt.figure(figsize=(14, 10))
|
||||||
# # Kosten und Einnahmen pro Stunde
|
# # Kosten und Einnahmen pro Stunde
|
||||||
# plt.subplot(1, 2, 1)
|
# plt.subplot(1, 2, 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user