enzoruiz / 3dbinpacking

A python library for 3D Bin Packing
MIT License
352 stars 88 forks source link

Return multiple solutions, or evaluate optimal according to cost_factor(s) #9

Open gamesguru opened 4 years ago

gamesguru commented 4 years ago

Thanks for v1.0 and v1.1.

Now I'm just curious, suppose there are multiple (good?) ways to pack the bins with items.. how does it choose the first solution? Is there a mode to see set of all solutions, or a way to pass a cost factor per bin?

Best, gg

enzoruiz commented 4 years ago

Hi @gamesguru Currently in the last version (1.1) and according the Item Distribution, the library tries to put items sequentially (first sorting bins and items from big to small or viceversa and then one by one trying to fit in each bin) and not using criterias like cost, to find multiple solutions and then choose the lowest cost of a bin to pack certain items. Can you give an example of how certain criteria, such as cost or others, could be used to package?, maybe we can find a new functionality.

Greetings!

gamesguru commented 4 years ago

Sure, let's say you are packing into fixed-rate shipping boxes. Perhaps two objects would fit into two small boxes, or one medium box, and the two small boxes may actually be cheaper. In another case, two medium boxes are more expensive than one large box. So I don't know the program would choose correctly in these two opposite situations, but I'm sure we could fix it easily.

I would be of the opinion it's best to leave the library modular, not to include any "cost function" option, but just to return all solutions and then to let the user evaluate them according to his or her needs. Alternatively the user can just request the top solution returned and let the stock evaluator make a primitive decision.

gamesguru commented 4 years ago

i am a bit confused by the solution to this

from py3dbp.main import Bin, Item, Packer
packer = Packer()

packer.add_bin(Bin('usps first-class envelope', 38.1, 30.48, 1.905, 368.875))
packer.add_bin(Bin('usps priority small-box', 21.9075, 13.6525, 4.1275, 1816.0))
packer.add_bin(Bin('usps priority medium-box-1', 27.94, 21.59, 13.97, 5448.0))
packer.add_bin(Bin('usps priority medium-box-2', 34.6075, 30.1625, 8.5725, 5448.0))
packer.add_bin(Bin('usps priority large-box-1', 30.48, 30.48, 13.97, 8172.0))
packer.add_bin(Bin('usps priority large-box-2', 60.16625, 29.845, 7.62, 8172.0))

packer.add_item(Item('250g [powder]', 15.0, 10.0, 2.5, 250))
packer.add_item(Item('250g [powder]', 15.0, 10.0, 2.5, 250))
packer.add_item(Item('50g [lotion]', 5.0, 5.0, 5.0, 50))
packer.add_item(Item('250g [lotion]', 9.0, 9.0, 8.0, 250))

packer.pack()

is it trying to solve for each bin separately, showing unfitted_items for each? I am not setting distribute_items.

It seems like the products should be able to fit in one box only as a possible solution. Why is it considering the first class envelop at all in the solution? Thanks

enzoruiz commented 4 years ago

Hi @gamesguru!

Regarding the first thing you mentioned, not necessarily adding one more parameter for the cost, perhaps dynamically sending constraints on the bins and items, as well as the maximum weight, quantity of items, maximum volume, etc. I will be thinking of some solution.

And the second one, by default the library tries to place all the items in each box created (from smallest to largest) and the reason is because the projects on which this library was based also did. But as you have seen since the first version was released so far, some improvements have been made and will continue to be made.

Sorry for the delay in reply Greetings!