Skip to content

Commit e2f903d

Browse files
committed
Fix sorting of inverters
The inverters were considered as sorted to have the largest exclusion bounds first, but since they were passed as a set, there is not ordering guarantees. We now sort them to ensure we are allocating the excess power to inverters with more capacity first. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent c5ff250 commit e2f903d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/frequenz/sdk/microgrid/_power_distributing/_distribution_algorithm/_battery_distribution_algorithm.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,12 @@ def _distribute_multi_inverter_pairs(
609609
else:
610610
remaining_power = power.power
611611

612-
# Inverters are sorted by largest excl bound first
613-
for inverter_id in inverter_ids:
612+
# Sort inverters to have the largest exclusion bounds first
613+
sorted_inverter_ids = sorted(
614+
inverter_ids, key=lambda inv_id: excl_bounds[inv_id], reverse=True
615+
)
616+
617+
for inverter_id in sorted_inverter_ids:
614618
if (
615619
not is_close_to_zero(remaining_power)
616620
and excl_bounds[inverter_id] <= remaining_power

0 commit comments

Comments
 (0)