Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rave, Fra's contribution #28

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
628155b
Upgrade original code
ravhello Oct 17, 2024
d178e27
Update Script.py
ravhello Oct 23, 2024
25f8608
Fixed examples
FrancescoDoti Nov 19, 2024
d097214
Name in Packer is now optional
FrancescoDoti Nov 19, 2024
712a266
Embellishment
ravhello Nov 19, 2024
0830fb9
Changed painter to fix ex 7
FrancescoDoti Nov 19, 2024
634faa2
Update example0.py
FrancescoDoti Nov 19, 2024
4bd5721
Merge branch 'rave' of https://github.com/ravhello/Insightfully-3D-bi…
FrancescoDoti Nov 19, 2024
bfd4ee3
rollback ex 7
ravhello Nov 19, 2024
ad20243
rollback ex 7
ravhello Nov 19, 2024
62022f2
Update example 7
FrancescoDoti Nov 19, 2024
01185ac
graphic update
ravhello Nov 19, 2024
c82c5bc
top face opacity update
ravhello Nov 19, 2024
8673274
Merge branch 'rave' of https://github.com/ravhello/Insightfully-3D-bi…
ravhello Nov 19, 2024
bbcef4f
Update Script.py
ravhello Nov 19, 2024
162312c
graphic improvement
ravhello Nov 20, 2024
ae0c84c
old main
ravhello Nov 20, 2024
3264215
fig.show removed, name check
ravhello Nov 20, 2024
0752bdb
efficiency on sorting
elmiranda00 Nov 20, 2024
ee49504
cylinder vis
ravhello Nov 20, 2024
f873859
Merge branch 'rave' of https://github.com/ravhello/Insightfully-3D-bi…
ravhello Nov 20, 2024
eb700cf
fixed logics
ravhello Nov 20, 2024
6420a40
top face proportional
ravhello Nov 20, 2024
7e15be6
stability+ precision update
ravhello Nov 21, 2024
beb097f
precision change
ravhello Nov 21, 2024
e8ea64c
Update example1.py
elmiranda00 Nov 26, 2024
d6e7636
ids and names for packers
ravhello Nov 27, 2024
3096618
Add example8.py for packing demonstration and enhance item/bin ID man…
ravhello Nov 27, 2024
675dc0b
Refactor binding packing logic to improve efficiency and enhance erro…
ravhello Nov 28, 2024
ea5d2d0
Add methods to pack all packers and plot bins separately
ravhello Nov 28, 2024
2a44138
Decimal improvements
ravhello Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Hsu Ruei-Chang (jerry800416)
Copyright (c) 2024 Riccardo Ravello

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 2 additions & 0 deletions Profiling.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd C:\Users\Riccardo Ravello\OneDrive - CentraleSupelec\Bureau\3D-bin-packing>snakeviz profilazione.prof
snakeviz profilazione.prof
594 changes: 594 additions & 0 deletions Script.py

Large diffs are not rendered by default.

41 changes: 18 additions & 23 deletions example0.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Evergreen Real Container (20ft Steel Dry Cargo Container)
# Unit cm/kg
box = Bin(
partno='example0',
bin_id='example0',
WHD=(589.8,243.8,259.1),
max_weight=28080,
corner=15,
Expand All @@ -27,12 +27,11 @@
# 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',
item_id='Dyson DC34 Animal',
typeof='cube',
WHD=(170, 82, 46),
weight=85.12,
level=1,
priority_level=1,
loadbear=100,
updown=True,
color='#FF0000')
Expand All @@ -42,12 +41,11 @@
# 1 pcs per case, 85 * 60 *60 (10)
for i in range(10):
packer.addItem(Item(
partno='wash{}'.format(str(i+1)),
name='wash',
item_id='washing machine',
typeof='cube',
WHD=(85, 60, 60),
weight=10,
level=1,
priority_level=1,
loadbear=100,
updown=True,
color='#FFFF37'
Expand All @@ -57,12 +55,11 @@
# one per box, 60 * 80 * 200 (80)
for i in range(5):
packer.addItem(Item(
partno='Cabinet{}'.format(str(i+1)),
name='cabint',
item_id='Cabinet',
typeof='cube',
WHD=(60, 80, 200),
weight=80,
level=1,
priority_level=1,
loadbear=100,
updown=True,
color='#842B00')
Expand All @@ -72,12 +69,11 @@
# one per box , 70 * 100 * 30 (20)
for i in range(10):
packer.addItem(Item(
partno='Server{}'.format(str(i+1)),
name='server',
item_id='Server',
typeof='cube',
WHD=(70, 100, 30),
weight=20,
level=1,
priority_level=1,
loadbear=100,
updown=True,
color='#0000E3')
Expand All @@ -88,7 +84,7 @@
packer.pack(
bigger_first=True,
distribute_items=False,
fix_point=False, # Try switching fix_point=True/False to compare the results
fix_point=True, # Try switching fix_point=True/False to compare the results
check_stable=False,
support_surface_ratio=0.75,
number_of_decimals=0
Expand All @@ -107,8 +103,8 @@

# '''
for item in box.items:
print("partno : ",item.partno)
print("type : ",item.name)
print("item_id : ",item.item_id)
print("type : ",item.item_name)
print("color : ",item.color)
print("position : ",item.position)
print("rotation type : ",item.rotation_type)
Expand All @@ -121,14 +117,14 @@
# '''
print("UNFITTED ITEMS:")
for item in box.unfitted_items:
print("partno : ",item.partno)
print("type : ",item.name)
print("item_id : ",item.item_id)
print("type : ",item.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)
unfitted_name += '{},'.format(item.item_id)
print("***************************************************")
print("***************************************************")
print('space utilization : {}%'.format(round(volume_t / float(volume) * 100 ,2)))
Expand All @@ -143,9 +139,8 @@
# draw results
painter = Painter(box)
fig = painter.plotBoxAndItems(
title=box.partno,
title=box.bin_id,
alpha=0.2,
write_num=True,
write_name=True,
fontsize=10
)
fig.show()
)
79 changes: 39 additions & 40 deletions example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
'''

# init packing function
packer = Packer()
# init bin
box = Bin('example1', (5.6875, 10.75, 15.0), 70.0,0,0)
packer = Packer(packer_id='Example Packer')
# init bin
box = Bin(WHD=(5.6875, 8, 10.0), max_weight=700.0, bin_id='example1')
packer.addBin(box)
# add item
packer.addItem(Item('50g [powder 1]', 'test','cube',(2, 2, 4), 1,1,100,True,'red'))
packer.addItem(Item('50g [powder 2]', 'test','cube',(2, 2, 4), 2,1,100,True,'blue'))
packer.addItem(Item('50g [powder 3]', 'test','cube',(2, 2, 4), 3,1,100,True,'gray'))
packer.addItem(Item('50g [powder 4]', 'test','cube',(2, 2, 4), 3,1,100,True,'orange'))
packer.addItem(Item('50g [powder 5]', 'test','cylinder',(2, 2, 4), 3,1,100,True,'lawngreen'))
packer.addItem(Item('50g [powder 6]', 'test','cylinder',(2, 2, 4), 3,1,100,True,'purple'))
packer.addItem(Item('50g [powder 7]', 'test','cylinder',(1, 1, 5), 3,1,100,True,'yellow'))
packer.addItem(Item('250g [powder 8]', 'test','cylinder',(4, 4, 2), 4,1,100,True,'pink'))
packer.addItem(Item('250g [powder 9]', 'test','cylinder',(4, 4, 2), 5,1,100,True,'brown'))
packer.addItem(Item('250g [powder 10]', 'test','cube',(4, 4, 2), 6,1,100,True,'cyan'))
packer.addItem(Item('250g [powder 11]', 'test','cylinder',(4, 4, 2), 7,1,100,True,'olive'))
packer.addItem(Item('250g [powder 12]', 'test','cylinder',(4, 4, 2), 8,1,100,True,'darkgreen'))
packer.addItem(Item('250g [powder 13]', 'test','cube',(4, 4, 2), 9,1,100,True,'orange'))
# add items
packer.addItem(Item(WHD=(2, 2, 4), weight=10, priority_level=1, updown=True, color='red', loadbear=7.5, item_id='10kg/7.5kg/Prio1', item_name='test', typeof='cube'))
packer.addItem(Item(WHD=(2, 2, 4), weight=8, priority_level=1, updown=True, color='blue', loadbear=7.5, item_id='8kg/7.5kg/Prio1', item_name='test', typeof='cube'))
packer.addItem(Item(WHD=(2, 2, 4), weight=8, priority_level=2, updown=True, color='gray', loadbear=4, item_id='8kg/4kg/Prio2', item_name='test', typeof='cube'))
packer.addItem(Item(WHD=(2, 2, 3), weight=3.5, priority_level=1, updown=True, color='orange', loadbear=2, item_id='3.5kg/2kg/Prio1', item_name='test', typeof='cube'))
packer.addItem(Item(WHD=(3, 2, 4), weight=9, priority_level=1, updown=True, color='lawngreen', loadbear=8, item_id='9kg/8kg/Prio1', item_name='test', typeof='cylinder'))
packer.addItem(Item(WHD=(3, 2, 4), weight=8, priority_level=2, updown=True, color='purple', loadbear=8, item_id='8kg/8kg/Prio2', item_name='test', typeof='cylinder'))
packer.addItem(Item(WHD=(3, 1, 5), weight=9, priority_level=1, updown=True, color='yellow', loadbear=8, item_id='9kg/8kg/Prio1', item_name='test', typeof='cylinder'))
packer.addItem(Item(WHD=(4, 4, 2), weight=3, priority_level=1, updown=True, color='pink', loadbear=2, item_id='3kg/2kg/Prio1', item_name='test', typeof='cylinder'))
packer.addItem(Item(WHD=(4, 4, 2), weight=3, priority_level=1, updown=True, color='brown', loadbear=2.5, item_id='3kg/2.5kg/Prio1', item_name='test', typeof='cylinder'))
packer.addItem(Item(WHD=(4, 4, 2), weight=11, priority_level=1, updown=True, color='cyan', loadbear=10, item_id='11kg/10kg/Prio1', item_name='test', typeof='cube'))
packer.addItem(Item(WHD=(2, 2, 2), weight=1.5, priority_level=1, updown=True, color='olive', loadbear=1.5, item_id='1.5kg/1.5kg/Prio1', item_name='test', typeof='cylinder'))
packer.addItem(Item(WHD=(2, 2, 1), weight=2, priority_level=1, updown=True, color='darkgreen', loadbear=2, item_id='2kg/2kg/Prio1', item_name='test', typeof='cylinder'))
packer.addItem(Item(WHD=(5, 2, 2), weight=2.5, priority_level=1, updown=True, color='orange', loadbear=1, item_id='2.5kg/1kg/Prio1', item_name='test', typeof='cube'))

# calculate packing
packer.pack(
Expand All @@ -48,41 +48,40 @@
volume_f = 0
unfitted_name = ''
for item in b.items:
print("partno : ",item.partno)
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))
print("item_id : ", item.item_id)
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 b.unfitted_items:
print("partno : ",item.partno)
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))
print("item_id : ", item.item_id)
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)
unfitted_name += '{},'.format(item.item_id)
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 : ",b.gravity)
print('space utilization : {}%'.format(round(volume_t / float(volume) * 100, 2)))
print('residual volume : ', float(volume) - volume_t)
print('unpack item : ', unfitted_name)
print('unpack item volume : ', volume_f)
print("gravity distribution : ", b.gravity)
stop = time.time()
print('used time : ',stop - start)
print('used time : ', stop - start)

# draw results
painter = Painter(b)
fig = painter.plotBoxAndItems(
title=b.partno,
title=b.bin_id,
alpha=0.2,
write_num=False,
fontsize=5
write_name=True,
fontsize=10
)
fig.show()
77 changes: 38 additions & 39 deletions example2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@
'''

# init packing function
packer = Packer()
packer = Packer(packer_id = 'Example Packer')
# init bin
box = Bin('example2',(30, 10, 15), 99,0,1)
box = Bin((30, 10, 15), 99, bin_id='example2', corner=0, put_type=1)
packer.addBin(box)
# add item
packer.addItem(Item('test1', 'test','cube',(9, 8, 7), 1, 1, 100, True,'red'))
packer.addItem(Item('test2', 'test','cube',(4, 25, 1), 1, 1, 100, True,'blue'))
packer.addItem(Item('test3', 'test','cube',(2, 13, 5), 1, 1, 100, True,'gray'))
packer.addItem(Item('test4', 'test','cube',(7, 5, 4), 1, 1, 100, True,'orange'))
packer.addItem(Item('test5', 'test','cube',(10, 5, 2), 1, 1, 100, True,'lawngreen'))
packer.addItem(Item('test6', 'test','cube',(6, 5, 2), 1, 1, 100, True,'purple'))
packer.addItem(Item('test7', 'test','cube',(5, 2, 9), 1, 1, 100, True,'yellow'))
packer.addItem(Item('test8', 'test','cube',(10, 8, 5), 1, 1, 100, True,'pink'))
packer.addItem(Item('test9', 'test','cube',(1, 3, 5), 1, 1, 100, True,'brown'))
packer.addItem(Item('test10', 'test','cube',(8, 4, 7), 1, 1, 100, True,'cyan'))
packer.addItem(Item('test11', 'test','cube',(2, 5, 3), 1, 1, 100, True,'olive'))
packer.addItem(Item('test12', 'test','cube',(1, 9, 2), 1, 1, 100, True,'darkgreen'))
packer.addItem(Item('test13', 'test','cube',(7, 5, 4), 1, 1, 100, True,'orange'))
packer.addItem(Item('test14', 'test','cube',(10, 2, 1), 1, 1, 100, True,'lawngreen'))
packer.addItem(Item('test15', 'test','cube',(3, 2, 4), 1, 1, 100, True,'purple'))
packer.addItem(Item('test16', 'test','cube',(5, 7, 8), 1, 1, 100, True,'yellow'))
packer.addItem(Item('test17', 'test','cube',(4, 8, 3), 1, 1, 100, True,'white'))
packer.addItem(Item('test18', 'test','cube',(2, 11, 5), 1, 1, 100, True,'brown'))
packer.addItem(Item('test19', 'test','cube',(8, 3, 5), 1, 1, 100, True,'cyan'))
packer.addItem(Item('test20', 'test','cube',(7, 4, 5), 1, 1, 100, True,'olive'))
packer.addItem(Item('test21', 'test','cube',(2, 4, 11), 1, 1, 100, True,'darkgreen'))
packer.addItem(Item('test22', 'test','cube',(1, 3, 4), 1, 1, 100, True,'orange'))
packer.addItem(Item('test23', 'test','cube',(10, 5, 2), 1, 1, 100, True,'lawngreen'))
packer.addItem(Item('test24', 'test','cube',(7, 4, 5), 1, 1, 100, True,'purple'))
packer.addItem(Item('test25', 'test','cube',(2, 10, 3), 1, 1, 100, True,'yellow'))
packer.addItem(Item('test26', 'test','cube',(3, 8, 1), 1, 1, 100, True,'pink'))
packer.addItem(Item('test27', 'test','cube',(7, 2, 5), 1, 1, 100, True,'brown'))
packer.addItem(Item('test28', 'test','cube',(8, 9, 5), 1, 1, 100, True,'cyan'))
packer.addItem(Item('test29', 'test','cube',(4, 5, 10), 1, 1, 100, True,'olive'))
packer.addItem(Item('test30', 'test','cube',(10, 10, 2), 1, 1, 100, True,'darkgreen'))
packer.addItem(Item((9, 8, 7), 1, 1, True, 'red', 100, 'test1', 'test', 'cube'))
packer.addItem(Item((4, 25, 1), 1, 1, True, 'blue', 100, 'test2', 'test', 'cube'))
packer.addItem(Item((2, 13, 5), 1, 1, True, 'gray', 100, 'test3', 'test', 'cube'))
packer.addItem(Item((7, 5, 4), 1, 1, True, 'orange', 100, 'test4', 'test', 'cube'))
packer.addItem(Item((10, 5, 2), 1, 1, True, 'lawngreen', 100, 'test5', 'test', 'cube'))
packer.addItem(Item((6, 5, 2), 1, 1, True, 'purple', 100, 'test6', 'test', 'cube'))
packer.addItem(Item((5, 2, 9), 1, 1, True, 'yellow', 100, 'test7', 'test', 'cube'))
packer.addItem(Item((10, 8, 5), 1, 1, True, 'pink', 100, 'test8', 'test', 'cube'))
packer.addItem(Item((1, 3, 5), 1, 1, True, 'brown', 100, 'test9', 'test', 'cube'))
packer.addItem(Item((8, 4, 7), 1, 1, True, 'cyan', 100, 'test10', 'test', 'cube'))
packer.addItem(Item((2, 5, 3), 1, 1, True, 'olive', 100, 'test11', 'test', 'cube'))
packer.addItem(Item((1, 9, 2), 1, 1, True, 'darkgreen', 100, 'test12', 'test', 'cube'))
packer.addItem(Item((7, 5, 4), 1, 1, True, 'orange', 100, 'test13', 'test', 'cube'))
packer.addItem(Item((10, 2, 1), 1, 1, True, 'lawngreen', 100, 'test14', 'test', 'cube'))
packer.addItem(Item((3, 2, 4), 1, 1, True, 'purple', 100, 'test15', 'test', 'cube'))
packer.addItem(Item((5, 7, 8), 1, 1, True, 'yellow', 100, 'test16', 'test', 'cube'))
packer.addItem(Item((4, 8, 3), 1, 1, True, 'white', 100, 'test17', 'test', 'cube'))
packer.addItem(Item((2, 11, 5), 1, 1, True, 'brown', 100, 'test18', 'test', 'cube'))
packer.addItem(Item((8, 3, 5), 1, 1, True, 'cyan', 100, 'test19', 'test', 'cube'))
packer.addItem(Item((7, 4, 5), 1, 1, True, 'olive', 100, 'test20', 'test', 'cube'))
packer.addItem(Item((2, 4, 11), 1, 1, True, 'darkgreen', 100, 'test21', 'test', 'cube'))
packer.addItem(Item((1, 3, 4), 1, 1, True, 'orange', 100, 'test22', 'test', 'cube'))
packer.addItem(Item((10, 5, 2), 1, 1, True, 'lawngreen', 100, 'test23', 'test', 'cube'))
packer.addItem(Item((7, 4, 5), 1, 1, True, 'purple', 100, 'test24', 'test', 'cube'))
packer.addItem(Item((2, 10, 3), 1, 1, True, 'yellow', 100, 'test25', 'test', 'cube'))
packer.addItem(Item((3, 8, 1), 1, 1, True, 'pink', 100, 'test26', 'test', 'cube'))
packer.addItem(Item((7, 2, 5), 1, 1, True, 'brown', 100, 'test27', 'test', 'cube'))
packer.addItem(Item((8, 9, 5), 1, 1, True, 'cyan', 100, 'test28', 'test', 'cube'))
packer.addItem(Item((4, 5, 10), 1, 1, True, 'olive', 100, 'test29', 'test', 'cube'))
packer.addItem(Item((10, 10, 2), 1, 1, True, 'darkgreen', 100, 'test30', 'test', 'cube'))

# calculate packing
packer.pack(
Expand All @@ -65,7 +65,7 @@
volume_f = 0
unfitted_name = ''
for item in b.items:
print("partno : ",item.partno)
print("item_id : ",item.item_id)
print("color : ",item.color)
print("position : ",item.position)
print("rotation type : ",item.rotation_type)
Expand All @@ -77,13 +77,13 @@
print("***************************************************")
print("UNFITTED ITEMS:")
for item in b.unfitted_items:
print("partno : ",item.partno)
print("item_id : ",item.item_id)
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)
unfitted_name += '{},'.format(item.item_id)
print("***************************************************")
print("***************************************************")
print('space utilization : {}%'.format(round(volume_t / float(volume) * 100 ,2)))
Expand All @@ -97,9 +97,8 @@
# draw results
painter = Painter(b)
fig = painter.plotBoxAndItems(
title=b.partno,
title=b.bin_id,
alpha=0.8,
write_num=False,
write_name=False,
fontsize=10
)
fig.show()
)
Loading