jerry800416 / 3D-bin-packing

3D Bin Packing improvements based on https://github.com/enzoruiz/3dbinpacking
MIT License
158 stars 44 forks source link

problem of plotting Cylinder #5

Closed Westlife1002 closed 1 year ago

Westlife1002 commented 2 years ago

There are some problem of plotting cylinder in example5.py

Traceback (most recent call last):
  File "C:/Users/mike/Desktop/3DBP/3D-bin-packing-master/example5.py", line 71, in <module>
    painter.plotBoxAndItems()
  File "C:\Users\mike\Desktop\3DBP\3D-bin-packing-master\py3dbp\main.py", line 615, in plotBoxAndItems
    self._plotCylinder(axGlob, float(x), float(y), float(z), float(w),float(h),float(d),color=color,mode=2)
  File "C:\Users\mike\Desktop\3DBP\3D-bin-packing-master\py3dbp\main.py", line 596, in _plotCylinder
    ax.plot_surface(x_grid, y_grid, z_grid,shade=False,fc=color,ec='black',alpha=1,color=color)
  File "C:\Users\mike\AppData\Local\Programs\Python\Python36\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 1736, in plot_surface
    polyc = art3d.Poly3DCollection(polys, *args, **kwargs)
  File "C:\Users\mike\AppData\Local\Programs\Python\Python36\lib\site-packages\mpl_toolkits\mplot3d\art3d.py", line 518, in __init__
    PolyCollection.__init__(self, verts, *args, **kwargs)
  File "C:\Users\mike\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\collections.py", line 961, in __init__
    Collection.__init__(self, **kwargs)
  File "C:\Users\mike\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\collections.py", line 170, in __init__
    self.update(kwargs)
  File "C:\Users\mike\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\artist.py", line 888, in update
    for k, v in props.items()]
  File "C:\Users\mike\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\artist.py", line 888, in <listcomp>
    for k, v in props.items()]
  File "C:\Users\mike\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\artist.py", line 881, in _update_property
    raise AttributeError('Unknown property %s' % k)
AttributeError: Unknown property fc
jerry800416 commented 2 years ago

use Python 3.6 & pip install -r requirenments.txt

Westlife1002 commented 2 years ago

I am using Python 3.6.5. still got this issue

jerry800416 commented 2 years ago

I can't reproduce this error, can you provide me the version number of the installed package and the OS used?

Westlife1002 commented 2 years ago

I am using windows 10, Python 3.6.5. from above error log it's something wrong in main.py, specifically "_plotCylinder". I can run example 1-4 without any problem. for example 5 I think it's ploting Cylinder and this issue happened.

jerry800416 commented 2 years ago

I'm sorry that i can't reproduce this error, maybe you can provide more info . In my guess,the problem is with the matplotlib version,fc is the attribute in matplotlib 3.3.4, check your matplotlib version and re-execute. Let me know if this solves your problem ,tks

Westlife1002 commented 2 years ago

I checked, it's Version: 2.2.3. is this version not working well? I cannot upgrade it because of other version dependency. Could you please take a look at plotly 3D mesh library which produce nicer interactive 3D graph: https://plotly.com/python/3d-mesh/#mesh-cube If you can add such ploting capability of it that will be greate.

Westlife1002 commented 2 years ago

Another question, in your version of 3DBP, is the distribution function disabled? i.e. can we still input multiple boxes or containers to pack all items? it seems this version can only support one bin/container to calculate.

jerry800416 commented 2 years ago

I checked, it's Version: 2.2.3. is this version not working well? I cannot upgrade it because of other version dependency. Could you please take a look at plotly 3D mesh library which produce nicer interactive 3D graph: https://plotly.com/python/3d-mesh/#mesh-cube If you can add such ploting capability of it that will be greate.

There is currently no plan to add a new plot library, maybe you can try to use virtualenv to solve the matplotlib version problem.

Westlife1002 commented 2 years ago

OK, I will try. I have one more question. Does the model really consider how to put cylindar items with other cube items seriously, to ensure the way of loading them are realistically sensible? e.g. avoiding putting cube items on top of the cylindar items because it will fall down during transport. I saw in the main.py that only the drawing part distinguish the cylindar and cube items, which seems that before this procedure all items are actually treated as cube item for calculating the result? Please clarify this issue or any potential limitations in real business practice. thank you very much

jerry800416 commented 2 years ago

The upside-down setting of the cylinder item is invalid, so no scrolling issues will occur, because packer will ensure that the upside is flat, you can check main.py -- line 29 self.updown = updown if typeof == ' cube' else False.

Cylinder items use the diameter as W and H, so it is essentially the same as a cube, but note that W must be equal to H when adding a cylinder. ex. packer.addItem(Item(partno='Box-5' , name='test', typeof='cylinder', WHD=(1,1 , 5), weight=1, level=1,loadbear=100, updown=True, color='olive'))

Westlife1002 commented 2 years ago

so you mean the cylinder item can only be put upright and they cannot be laid down(lay flat)?

jerry800416 commented 2 years ago

In my case ,yes.

Westlife1002 commented 2 years ago

where can I remove the limitation? I prefer the model to determin if the cylinder item should be put upright or laid down. and if possible, how to add the constraint that any cube item cannot be put on top of a cylinder item. this will fit for majority of the scenario in real practice.

jerry800416 commented 2 years ago

Sorry,there is no way to remove the limitation. The cylinder only be upright, so the drawing function doesn't consider the situation of upside down.If the limitation is removed, it will cause an error in the drawing function.

Westlife1002 commented 2 years ago

Why does this model take so much time to compute a solution when the quanity of items is big. e.g. I have 3 types of boxes loading for a 40' container:

65*33*26 (252 cartons); 
84*42*33 (222 cartons);
 48*48*38 (270 cartons); 

it took nearly 10 minutes to reach a solution. why does it become dramatically slower when the number of items (boxes) increased?

moschd commented 2 years ago

@Westlife1002 Because each new item that is being evaluated to be placed inside the bin is being checked against all items already placed in the bin in order to determine if it is a valid position. This makes calculation time far from linear. For example, see the loop at line 148 in main.py.

Westlife1002 commented 2 years ago

@Westlife1002 Because each new item that is being evaluated to be placed inside the bin is being checked against all items already placed in the bin in order to determine if it is a valid position. This makes calculation time far from linear. For example, see the loop at line 148 in main.py.

do u have any workaround on this issue? apparently the computing time is too slow to be useful in this case.

moschd commented 2 years ago

There are definitely ways to improve calculation time, but incorporating these concepts into the current implementation are not rudimentary. I sadly will not have the spare time to contribute to this repository. If you are interested in an implementation that can support fast-paced high-volume logistic operations, you can let me know how to contact you and I might be able to help you.

Westlife1002 commented 1 year ago

@moschd hi Moshchd, this is very import issue, as in real world a lot of shipments come with small cartons to fill a container. Please let me know how to contact you. thank you for your help. @jerry800416 do you have any quick workaround? thanks

moschd commented 1 year ago

@Westlife1002 Hi, yes this is very true. Feel free to contact me on dennismosch@hotmail.com.

jerry800416 commented 1 year ago

@Westlife1002 If you need fast calculation, you need use algorithms such as GA , PSO or neural network. This is my goal to improve in the next stage, but I have not completed it yet , and it's not a free public project. If @moschd can help you, please contact him.

allenxu commented 1 year ago

Hi Jerry , I know it's closed, but I got some question here.

If we apply WHD to xyz, and cylinder can only be put in a upright manner. I think the diameter of cylinder should be W and D? I know it's working correctly in current version , where W and H stand for diameter. I still got this question, could you point out what's wrong with my thoughts? And if you think it's more convenient you can use Chinese cause I am from mainland.

Thanks

jerry800416 commented 1 year ago

Hi @allenxu : 如果直徑設置為W和D,那確實是可以讓圓柱體以傾倒的狀態打包,但是如果開放這個功能,則會有更多的延伸問題,比如說

  1. 圓柱體傾倒放置後,因頂部非平面,那是否可以在上面堆疊物品?
  2. 圓柱體傾倒放置後,是否有滾動的可能,那在圓柱體滾動的情況下,如何確保堆疊在上面的物品不會因此產生翻覆的狀況?

所以我傾向於在完善上述規則前,僅開放圓柱體以直立式打包

另外,目前圓柱體打包方式實際上還是和立方體一樣的模式,兩者的差別只在畫圖上而已,後續可優化的方式是以交叉堆疊方式打包(如下圖所示)

image