Close to equal Bin packing algoritm js

  Kiến thức lập trình

I have array of random numbers from 1 to 100
for ex.

let arr = [10, 5, 32, 10, 1, 25, 29]

And 5 bins with numbers, some of them already partially filled, and numbers there cant be removed.

let bin1 = [23,8,1]
let bin2 = []
let bin3 = [5, 11]
let bin4 = [33]
let bin5 = []

bins have maximum capacity = 50.

I also know numbers CANT be spread execly equal(or the chances of this outcome is really slim).
But i need some logic to spread them to bins as close to equal as posible.

So the expected result will look like :

bin1 = [23, 8, 1, 5]     //38
bin2 = [32, 10]          //42
bin3 = [5, 11, 25]       //41
bin4 = [33, 1]           //34
bin5 = [29, 10]          //39

Does sombody already solve this or at least tips on how to do it?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT