Let's explain! The binpacking problem is a problem in which there are a random size item and multiple bins of the same size to pack it, and the number of bins is minimized.
There is oneDpack. with anaconda prompt
pip install oneDpack
How to use Enter the size of bin as cap and the size of what you want to put in items. Larger caps are very slow.
from oneDpack import*
cap=60
items=[2,4,5,2,7,4,7,3,7,3,7,43,8,2,4,13,6,4,3,2,4,7,9,10,40,23]
for i in packing(cap,items):
print(i)
print(sum(i))
output
[4, 13, 43]
60
[2, 3, 4, 4, 7, 40]
60
[2, 2, 3, 3, 4, 7, 7, 7, 7, 8, 10]
60
[2, 4, 5, 6, 9, 23]
49
There is a reckpack. with anaconda prompt
pip install reckpack
How to use Enter the size of bins and the vertical and horizontal sizes of cargo.
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from collections import*
from rectpack import newPacker
from pandas import*
from numpy import*
bins = [(50,50)]
cargo = [(15,20),(30,20),(15,20),(10,20),(20,14),(15,20),(11,20),(30,10)]
packer = newPacker()
#Set the container.
for i, b in enumerate(bins):
packer.add_bin(*b, bid=i)
#Set the box.
for i, r in enumerate(cargo):
packer.add_rect(*r, rid=i)
#Perform mass filling.
packer.pack()
for i, abin in enumerate(packer,1):
for r in abin:
print(r.x,r.y,r.width, r.height)
output
Outputs the x-coordinate from the lower left, the y-coordinate from the lower left, the length from left to right, and the length from bottom to top.
0 0 30 20
30 0 20 15
30 15 20 15
0 30 15 20
0 20 30 10
15 30 14 20
29 30 11 20
40 30 10 20
It will be like this when visualized.
%matplotlib inline
def draw_result(packer):
#Screen size
fig = plt.figure(figsize=(20,10))
for i, abin in enumerate(packer,1):
ax = fig.add_subplot(i, len(packer), 1, aspect="equal")
#Draw the container.
ax.add_patch(Rectangle((0,0), abin.width, abin.height, fc="none", ec="g", lw=2, zorder=10))
for r in abin:
#Draw a box.
ax.add_patch(Rectangle((r.x, r.y), r.width, r.height, fc="lightblue", ec="k"))
cx, cy = r.x + r.width / 2, r.y + r.height / 2
ax.text(cx, cy, r.rid, ha ="center",va="center", color="k", fontsize=14)
ax.relim()
ax.autoscale_view()
draw_result(packer)
We are currently searching, please let us know in the comments if you have any recommendations.
Recommended Posts