BoxPacker icon indicating copy to clipboard operation
BoxPacker copied to clipboard

Placement according to the most suitable length and width?

Open fonteyazilim opened this issue 4 years ago • 4 comments

Hi Sir,

First of all, thank you very much for the application, it is very successful.

However, I need a slight change in the insertion algorithm. For parts, how can we always fill in the width and length in the most appropriate way? How can you support this issue? I have samples.

`

$packer = new Packer();

$packer->addBox(new TestBox('Le petite box', 220, 540, 1, 0, 220, 540, 1, 0));

$packer->addItem(new TestItem('1-60x80', 80,60, 1, 0, true), 1);
$packer->addItem(new TestItem('2-60x80', 80,60, 1, 0, true), 1);
$packer->addItem(new TestItem('3-60x100', 100,60, 1, 0, true), 1);
$packer->addItem(new TestItem('4-60x80', 80,60, 1, 0, true), 1);
$packer->addItem(new TestItem('5-60x80', 80,60, 1, 0, true), 1);
$packer->addItem(new TestItem('6-60x80', 80,60, 1, 0, true), 1);
$packer->addItem(new TestItem('7-60x80', 80,60, 1, 0, true), 1);
$packer->addItem(new TestItem('8-60x120', 120,60, 1, 0, true), 1);
$packer->addItem(new TestItem('9-60x160', 160,60, 1, 0, true), 1);
$packer->addItem(new TestItem('10-80x50', 50,80, 1, 0, true), 1);
$packer->addItem(new TestItem('11-80x60', 60,80, 1, 0, true), 1);
$packer->addItem(new TestItem('12-80x110', 110,80, 1, 0, true), 1);
$packer->addItem(new TestItem('13-90x160', 160,90, 1, 0, true), 1);
$packer->addItem(new TestItem('14-60x120', 120,60, 1, 0, true), 1);
$packer->addItem(new TestItem('15-60x80', 80,60, 1, 0, true), 1);
$packer->addItem(new TestItem('16-60x100', 100,60, 1, 0, true), 1);
$packer->addItem(new TestItem('17-60x120', 120,60, 1, 0, true), 1);
$packer->addItem(new TestItem('18-60x120', 120,60, 1, 0, true), 1);



$packedBoxes = $packer->pack();

echo "These items fitted into " . count($packedBoxes) . " box(es)<br>" . PHP_EOL;
foreach ($packedBoxes as $packedBox) {
    $boxType = $packedBox->getBox(); // your own box object, in this case TestBox
    echo "This box is a {$boxType->getReference()}, it is {$boxType->getOuterWidth()}mm wide, {$boxType->getOuterLength()}mm long and {$boxType->getOuterDepth()}mm high<br>" . PHP_EOL;
    echo "The combined weight of this box and the items inside it is {$packedBox->getWeight()}g<br>" . PHP_EOL;

    echo "The items in this box are:<br>" . PHP_EOL;
    $packedItems = $packedBox->getItems();
    foreach ($packedItems as $packedItem) { // $packedItem->getItem() is your own item object, in this case TestItem
        echo $packedItem->getItem()->getDescription()."<br>" . PHP_EOL;
    }
}

`

Result:

These items fitted into 2 box(es) This box is a Le petite box, it is 220mm wide, 540mm long and 1mm high The combined weight of this box and the items inside it is 0g The items in this box are: 13-90x160 9-60x160 12-80x110 14-60x120 17-60x120 18-60x120 8-60x120 16-60x100 3-60x100 1-60x80 11-80x60 15-60x80 2-60x80 4-60x80 10-80x50 This box is a Le petite box, it is 220mm wide, 540mm long and 1mm high The combined weight of this box and the items inside it is 0g The items in this box are: 5-60x80 6-60x80 7-60x80

Placement possible sample image: örnek görsel

Thanks.

fonteyazilim avatar May 13 '21 16:05 fonteyazilim

hi, i can pay to change the algorithm as i want.

fonteyazilim avatar May 16 '21 09:05 fonteyazilim

Hi @fonteyazilim

There is no perfect box-packing algorithm in existence, so like all such algorithms BoxPacker is essentially a set of heuristics which due to their very nature will sometimes pick the non-optimal result. I'll take a look at this specific example when I next have time.

dvdoug avatar May 16 '21 20:05 dvdoug

Hi @dvdoug Thanks for your answer. I can pay for this development. The logic here always comes by filling the most suitable width according to the dimensions.

fonteyazilim avatar May 17 '21 17:05 fonteyazilim

Hi sir, Have you had a review on this?

fonteyazilim avatar Dec 25 '21 11:12 fonteyazilim