dvdoug / BoxPacker

4D bin packing / knapsack problem solver
MIT License
612 stars 156 forks source link

$packedBoxes only contains one box #597

Closed eschiendorfer closed 7 months ago

eschiendorfer commented 10 months ago

Thanks for your great tool! It offers so much, but I believe there is a simple thing missing. I want to get ALL boxes, that fit all the items.

So I follow your example: https://boxpacker.io/en/3.x/getting-started.html#packing-a-set-of-items-into-a-given-set-of-box-types

But count($packedBoxes) always returns 1...

It's very simple to reproduce: Just add 2 boxes that work. The boxes only differ in height. The system will only return the smaller box. If you reduce the smaller box, so that it's no more fitting, the system suddenly returns the bigger box.

Maybe I am missing something? How to get both boxes?

I am on version 3.12.1 (as I am not yet on newest php version)

dvdoug commented 10 months ago

Hi @eschiendorfer

My first question to you would be why do you want to do that? Is it because smallest box isn't "best"? If so, there is a mechanism for choosing which box to use, see https://boxpacker.io/en/3.x/sortation.html#choosing-between-permutations

If you really do just want all the permutations, this is the commit that added the functionality to v4, you should be able to take the nested loops from packAllPermutations() and construct your own version.

https://github.com/dvdoug/BoxPacker/commit/6022b3d272fa33d3ba2b4984318dfa6a75430cc1

eschiendorfer commented 10 months ago

Hello @dvdoug Thanks a lot for the fast response. Yeah it's kind of "the smallest box isn't always the best/cheapest". That's why I thought it's best to just give the packer the options and he can still choses "the best one".