Skip to content

Commit

Permalink
explained lower bound algo for Dist From AVG objectives.py
Browse files Browse the repository at this point in the history
  • Loading branch information
8onlichtman authored May 5, 2024
1 parent 7c7aea7 commit a58bde2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions prtpy/objectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ def __str__(self) -> str:
return "minimize-the-distance-from-avg"
def lower_bound(self, sums:list, sum_of_remaining_items:float, are_sums_in_ascending_order:bool=False)->float:
"""
First we calculate the final avg including the remaining items.
We try to add values from the remaining sum to the bins that haven't reached the avg yet
(they don't contribute to our final difference because we only take the bins that are more than avg).
If at any point all bins are equal to avg then we just need to divide the remaining sum amongst all bins
and the residue will be given out to random bins (one each).
We calculate and return the difference.
>>> MinimizeDistAvg.lower_bound([10,20,30,40,50], sum_of_remaining_items=5)
28.0
>>> MinimizeDistAvg.lower_bound([10,20,30,40,50], sum_of_remaining_items=20)
Expand Down

0 comments on commit a58bde2

Please sign in to comment.