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

Algorithm seems inefficient for tight packing #264

Open
MarcoWel opened this issue Oct 25, 2021 · 6 comments
Open

Algorithm seems inefficient for tight packing #264

MarcoWel opened this issue Oct 25, 2021 · 6 comments

Comments

@MarcoWel
Copy link

MarcoWel commented Oct 25, 2021

Hi,
First of all a big thank you to @dvdoug for this excellent and easy-to-use library. We use it to automatically find the right box for a given set of products.

However, there are regular cases where Packer() just does not seem to work well. One particular case is the following:

$packer = new Packer();
$packer->addBox(new TestBox('Small', 160, 130,  70, 0, 0, 0, 0, 100000));
$packer->addBox(new TestBox('Large', 250, 175, 100, 0, 0, 0, 0, 100000));
$rot = TestItem::ROTATION_BEST_FIT; // TestItem::ROTATION_KEEP_FLAT;
$packer->addItem(new TestItem('Item 1', 105,  70,  14, 0, $rot), 1);
$packer->addItem(new TestItem('Item 2', 152, 101,   5, 0, $rot), 1);        
$packer->addItem(new TestItem('Item 3',  80,  70,  50, 0, $rot), 1);
$packer->addItem(new TestItem('Item 4',  97,  71,  28, 0, $rot), 1);
$packer->addItem(new TestItem('Item 5',  95,  70,  28, 0, $rot), 1); 
$packedBoxes = $packer->pack();

This leads to Packer() suggesting the large box although everything would fit into the small box as well.
image

Just providing the small box with ROTATION_BEST_FIT leads to Item 2 (yellow) not fitting in the package:
image

Just providing the small box with ROTATION_KEEP_FLAT would actually work just fine, but somehow it does not fit Item 5 (dark red) anymore, although there is clearly enough space left:
image

Any ideas?

Best regards,
Marco

@Elyos59
Copy link

Elyos59 commented Oct 26, 2021

Hi!

Same for me : #261 (comment)

And if I add 1 unit to my length, width, depth box the result is completely different :(

@dvdoug
Copy link
Owner

dvdoug commented Oct 26, 2021

I'll try and take a look later this week

@dvdoug
Copy link
Owner

dvdoug commented Nov 1, 2021

$packer->addBox(new TestBox('Small', 160, 130,  70, 0, 0, 0, 0, 100000));
$packer->addBox(new TestBox('Large', 250, 175, 100, 0, 0, 0, 0, 100000));

I assume in the example you meant the below? Otherwise there won't be any results 😅

$packer->addBox(new TestBox('Small', 160, 130,  70, 160, 130,  70, 0, 100000));
$packer->addBox(new TestBox('Large', 250, 175, 100, 250, 175, 100, 100000));

@dvdoug
Copy link
Owner

dvdoug commented Nov 6, 2021

This is one of those where when I tweak the logic to make the packing better in this particular scenario better, others regress and get worse. Will keep at it...

@colinmollenhour
Copy link
Contributor

Not sure if I should open a separate task or not but here is a similar example that is actually much simpler:

  • 5 units of an item which is 2.6 L x 2.6 W x 4.6 H inches
  • One box option that is 7.25 L x 7.25 W x 6.5 H inches (a USPS flat rate box)

This should be able to fit up to 6 units by laying 4 on their side and stacking those 4 two high and then the remaining two upright. However, BoxPacker splits it into two boxes (first one with 3 units shown) but you can see how six would be able to fit:

image

@dvdoug
Copy link
Owner

dvdoug commented Jan 16, 2022

Not sure if I should open a separate task or not

In general yes please as it's very possible there are different issues in play for different scenarios. I've created #272 to track that example

dvdoug added a commit that referenced this issue Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants