Skip to content
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

Merged
merged 12 commits into from
May 15, 2024
Merged

Complete greedy.py #22

merged 12 commits into from
May 15, 2024

Conversation

8onlichtman
Copy link
Contributor

Added MinimizeTheDistanceFromAvg objective to objectives.py and to complete_greedy.py

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:
"""
Copy link
Collaborator

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

Copy link
Contributor Author

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):
Copy link
Collaborator

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

Copy link
Contributor Author

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)
Copy link
Collaborator

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

Copy link
Contributor Author

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])
Copy link
Collaborator

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?

Copy link
Contributor Author

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):
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added explanation.

@erelsgl erelsgl merged commit 54dc223 into coin-or:main May 15, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants