Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. # bin packing algo (estimation)
  2. # since it is Np- Hard
  3. # for better methods (first fit and best fit) use self balancing trees
  4. # this one is Next fit
  5.  
  6. def bins_needed(item_weights, bin_capacity):
  7. remain= bin_capacity
  8. bins=0
  9. for i in item_weights:
  10. if i> bin_capacity:
  11. bins+=1
  12. remain= bin_capacity
  13. else:
  14. bin_capacity-= i
  15. return bins
  16.  
  17. wt= [2, 5, 4, 7, 1, 3, 8]
  18. cap= 10
  19. print(bins_needed(wt, cap))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement