通过解决装箱问题,将加权任务平均分配给工人。这个包为用户提供了一个抽象来扩展
binpacker的Python项目详细描述
通用装箱问题解决程序。
Given a set of items with weight information and capacity of a bin, Binpacker determines which items can fit in the bin with that capacity and continues to pack all items in new bins in a way that it will utilize the space of each bin. In the other word, Binpacker can be used to determine what is the minimum number of bins we can use to pack all items with different weights.
要求
- python 3.4(已测试)
目标
这个库的最终目标是为 解决各种应用中的装箱问题。
代码示例
假设一个箱子的容量(11)和一个包含 不同的重量,我们想在 利用每个箱子的空间。
importtimefrombinpacker.binpackerimportBinpackerfrombinpacker.binpackerimportItempacker=Binpacker(11)packer.items=[Item('A',4),Item('B',1),Item('C',2),Item('D',6),Item('E',9),Item('F',3),Item('G',7),Item('H',2),Item('I',5)]j=0whileTrue:packer.pack_items()fori,xinenumerate(packer.bins):print('Bin ({}%) {}: {}'.format(x.utilization,i,[i.nameforiinx.get_items()]))print('----------------------------------')packer._items.append(Item('Z{}'.format(i),2))j+=1time.sleep(3)output:Bin(100.0%)0:['H','C','F','A']Bin(100.0%)1:['I','D']Bin(90.91%)2:['B','E']Bin(63.64%)3:['G']----------------------------------Bin(100.0%)0:['H','C','F','A']Bin(100.0%)1:['I','D']Bin(90.91%)2:['B','E']Bin(81.82%)3:['Z0','G']----------------------------------Bin(100.0%)0:['H','C','F','A']Bin(100.0%)1:['I','D']Bin(90.91%)2:['B','E']Bin(100.0%)3:['Z0','G','Z1']----------------------------------Bin(100.0%)0:['H','C','F','A']Bin(100.0%)1:['I','D']Bin(90.91%)2:['B','E']Bin(100.0%)3:['Z0','G','Z1']Bin(18.18%)4:['Z2']----------------------------------Bin(100.0%)0:['H','C','F','A']Bin(100.0%)1:['I','D']Bin(90.91%)2:['B','E']Bin(100.0%)3:['Z0','G','Z1']Bin(36.36%)4:['Z2','Z3']----------------------------------Bin(100.0%)0:['H','C','F','A']Bin(100.0%)1:['I','D']Bin(90.91%)2:['B','E']Bin(100.0%)3:['Z0','G','Z1']Bin(54.55%)4:['Z2','Z3','Z4']
- 注意(xxx%)是丰满度的百分比