Skip to content

Commit

Permalink
Battery SoC = 0 > set Discharge randomply to 0/1. For longer periods …
Browse files Browse the repository at this point in the history
…of storage (#366)

* Battery SoC = 0 > hard Discharge Setting Off
  • Loading branch information
drbacke authored Jan 13, 2025
1 parent 9ad61f6 commit 10703bb
Show file tree
Hide file tree
Showing 3 changed files with 421 additions and 409 deletions.
58 changes: 35 additions & 23 deletions src/akkudoktoreos/optimization/genetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,29 +442,41 @@ def evaluate(
individual[:] = adjusted_individual

# New check: Activate discharge when battery SoC is 0
battery_soc_per_hour = np.array(
o.get("akku_soc_pro_stunde", [])
) # Example key for battery SoC

if battery_soc_per_hour is not None:
if battery_soc_per_hour is None or discharge_hours_bin is None:
raise ValueError("battery_soc_per_hour or discharge_hours_bin is None")
min_length = min(battery_soc_per_hour.size, discharge_hours_bin.size)
battery_soc_per_hour_tail = battery_soc_per_hour[-min_length:]
discharge_hours_bin_tail = discharge_hours_bin[-min_length:]
len_ac = len(self.config.optimization_ev_available_charge_rates_percent)

# Find hours where battery SoC is 0
zero_soc_mask = battery_soc_per_hour_tail == 0
discharge_hours_bin_tail[zero_soc_mask] = (
len_ac + 2
) # Activate discharge for these hours

# Merge the updated discharge_hours_bin back into the individual
adjusted_individual = self.merge_individual(
discharge_hours_bin, eautocharge_hours_index, washingstart_int
)
individual[:] = adjusted_individual
# battery_soc_per_hour = np.array(
# o.get("akku_soc_pro_stunde", [])
# ) # Example key for battery SoC

# if battery_soc_per_hour is not None:
# if battery_soc_per_hour is None or discharge_hours_bin is None:
# raise ValueError("battery_soc_per_hour or discharge_hours_bin is None")
# min_length = min(battery_soc_per_hour.size, discharge_hours_bin.size)
# battery_soc_per_hour_tail = battery_soc_per_hour[-min_length:]
# discharge_hours_bin_tail = discharge_hours_bin[-min_length:]
# len_ac = len(self.config.optimization_ev_available_charge_rates_percent)

# # # Find hours where battery SoC is 0
# # zero_soc_mask = battery_soc_per_hour_tail == 0
# # discharge_hours_bin_tail[zero_soc_mask] = (
# # len_ac + 2
# # ) # Activate discharge for these hours

# # When Battery SoC then set the Discharge randomly to 0 or 1. otherwise it's very unlikely to get a state where a battery can store energy for a longer time
# # Find hours where battery SoC is 0
# zero_soc_mask = battery_soc_per_hour_tail == 0
# # discharge_hours_bin_tail[zero_soc_mask] = (
# # len_ac + 2
# # ) # Activate discharge for these hours
# set_to_len_ac_plus_2 = np.random.rand() < 0.5 # True mit 50% Wahrscheinlichkeit

# # Werte setzen basierend auf der zufälligen Entscheidung
# value_to_set = len_ac + 2 if set_to_len_ac_plus_2 else 0
# discharge_hours_bin_tail[zero_soc_mask] = value_to_set

# # Merge the updated discharge_hours_bin back into the individual
# adjusted_individual = self.merge_individual(
# discharge_hours_bin, eautocharge_hours_index, washingstart_int
# )
# individual[:] = adjusted_individual

# More metrics
individual.extra_data = ( # type: ignore[attr-defined]
Expand Down
Loading

0 comments on commit 10703bb

Please sign in to comment.