janet-19 / 3d-bin-packing-problem Goto Github PK
View Code? Open in Web Editor NEWA python model of 3D Bin Packing problem
A python model of 3D Bin Packing problem
def can_hold_item_with_rotation(self, item, pivot):
"""Evaluate whether one item can be placed into bin with all optional orientations.
Args:
item: any item in item list.
pivot: an (x, y, z) coordinate, the back-lower-left corner of the item will be placed at the pivot.
Returns:
a list containing all optional orientations. If not, return an empty list.
"""
fit = False
valid_item_position = [0, 0, 0]
item.position = pivot
rotation_type_list = []
for i in range(0, len(RotationType.ALL)):
item.rotation_type = i
dimension = item.get_dimension()
if (
pivot[0] + dimension[0] <= self.length and # x-axis
pivot[1] + dimension[1] <= self.width and # y-axis
pivot[2] + dimension[2] <= self.height # z-axis
):
fit = True
for current_item_in_bin in self.items:
if intersect(current_item_in_bin, item):
fit = False
item.position = [0, 0, 0]
break
if fit:
if self.get_total_weight() + item.weight > self.capacity: # estimate whether bin reaches its capacity
fit = False
item.position = [0, 0, 0]
continue
else:
rotation_type_list.append(item.rotation_type)
else:
continue
return rotation_type_list
There is an error in the above function while it is looping through rotations checking for fitment. If a later rotation is found to not fit, either do to intersection or weight, the items position is 0'ed. This resets the item to the origin instead of it's pivot despite previous rotations that do work for the given pivot location. Simply not setting the position to 0,0,0 preserves the pivot location and the algorithm works correctly. There was some thought given to this given the unused valid_item_position variable I suspect.
Hi, I'm surprised how you improved enzoruiz`s package. It's great work! But I find out some issue.. I trying to put 9 items in one box:
packer.add_bin(Bin('small-envelope', 35, 50, 40, 1))
packer.add_item(Item('item_1', 10, 7, 18, 0))
packer.add_item(Item('item_2', 10, 7, 18, 0))
packer.add_item(Item('item_3', 5, 6, 10, 0))
packer.add_item(Item('item_4', 5, 6, 10, 0))
packer.add_item(Item('item_5', 5, 6, 10, 0))
packer.add_item(Item('item_6', 20, 50, 12, 0))
packer.add_item(Item('item_7', 20, 50, 12, 0))
packer.add_item(Item('item_8', 20, 50, 12, 0))
packer.add_item(Item('item_9', 20, 50, 12, 0))
but items 'item_3', 'item_4', 'item_5' always putting at one place [0,0,0] :
::::::::::: small-envelope(35x50x40, max_weight:1) vol(70000) item_number(9) filling_ratio(1)
FITTED ITEMS:
====> item_6(20x50x12, weight: 0) pos([0, 0, 0]) rt(0) vol(12000)
====> item_7(20x50x12, weight: 0) pos([0, 0, Decimal('12')]) rt(2) vol(12000)
====> item_8(20x50x12, weight: 0) pos([Decimal('20'), 0, 0]) rt(2) vol(12000)
====> item_9(20x50x12, weight: 0) pos([Decimal('20'), 0, Decimal('20')]) rt(2) vol(12000)
====> item_1(10x7x18, weight: 0) pos([0, 0, Decimal('32')]) rt(1) vol(1260)
====> item_2(10x7x18, weight: 0) pos([0, Decimal('10'), Decimal('32')]) rt(1) vol(1260)
====> item_3(5x6x10, weight: 0) pos([0, 0, 0]) rt(0) vol(300)
====> item_4(5x6x10, weight: 0) pos([0, 0, 0]) rt(0) vol(300)
====> item_5(5x6x10, weight: 0) pos([0, 0, 0]) rt(0) vol(300)
I hope you resolve that issue:)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.