-
Notifications
You must be signed in to change notification settings - Fork 48
/
example0.py
151 lines (134 loc) · 4.11 KB
/
example0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from py3dbp import Packer, Bin, Item, Painter
import time
start = time.time()
'''
This example can be used to compare the fix_point function with and without the fix_point function.
'''
# init packing function
packer = Packer()
# Evergreen Real Container (20ft Steel Dry Cargo Container)
# Unit cm/kg
box = Bin(
partno='example0',
WHD=(589.8,243.8,259.1),
max_weight=28080,
corner=15,
put_type=0
)
packer.addBin(box)
# dyson DC34 (20.5 * 11.5 * 32.2 ,1.33kg)
# 64 pcs per case , 82 * 46 * 170 (85.12)
for i in range(5):
packer.addItem(Item(
partno='Dyson DC34 Animal{}'.format(str(i+1)),
name='Dyson',
typeof='cube',
WHD=(170, 82, 46),
weight=85.12,
level=1,
loadbear=100,
updown=True,
color='#FF0000')
)
# washing machine (85 * 60 *60 ,10 kG)
# 1 pcs per case, 85 * 60 *60 (10)
for i in range(10):
packer.addItem(Item(
partno='wash{}'.format(str(i+1)),
name='wash',
typeof='cube',
WHD=(85, 60, 60),
weight=10,
level=1,
loadbear=100,
updown=True,
color='#FFFF37'
))
# 42U standard cabinet (60 * 80 * 200 , 80 kg)
# one per box, 60 * 80 * 200 (80)
for i in range(5):
packer.addItem(Item(
partno='Cabinet{}'.format(str(i+1)),
name='cabint',
typeof='cube',
WHD=(60, 80, 200),
weight=80,
level=1,
loadbear=100,
updown=True,
color='#842B00')
)
# Server (70 * 100 * 30 , 20 kg)
# one per box , 70 * 100 * 30 (20)
for i in range(10):
packer.addItem(Item(
partno='Server{}'.format(str(i+1)),
name='server',
typeof='cube',
WHD=(70, 100, 30),
weight=20,
level=1,
loadbear=100,
updown=True,
color='#0000E3')
)
# calculate packing
packer.pack(
bigger_first=True,
distribute_items=False,
fix_point=False, # Try switching fix_point=True/False to compare the results
check_stable=False,
support_surface_ratio=0.75,
number_of_decimals=0
)
# print result
for box in packer.bins:
volume = box.width * box.height * box.depth
print(":::::::::::", box.string())
print("FITTED ITEMS:")
volume_t = 0
volume_f = 0
unfitted_name = ''
# '''
for item in box.items:
print("partno : ",item.partno)
print("type : ",item.name)
print("color : ",item.color)
print("position : ",item.position)
print("rotation type : ",item.rotation_type)
print("W*H*D : ",str(item.width) +'*'+ str(item.height) +'*'+ str(item.depth))
print("volume : ",float(item.width) * float(item.height) * float(item.depth))
print("weight : ",float(item.weight))
volume_t += float(item.width) * float(item.height) * float(item.depth)
print("***************************************************")
print("***************************************************")
# '''
print("UNFITTED ITEMS:")
for item in box.unfitted_items:
print("partno : ",item.partno)
print("type : ",item.name)
print("color : ",item.color)
print("W*H*D : ",str(item.width) +'*'+ str(item.height) +'*'+ str(item.depth))
print("volume : ",float(item.width) * float(item.height) * float(item.depth))
print("weight : ",float(item.weight))
volume_f += float(item.width) * float(item.height) * float(item.depth)
unfitted_name += '{},'.format(item.partno)
print("***************************************************")
print("***************************************************")
print('space utilization : {}%'.format(round(volume_t / float(volume) * 100 ,2)))
print('residual volumn : ', float(volume) - volume_t )
print('unpack item : ',unfitted_name)
print('unpack item volumn : ',volume_f)
print("gravity distribution : ",box.gravity)
# '''
stop = time.time()
print('used time : ',stop - start)
# draw results
painter = Painter(box)
fig = painter.plotBoxAndItems(
title=box.partno,
alpha=0.2,
write_num=True,
fontsize=10
)
fig.show()