-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete greedy.py #22
Conversation
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: | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be an explanation to the algorithm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an explanation for the algorithm.
|
||
# Create a stack whose elements are a partition and the current depth. | ||
# Initially, it contains a single tuple: an empty partition with depth 0. | ||
first_bins = binner.new_bins(numbins) | ||
first_bins = binner.new_bins(numbins) | ||
if (relative_value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the code should be explained in the documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added explanation in the documentation.
if relative_value: | ||
fast_lower_bound = 0 | ||
for i in range (numbins): | ||
fast_lower_bound = fast_lower_bound + max((current_sums[i]-(max(relative_value) * sum(items) - relative_value[i] * sum(items)))-sum(items)*relative_value[i],0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The algorithm should be explained
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added explanation.
binner.remove_item_from_bin(best_bins, i, 0) | ||
|
||
for i in range(numbins): | ||
binner.sums(best_bins)[i] = math.floor(binner.sums(best_bins)[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are the sums rounded to integers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sums were supposed to be integers the whole time but with relative values - I needed to add a double value into each one of the bins in the beggining of the algorithm. This gave me issues, for example some values were something.00000000000001 so I just turned them into integers after removing the double value.
|
||
|
||
if (relative_value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code should be explained
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added explanation.
Added MinimizeTheDistanceFromAvg objective to objectives.py and to complete_greedy.py