Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement