-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
Added Branch And Bound algorithm to solve 0-1 Knapsack Problem #4566
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
Added Branch And Bound algorithm to solve 0-1 Knapsack Problem #4566
Conversation
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
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.
well done
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.
Great work
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@algorithms-keeper review-all |
As 0/1 Knapsack is about maximizing the total value, we cannot directly use the LC Branch and Bound technique to solve this. Instead, we convert this into a minimization problem by taking negative of the given values. | ||
Follow the steps below to solve the problem: | ||
|
||
1. Sort the items based on their value/weight(V/W) ratio. |
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.
It'd be helpful if we make it `V` and `W`. Same for all other variables like minLB -> `minLB` -> minLB
|
||
## Tests | ||
|
||
To be completed. |
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 think you've completed?
""" | ||
We are planning for a picnic. | ||
There are some items we would like to carry. | ||
Our knapsack is only able to carry 15 pounds of items. | ||
The items are given with some ratings from 1 to 10 to indicates how strongly we want to include the particular item in knapsack for the picnic. | ||
Once the item is included in the knapsack, the same item cannot be carried again. | ||
|
||
There are total of 6 items as follows: | ||
1. Ant Repellent,1,2 | ||
2. Blanket,4,3 | ||
3. Brownies,3,10 | ||
4. Frisbee,1,6 | ||
5. Salad,5,4 | ||
6. Watermelon,10,10 | ||
|
||
Calculate the maximum rating and total weight that the knapsack can take. | ||
""" |
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.
Or we can put these in README, making the code itself "self-contained"
def __init__(self, name: str, weight: float, rating: float) -> None: | ||
self._name = name | ||
self._weight = weight | ||
self._rating = rating |
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.
rating
means value
I guess? See if we can align it with the definition in README.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
In preparation for that denial-of-service attack that is Hacktoberfest, I am closing all pull requests that do not have passing tests. |
Describe your change:
Added Branch And Bound Algorithm to solve 0-1 Knapsack Problem
Checklist:
Fixes: #{$ISSUE_NO}
.