BoxPacker
BoxPacker copied to clipboard
How to make volume box full first when item need more than 1 box
Hi Doug.. Thank you for creating this wonderful project. I recently used your project to estimate how much cargo is needed from a list of items in the database. However, after the calculation, there are several cargoes/boxes that are not fully filled in volume even though there are some items that can make these boxes full by volume. Can I make a box full of volume first before stuff is put into the next box?
Thank you in advance
Item Test : 1480X1140X1140->2 1480X1140X750->56 2240X1480X1200->1 2240X1480X1300->1 2240X1480X1480->1 2240X1480X1600->3 2240X1480X2240->16 2240X1480X750->5 250X180X150->1 2600X260X1400->3 400X350X230->3
Box Test $packer->addBox(new TestBox('20 Feet', 6058, 2438, 2591, 2200, 5758, 2352, 2385, 24000));
Current result =
These items fitted into 11 Container(s)
This Container is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2200g The volume in container is 82.3% The items in this box are: CWF-055CF was packed at co-ordinate (0, 0, 0) with l1140, w1480, d750 CWF-056CE was packed at co-ordinate (2960, 0, 750) with l1140, w1480, d750 CWF-056E6 was packed at co-ordinate (2960, 1140, 1500) with l1140, w1480, d750 CWF-056E0 was packed at co-ordinate (2960, 0, 1500) with l1140, w1480, d750 CWF-056DF was packed at co-ordinate (1480, 1140, 1500) with l1140, w1480, d750 CWF-056DE was packed at co-ordinate (1480, 0, 1500) with l1140, w1480, d750 CWF-056DD was packed at co-ordinate (0, 1140, 1500) with l1140, w1480, d750 CWF-056DC was packed at co-ordinate (0, 0, 1500) with l1140, w1480, d750 CWF-056DB was packed at co-ordinate (4440, 0, 750) with l1480, w1140, d750 CWF-056D1 was packed at co-ordinate (2960, 1140, 750) with l1140, w1480, d750 CWF-0566D was packed at co-ordinate (1480, 1140, 750) with l1140, w1480, d750 CWF-055D1 was packed at co-ordinate (0, 1140, 0) with l1140, w1480, d750 CWF-05666 was packed at co-ordinate (1480, 0, 750) with l1140, w1480, d750 CWF-05655 was packed at co-ordinate (0, 1140, 750) with l1140, w1480, d750 CWF-0562B was packed at co-ordinate (0, 0, 750) with l1140, w1480, d750 CWF-0561F was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d750 CWF-0561D was packed at co-ordinate (2960, 1140, 0) with l1140, w1480, d750 CWF-05611 was packed at co-ordinate (2960, 0, 0) with l1140, w1480, d750 CWF-0560F was packed at co-ordinate (1480, 1140, 0) with l1140, w1480, d750 CWF-055D3 was packed at co-ordinate (1480, 0, 0) with l1140, w1480, d750 CWF-056F5 was packed at co-ordinate (4440, 0, 1500) with l1480, w1140, d750
This Container is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2200g The volume in container is 54.8% The items in this box are: CWF-056F6 was packed at co-ordinate (0, 0, 0) with l1140, w1480, d750 CWF-056FE was packed at co-ordinate (0, 1140, 0) with l1140, w1480, d750 CWF-05740 was packed at co-ordinate (1480, 0, 0) with l1140, w1480, d750 CWF-05742 was packed at co-ordinate (1480, 1140, 0) with l1140, w1480, d750 CWF-05784 was packed at co-ordinate (2960, 0, 0) with l1140, w1480, d750 CWF-05792 was packed at co-ordinate (2960, 1140, 0) with l1140, w1480, d750 CWF-057E3 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d750 CWF-057E4 was packed at co-ordinate (0, 0, 750) with l1140, w1480, d750 CWF-057EB was packed at co-ordinate (0, 1140, 750) with l1140, w1480, d750 CWF-057F9 was packed at co-ordinate (1480, 0, 750) with l1140, w1480, d750 CWF-05804 was packed at co-ordinate (1480, 1140, 750) with l1140, w1480, d750 CWF-05806 was packed at co-ordinate (2960, 0, 750) with l1140, w1480, d750 CWF-05815 was packed at co-ordinate (2960, 1140, 750) with l1140, w1480, d750 CWF-05821 was packed at co-ordinate (4440, 0, 750) with l1480, w1140, d750
This Container is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2200g The volume in container is 59.1% The items in this box are: CWF-057FB was packed at co-ordinate (0, 0, 750) with l2240, w1480, d1200 CWF-0549D was packed at co-ordinate (1480, 0, 750) with l2240, w1480, d750 CWF-0549F was packed at co-ordinate (2960, 0, 750) with l2240, w1480, d750 CWF-05555 was packed at co-ordinate (0, 0, 0) with l1140, w1480, d750 CWF-05556 was packed at co-ordinate (0, 1140, 0) with l1140, w1480, d750 CWF-05557 was packed at co-ordinate (1480, 0, 0) with l1140, w1480, d750 CWF-055AC was packed at co-ordinate (1480, 1140, 0) with l1140, w1480, d750 CWF-055C4 was packed at co-ordinate (2960, 0, 0) with l1140, w1480, d750 CWF-055C8 was packed at co-ordinate (2960, 1140, 0) with l1140, w1480, d750 CWF-055CB was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d750 CWF-0554D was packed at co-ordinate (4440, 0, 750) with l1480, w1140, d750
This Container is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2200g The volume in container is 79.8% The items in this box are: CWF-052FD was packed at co-ordinate (0, 0, 0) with l2240, w1480, d1600 CWF-055B9 was packed at co-ordinate (1480, 0, 0) with l2240, w1480, d1480 CWF-05824 was packed at co-ordinate (2960, 0, 0) with l2240, w1480, d1300 CWF-05388 was packed at co-ordinate (0, 0, 1600) with l2240, w1480, d750 CWF-05438 was packed at co-ordinate (1480, 0, 1600) with l2240, w1480, d750 CWF-05492 was packed at co-ordinate (2960, 0, 1600) with l2240, w1480, d750 CWF-05491 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d750 CWF-0553D was packed at co-ordinate (4440, 0, 750) with l1480, w1140, d750 CWF-0554B was packed at co-ordinate (4440, 0, 1600) with l1480, w1140, d750
This Container is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2200g The volume in container is 79.2% The items in this box are: CWF-05273 was packed at co-ordinate (0, 0, 0) with l2240, w1480, d2240 CWF-0537C was packed at co-ordinate (1480, 0, 0) with l2240, w1480, d2240 CWF-05395 was packed at co-ordinate (2960, 0, 0) with l2240, w1480, d2240 CWF-05771 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d1140 CWF-0538B was packed at co-ordinate (4440, 0, 1140) with l1480, w1140, d750 CWF-04C4D was packed at co-ordinate (4440, 0, 1890) with l350, w400, d230 CWF-0554F was packed at co-ordinate (4840, 0, 1890) with l350, w400, d230 CWF-057F0 was packed at co-ordinate (4440, 350, 1890) with l400, w350, d230 CWF-04FA8 was packed at co-ordinate (5240, 0, 1890) with l180, w250, d150
This Container is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2200g The volume in container is 78.8% The items in this box are: CWF-0541E was packed at co-ordinate (0, 0, 0) with l2240, w1480, d2240 CWF-0541F was packed at co-ordinate (1480, 0, 0) with l2240, w1480, d2240 CWF-05421 was packed at co-ordinate (2960, 0, 0) with l2240, w1480, d2240 CWF-05822 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d1140 CWF-053A3 was packed at co-ordinate (4440, 0, 1140) with l1480, w1140, d750
This Container is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2200g The volume in container is 76.8% The items in this box are: CWF-05422 was packed at co-ordinate (0, 0, 0) with l2240, w1480, d2240 CWF-054A1 was packed at co-ordinate (1480, 0, 0) with l2240, w1480, d2240 CWF-056F8 was packed at co-ordinate (2960, 0, 0) with l2240, w1480, d2240 CWF-053A5 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d750 CWF-053A7 was packed at co-ordinate (4440, 0, 750) with l1480, w1140, d750
This Container is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2200g The volume in container is 76.8% The items in this box are: CWF-057F3 was packed at co-ordinate (0, 0, 0) with l2240, w1480, d2240 CWF-057F6 was packed at co-ordinate (1480, 0, 0) with l2240, w1480, d2240 CWF-057FD was packed at co-ordinate (2960, 0, 0) with l2240, w1480, d2240 CWF-053AE was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d750 CWF-053AF was packed at co-ordinate (4440, 0, 750) with l1480, w1140, d750
This Container is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2200g The volume in container is 76.8% The items in this box are: CWF-057FF was packed at co-ordinate (0, 0, 0) with l2240, w1480, d2240 CWF-05802 was packed at co-ordinate (1480, 0, 0) with l2240, w1480, d2240 CWF-05808 was packed at co-ordinate (2960, 0, 0) with l2240, w1480, d2240 CWF-053B4 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d750 CWF-05435 was packed at co-ordinate (4440, 0, 750) with l1480, w1140, d750
This Container is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2200g The volume in container is 63.7% The items in this box are: CWF-05809 was packed at co-ordinate (0, 0, 0) with l2240, w1480, d2240 CWF-052FA was packed at co-ordinate (1480, 0, 0) with l2240, w1480, d1600 CWF-052FB was packed at co-ordinate (2960, 0, 0) with l2240, w1480, d1600 CWF-05486 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d750 CWF-0548F was packed at co-ordinate (4440, 0, 750) with l1480, w1140, d750
This Container is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2200g The volume in container is 8.8% The items in this box are: CWF-056FB was packed at co-ordinate (0, 0, 0) with l260, w2600, d1400 CWF-056FC was packed at co-ordinate (2600, 0, 0) with l260, w2600, d1400 CWF-056FD was packed at co-ordinate (0, 260, 0) with l260, w2600, d1400
Hello @hudaibrhm
Have you see https://boxpacker.io/en/stable/weight-distribution.html? Try turning that behaviour off and you may get the results you're expecting 🤞
Hi @dvdoug , thank you for quick response :)
Actually i already did set setMaxBoxesToBalanceWeight to 0
My Current Function :
public function create_cargo()
{
$packer = new Packer();
$packer->setMaxBoxesToBalanceWeight(0);
//leave comment to add new cargo available
$packer->addBox(new TestBox('20 Feet', 6058, 2438, 2591, 2200,5758, 2352, 2385, 24000));
// $packer->addBox(new TestBox('40 Feet', 12058, 2438, 2591, 3800,10758, 2352, 2385, 26680));
//item must flat
$packer->addItem(new TestItem('Item 1', 1480, 1140, 1140, 1, true), 3);
$packer->addItem(new TestItem('Item 2', 1480, 1140, 750, 1, true), 19);
$packer->addItem(new TestItem('Item 3', 2240, 1480, 1200, 1, true), 1);
$packer->addItem(new TestItem('Item 4', 2240, 1480, 1300, 1, true), 1);
$packer->addItem(new TestItem('Item 5', 2240, 1480, 1480, 1, true), 1);
$packer->addItem(new TestItem('Item 6', 2240, 1480, 1600, 1, true), 6);
$packer->addItem(new TestItem('Item 7', 2240, 1480, 2240, 1, true), 8);
$packer->addItem(new TestItem('Item 8', 2240, 1480, 750, 1, true), 1);
$packer->addItem(new TestItem('Item 9', 250, 180, 150, 1, true), 1);
$packer->addItem(new TestItem('Item 10', 2600, 260, 1400, 1, true), 7);
$packer->addItem(new TestItem('Item 11', 400, 350, 230, 1, true), 2);
$packedBoxes = $packer->pack();
echo "These items fitted into " . count($packedBoxes) . " Container(s)" . PHP_EOL;
echo "</br>";
echo "</br>";
$i = 1;
foreach ($packedBoxes as $packedBox) {
$boxType = $packedBox->getBox();
echo "This Container number {$i} is a {$boxType->getReference()}, it is {$boxType->getOuterWidth()}mm wide, {$boxType->getOuterLength()}mm long and {$boxType->getOuterDepth()}mm high" . PHP_EOL;
echo "</br>";
echo "The combined weight of this container and the cases inside it is {$packedBox->getWeight()}g" . PHP_EOL;
echo "</br>";
echo "The volume in container is {$packedBox->getVolumeUtilisation()}%" . PHP_EOL;
echo "</br>";
echo "The items in this box are:" . PHP_EOL;
echo "</br>";
$packedItems = $packedBox->getItems();
foreach ($packedItems as $packedItem) { // $packedItem->getItem() is your own item object, in this case TestItem
echo $packedItem->getItem()->getDescription() . ' was packed at co-ordinate ' ;
echo '(' . $packedItem->getX() . ', ' . $packedItem->getY() . ', ' . $packedItem->getZ() . ') with ';
echo 'l' . $packedItem->getLength() . ', w' . $packedItem->getWidth() . ', d' . $packedItem->getDepth();
echo PHP_EOL;
echo "</br>";
}
$i++;
echo "</br>";
echo "</br>";
}
}
Result :
These items fitted into 7 Container(s)
This Container number 1 is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2212g The volume in container is 83.3% The items in this box are: Item 6 was packed at co-ordinate (1480, 0, 750) with l2240, w1480, d1600 Item 6 was packed at co-ordinate (0, 0, 750) with l2240, w1480, d1600 Item 5 was packed at co-ordinate (2960, 0, 750) with l2240, w1480, d1480 Item 2 was packed at co-ordinate (0, 0, 0) with l1140, w1480, d750 Item 2 was packed at co-ordinate (0, 1140, 0) with l1140, w1480, d750 Item 2 was packed at co-ordinate (1480, 0, 0) with l1140, w1480, d750 Item 2 was packed at co-ordinate (1480, 1140, 0) with l1140, w1480, d750 Item 2 was packed at co-ordinate (2960, 0, 0) with l1140, w1480, d750 Item 2 was packed at co-ordinate (2960, 1140, 0) with l1140, w1480, d750 Item 2 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d750 Item 2 was packed at co-ordinate (4440, 0, 750) with l1480, w1140, d750 Item 2 was packed at co-ordinate (4440, 0, 1500) with l1480, w1140, d750
This Container number 2 is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2211g The volume in container is 84.4% The items in this box are: Item 6 was packed at co-ordinate (0, 0, 750) with l2240, w1480, d1600 Item 6 was packed at co-ordinate (1480, 0, 750) with l2240, w1480, d1600 Item 6 was packed at co-ordinate (2960, 0, 750) with l2240, w1480, d1600 Item 8 was packed at co-ordinate (0, 0, 0) with l2240, w1480, d750 Item 2 was packed at co-ordinate (1480, 0, 0) with l1140, w1480, d750 Item 2 was packed at co-ordinate (1480, 1140, 0) with l1140, w1480, d750 Item 2 was packed at co-ordinate (2960, 0, 0) with l1140, w1480, d750 Item 2 was packed at co-ordinate (2960, 1140, 0) with l1140, w1480, d750 Item 2 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d750 Item 2 was packed at co-ordinate (4440, 0, 750) with l1480, w1140, d750 Item 2 was packed at co-ordinate (4440, 0, 1500) with l1480, w1140, d750
This Container number 3 is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2208g The volume in container is 79.1% The items in this box are: Item 7 was packed at co-ordinate (0, 0, 0) with l2240, w1480, d2240 Item 7 was packed at co-ordinate (1480, 0, 0) with l2240, w1480, d2240 Item 7 was packed at co-ordinate (2960, 0, 0) with l2240, w1480, d2240 Item 1 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d1140 Item 2 was packed at co-ordinate (4440, 0, 1140) with l1480, w1140, d750 Item 11 was packed at co-ordinate (4440, 0, 1890) with l350, w400, d230 Item 11 was packed at co-ordinate (4840, 0, 1890) with l350, w400, d230 Item 9 was packed at co-ordinate (5240, 0, 1890) with l180, w250, d150
This Container number 4 is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2208g The volume in container is 43.2% The items in this box are: Item 4 was packed at co-ordinate (0, 0, 0) with l1480, w2240, d1300 Item 3 was packed at co-ordinate (2240, 0, 0) with l1480, w2240, d1200 Item 10 was packed at co-ordinate (0, 1480, 0) with l260, w2600, d1400 Item 10 was packed at co-ordinate (2600, 1480, 0) with l260, w2600, d1400 Item 10 was packed at co-ordinate (0, 1740, 0) with l260, w2600, d1400 Item 10 was packed at co-ordinate (2600, 1740, 0) with l260, w2600, d1400 Item 10 was packed at co-ordinate (0, 2000, 0) with l260, w2600, d1400 Item 10 was packed at co-ordinate (2600, 2000, 0) with l260, w2600, d1400
This Container number 5 is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2205g The volume in container is 78.8% The items in this box are: Item 7 was packed at co-ordinate (0, 0, 0) with l2240, w1480, d2240 Item 7 was packed at co-ordinate (1480, 0, 0) with l2240, w1480, d2240 Item 7 was packed at co-ordinate (2960, 0, 0) with l2240, w1480, d2240 Item 1 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d1140 Item 2 was packed at co-ordinate (4440, 0, 1140) with l1480, w1140, d750
This Container number 6 is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2205g The volume in container is 72.3% The items in this box are: Item 7 was packed at co-ordinate (0, 0, 0) with l2240, w1480, d2240 Item 7 was packed at co-ordinate (1480, 0, 0) with l2240, w1480, d2240 Item 6 was packed at co-ordinate (2960, 0, 0) with l2240, w1480, d1600 Item 1 was packed at co-ordinate (4440, 0, 0) with l1480, w1140, d1140 Item 2 was packed at co-ordinate (4440, 0, 1140) with l1480, w1140, d750
This Container number 7 is a 20 Feet, it is 6058mm wide, 2438mm long and 2591mm high The combined weight of this container and the cases inside it is 2201g The volume in container is 2.9% The items in this box are: Item 10 was packed at co-ordinate (0, 0, 0) with l260, w2600, d1400
In box/container number 4 only get 43.2% volume and number 7 only 1 item added. I think item in box/container number 7 can added into box/container number 4 and we can saving number of box/container become 6 only.
am i doing something wrong ? or any other parameter must be added into my controller to get more efficiency result ?
Hi @hudaibrhm
Yes, it looks like that last item is certainly not being packed optimally - I'll need to investigate further. Thanks for reporting it