Created
March 27, 2017 14:03
-
-
Save rupalbarman/83dca02f252e314899b90b85b277d383 to your computer and use it in GitHub Desktop.
Simple Bin Packing Algorithm code which uses Next-fit technique
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # bin packing algo (estimation) | |
| # since it is Np- Hard | |
| # for better methods (first fit and best fit) use self balancing trees | |
| # this one is Next fit | |
| def bins_needed(item_weights, bin_capacity): | |
| remain= bin_capacity | |
| bins=0 | |
| for i in item_weights: | |
| if i> bin_capacity: | |
| bins+=1 | |
| remain= bin_capacity | |
| else: | |
| bin_capacity-= i | |
| return bins | |
| wt= [2, 5, 4, 7, 1, 3, 8] | |
| cap= 10 | |
| print(bins_needed(wt, cap)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment