Skip to content

Algorithm seems inefficient for tight packing #264

@MarcoWel

Description

@MarcoWel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions