Code Monkey home page Code Monkey logo

boxpacker's Introduction

Taps mic🎤, is thing on?

Hello!

In my day job I help to make awesome applications that help to empower people and bring the world a little closer together. With my open source hat on, I create and/or maintain some libraries that I've needed that otherwise wouldn't exist 🦾 Check them out!

Tell me more

Sometimes in my career, I've looked for a library to complete what I imagined to be a fairly common task and to my surprise have found that one either doesn't exist or has been abandoned by its original author. This makes me sad, sometimes sad enough that I've decided to do something about it 😇.

Those libraries have now recorded over 2,500,000 downloads so I'm fairly confident that there are people out there using them to do all sorts of wonderful things.

An original creation because nothing else that I could find was suitable. When you try and get a pricing quote from a courier, you're asked for the width/length/depth of the box and it's weight. When you're working in e-commerce, weight is easy: you simply add up the individual weights of the all the stuff the customer ordered.

But the dimensions of the box(es)? That's....more complex.

If you have a latitude/longitude from GPS and just want to plot it on Google Maps or OpenStreetMap you probably don't need this. But if you have grid co-ordinates from a national mapping system e.g. the UK's Ordnance Survey and need to convert them, or have recently had your mind blown by discovering that the GPS latitude/longitude of a spot does not always agree with what national mapping authorities think it is then you need a conversion library. This project already existed when I first needed to do co-ordinate conversion, but was written for an old version of PHP. I polished it up, fixed some bugs and added some features.

Since then, the project has been completely rewritten and now supports over 6000 different coordinate systems, up from just 10 in previous versions.

My most recent pick-up, this is actually a fork of an abandoned fork of a long-abandoned project making me something of a 3rd-generation maintainer. This Behat extension allows you to generate code coverage reports when running a Behat test suite, just like those you can get when running PHPUnit.

In 2020 I did substantial work enhancing the code coverage statistics reported by PHPUnit's code coverage component, to (optionally) produce branch and path coverage alongside the traditional line-based metrics. As part of that work, I also contributed performance enhancements that make coverage generation quicker even when not using the new metrics.

An in-depth writeup of the changes is available to read here.

boxpacker's People

Contributors

acabala avatar bram123 avatar colinmollenhour avatar cosmologist avatar dependabot[bot] avatar dvdoug avatar garbee avatar ibboard avatar joachimdeboer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

boxpacker's Issues

Full Example

Hello @dvdoug
Could you please provide a full example including creating items and boxes implement the BoxPacker\Item and BoxPacker\Box interfaces. Because i already created those two classes but it's seems there is something missing.
Thanks

Outer dimensions and box weight

Hello!

I've developed a free (MIT) plugin for WooCommerce (not released yet), I've come up with following settings screen for the plugin:

image

I'm wondering do you use the Outer dimensions of package (and empty weight) to anything? I don't want to add those to the plugin, it would clutter the interface.

If I've understood this correctly the outer dimensions and box weight is irrelevant to the algorithm. Is that right?

Thanks, great plugin. P.S. I wish there were a way to minimize the price, currently the algorithm does not take the price in to account at all.

Hi, where is the TestBox and TestItem class?

Hello, I downloaded your library now, but when I try to run your examples (README.md), I get the message that TestBox and TestItem classes were not found.

So I implemented them, but even so, there are methods in ItemList and BoxList classes that do not exist, for example, $box->insert().

Can you share all the files to help me?

Rotación de los articulos

Cordial saludo.
Estoy usando la función "To just see if a selection of items will fit into one specific box"

Quisiera saber si esta se encarga de rotar los items insertados de la mejor manera y como lo hace.
Si lo realiza por items?
Si lo realiza por presentación? (es decir todos los items que sean iguales).

Muchas gracias por sus respuestas.

How to access box count for each box?

Hi there,
I got this working, when I print_r($packedBoxes) the results I can see all the data there.

But how do I access it? I some how figured out that I can run $packedBoxes->count() to get the total box count... But how do I get the box count for the different sizes?

Thanks

Ralph

Can't get it to work

Hi @dvdoug
I am trying to implement for an ecommerce application
I have installed with composer inside a directory outside of public_html.

I have included all of your files into my webpage php script which is in the public_html folder, using the following code:

require_once $_SERVER['DOCUMENT_ROOT'] . '/../composer/vendor/autoload.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/../composer/vendor/dvdoug/boxpacker/Box.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/../composer/vendor/dvdoug/boxpacker/BoxList.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/../composer/vendor/dvdoug/boxpacker/Item.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/../composer/vendor/dvdoug/boxpacker/ItemList.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/../composer/vendor/dvdoug/boxpacker/PackedBox.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/../composer/vendor/dvdoug/boxpacker/PackedBoxList.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/../composer/vendor/dvdoug/boxpacker/Packer.php';

When I try to run using the example code in your Readme, the script fails as soon as it gets to "$packer = new Packer();" with error message:

Fatal error: Class 'Packer' not found

If I add "namespace DVDoug\BoxPacker;" to the first line of the webpage php script I get a 500 server error but can't see what this error is.

Where am I going wrong here?

Box packing look-ahead causes unrotated packing when there's not enough space

There's a condition on line 292 that tries to short-circuit some of the packing algorithm and says "is the second item the same as this one and can we pack another one in more efficiently". In certain situations (where a box would slip perfectly down the side, if rotated, and there's enough length to fit two items) then it incorrectly starts a new row that is /not/ rotated. This allows it to pack far more items in a box than it should!

Example: Identical 30x10x30 items in a 40x70x30 box. There's enough space for seven items in a row, then turn two and fit them in the remaining width, with a 10x10x30 gap in the corner.

What actually happens: There's enough space for seven items in a row, then the short-circuit says an eighth item can fit in unrotated, so it fits the item in unrotated (which would stick out of the box by 20) and keeps packing them in that way.

Slow with large quantities of items

I'd like to use this box packer. However, it seems to always process boxes one at a time, even if I specify a quantity.

If I am shipping 5000 of something, for instance, it can take quite a long time to compute. It would be nice if the box packer recognized entire boxes that could be packed with (say) 100 of a single item, so that the remaining work would be fairly small for the odds and ends.

Dimensions of the used space

How can I get dimensions of the used space in a box? In my approach the container is only used to tell maximum dimensions. I want to know how much space the actual items are taking inside the container.

In the simple example below you can see that getRemainingLength() etc. functions are not helping in this case. The space items are taking in total is something like 15x13x16. I want to get this information programmatically.

containers
100x50x50 0.814kg 1.2%
remaining 100x22x50
items
15x13x8 0.407kg
15x13x8 0.407kg

This is really important for me because I need to know the minimum container for items that I don't know beforehand. There is no functionality like in php-laff which allows to pack items without knowing the containers.

Number of items fit into box off significantly

I have a 24x24x24 box. From the test example it would be something like:

$box1 = new TestBox('24x24x24Box', 24, 24, 24, 24, 24, 24, 2, 100);

I have the following 6x6x6 item that weighs 1 pound. Again, from the test example it would be something like:

$item1 = new TestItem('6x6x6Item', 6, 6, 6, 1);

Based on just the dimensions alone, I should be able to fit 64 of that item into the box. The problem that I am having is BoxPacker seems to think it can only fit 16 of this item in to this box. Looking at it, it appears that it fits the depth and length correctly, but the width is not being taken into account? I am not sure.

An example of my current code (simplified for here, of course):

$packer = new Packer();
$packer->addBox(new TestBox('24x24x24Box', 24, 24, 24, 24, 24, 24, 2, 100));

for ($i = 0; $i < 64; $i++) {
    $packer->addItem(new TestItem('6x6x6Item', 6, 6, 6, 1));
}

$packedBoxes = $packer->pack();

I am happy to provide more information if needed. I am using the most recent version (v1.2).

After doing some debugging, I may have found the cause of this. Take the two following lines for example in Packer.php around line 264:

$fitsSameGap = min($remainingWidth - $itemWidth, $remainingLength - $itemLength);
$fitsRotatedGap = min($remainingWidth - $itemLength, $remainingLength - $itemWidth);

In this case, after the first iteration we would have both $fitsSameGap and $fitsRotatedGap = 18. After Three more iterations, we would be down to zero. This fits four items in the box so far. On line 273, in the if statement, on all four of these iterations we enter the first block of the if statement because of this case:

$fitsSameGap <= $fitsRotatedGap

After four iterations, we have filled in the length of the box with four items, which would be correct. On the fifth iteration, both $fitsSameGap and $fitsRotatedGap will now be -6. Because they are both less than or equal to 0, we won't enter the if statement on line 267, and jump down to the else clause. Here, as far as I can tell, it just moves up a layer. After BoxPacker is done, I get the 24x24x24 box filled length wise and depth wise with 16 items (which is right if you don't use width, 4 length by 4 deep). The program does not appear to be taking into account the width of the items.

Hope this helps.

BoxPacker is not autoloading with composer

I've just installed BoxPacker by following the instructions in the Readme file, but the autoloader doesn't add any namespaces or classes into it. My composer was just updated and nothing seems wrong. What could be happening?

Composer Issues & Autoload Issues

I've been experiences an odd issue in my Laravel Setup, I have added "dvdoug/boxpacker": "^2.0" to my composer.json, it installs fine but everytime I try to run the Packer I get the following error:

local.ERROR: exception 'Symfony\\Component\\Debug\\Exception\\FatalErrorException' with message 'Class 'DVDoug\\BoxPacker\\TestBox' not found' in /Users/someone/Sites/nerd/rest/app/Http/Controllers/OrdersController.php:2846\nStack trace:\n#0 {main} \n

The code at that Errors Line Number is:

$_packer->addBox( new TestBox( $_package->id, $_outerwidth, $_outlength, $_outerdepth, $_emptyweight, $_innerwidth, $_innerlength, $_innerdepth, $_maxweight ) );

But I have the following included in my controller:

use DVDoug\BoxPacker\Packer;
use DVDoug\BoxPacker\TestBox;
use DVDoug\BoxPacker\TestItem;

Now here is the part that is driving me crazy, this only happens when I run a composer update for anything at all, it's like I have to reinstall it everytime not sure why. The package goes missing again?

Any Suggestions?

PHPUnit error: Interface not found

Hey Doug,

First of all, I want to thank you for sharing your project! However, I've tried running the tests with composer but couldn't get it to work.

This is what I've done:

  • Download the project folder
  • (CMD) composer install
  • (CMD) phpunit

This is the error I got at first:
Problem 1
- The requested package dvdoug/boxpacker No version set (parsed as 1.0.0) could not be found.

This was solved by adding:
"dvdoug/boxpacker": "*"
To:
"require": { ... }
in composer.json.

The error that followed was:
PHP Fatal error: Interface 'DVDoug\BoxPacker\Box' not found in C:\<mainFolder>\BoxPacker\tests\bootstrap.php on line 10

Fatal error: Interface 'DVDoug\BoxPacker\Box' not found in C:\<mainFolder>\BoxPacker\tests\bootstrap.php on line 10

Do you have any idea what I could be doing wrong here?

Kind rgds,
Chris

Class 'DVDoug\BoxPacker\TestBox' not found

Sorry for the noobish question, but I just can't get the example to work.

composer.json

{
    "require": {
        "dvdoug/boxpacker": "~1.5"
    }
}

php

<?php
require_once 'vendor/autoload.php';

use DVDoug\BoxPacker\ItemList;
use DVDoug\BoxPacker\Packer;
use DVDoug\BoxPacker\TestBox;
use DVDoug\BoxPacker\TestItem;

/*
   * To figure out which boxes you need, and which items go into which box
   */
$packer = new Packer();
$packer->addBox(new TestBox('Le petite box', 300, 300, 10, 10, 296, 296, 8, 1000));
$packer->addBox(new TestBox('Le grande box', 3000, 3000, 100, 100, 2960, 2960, 80, 10000));
$packer->addItem(new TestItem('Item 1', 250, 250, 2, 200));
$packer->addItem(new TestItem('Item 2', 250, 250, 2, 200));
$packer->addItem(new TestItem('Item 3', 250, 250, 2, 200));
$packedBoxes = $packer->pack();

echo("These items fitted into " . count($packedBoxes) . " box(es)" . 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" . PHP_EOL);
    echo("The combined weight of this box and the items inside it is {$packedBox->getWeight()}g" . PHP_EOL);

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

    echo(PHP_EOL);
}


/*
 * To just see if a selection of items will fit into one specific box
 */
$box = new TestBox('Le box', 300, 300, 10, 10, 296, 296, 8, 1000);

$items = new ItemList();
$items->insert(new TestItem('Item 1', 297, 296, 2, 200));
$items->insert(new TestItem('Item 2', 297, 296, 2, 500));
$items->insert(new TestItem('Item 3', 296, 296, 4, 290));

$packer = new Packer();
$packedBox = $packer->packIntoBox($box, $items);
/* $packedBox->getItems() contains the items that fit */

screen shot 2015-11-13 at 18 14 32

Sorting of boxes breaks if any difference is > 2^31-1

If you have the following boxes:

            $packer->addBox(new TestBox('Large Letter', 353, 250, 25, 10, 351, 248, 23, 500));
            $packer->addBox(new TestBox('Small Parcel', 450, 350, 160, 50, 448, 348, 158, 2000));
            $packer->addBox(new TestBox('Medium Parcel', 610, 460, 460, 100, 608, 458, 458, 20000));
            $packer->addBox(new TestBox('Large Parcel', 1300, 1290, 1290, 250, 1298, 1288, 1288, 30000));

Then the BoxList will sort the items correctly and try fitting items in the large letter first, then the small parcel, then the medium, then the large parcel.

If you increase the Large Parcel slightly so that Volume(Large Letter) - Volume(Large Parcel) > 2^31-1 (which isn't PHP_INT_MAX on my system, but is the max signed integer) like this:

            $packer->addBox(new TestBox('Large Letter', 353, 250, 25, 10, 351, 248, 23, 500));
            $packer->addBox(new TestBox('Small Parcel', 450, 350, 160, 50, 448, 348, 158, 2000));
            $packer->addBox(new TestBox('Medium Parcel', 610, 460, 460, 100, 608, 458, 458, 20000));
            $packer->addBox(new TestBox('Large Parcel', 1400, 1290, 1290, 250, 1398, 1288, 1288, 30000));

Then the compare function in BoxList returns something in the region of 2.3bn and puts Large Parcel as the "smallest" item because of integer overflow (until you get to a difference of ~4.3bn, at which point the overflow wraps around to positive again and all is good… until ~6.4bn!)

Step by Step use

I spent an entire day to try to make it work but failed miserably. Can anyone tell me step by step how to use it. I need it urgently

length and width dimensions always same

why the length and width dimensions of the box and the goods must always be the same? What should always be the same?
What if I make a different length and width dimensions? no influence? thanks Doug

Not packing optimally

We have a box with inner dimensions 165mm (width) x 225mm (length) x 25 (depth) and are packing 23 items of dimension 20mm (width) x 69mm (length) x 20mm (height).

The packing algorithm reports that only 17 would fit in box one and the remaining 6 in an additional box.

We know from physically packing that 23 items will fit in the box with simple rotation.

Can you confirm if there is some kind of tolerance at play here that is maybe not utilising the space effectively? Please find attached debug output for this packing situation.

debugReport.txt

Help

Doug, im trying to test and use your code for months... but i really cant make it run, i really didn't understand how to use in the documentation.

Can u please help me and teach me how to put this code to run?

[SOLVED] I made it work... my next comment says about it!

Thanks

LogAwareInterface is not available

Hi, I wasn't sure how to contact you otherwise, but I'm trying to implement this in my ci application.

I don't have PSR or PHPUnit and whenI try to use this library I get an error because PHP cant find LogAwareInterface.

I removed the code for the logger and it seems to be ok, I used require() statements instead of the autoload feature because Im using CI.

Finally, do I have to know how many Boxes to create, or do I just define the box sizes available.

cheers

Can this work with 2D?

I'm considering using this for packing large industrial sized parts like pumps and motors into crates, but not sure if I can make this work.

i.e. It is unlikely I can pack any particular item on top of any other particular item. Placing a motor on top of a pump won't work, as they will surely fall off in transit.
Some motors can fit along side a pump though, and that might work.
Some pumps look like letter T in shape, and I can achieve better packing by chaining them, one T facing forward, one backwards.

Overall, ... was thinking of writing my own library, but is there a way to make yours work for my purpose?

Testcase where algorithm is inefficient

Originally from an issue reported via email:

      $packer = new Packer();
      $packer->addBox(new TestBox('OW Box 1', 51, 33, 33, 0.6, 51, 33, 33, 0.6));
      $packer->addBox(new TestBox('OW Box 2', 50, 40, 40, 0.95, 50, 40, 40, 0.95));
      $packer->addItem(new TestItem('Product', 28, 19, 9, 0), 6);
      $packedBoxes = $packer->pack();

Should be 1 box, BoxPacker says 2

laravel 5.2

I used composer, all seems correctly installed.
but even when running phpunit i got error about:
"Fatal error: Interface 'DVDoug\BoxPacker\Box' not found "
I installed BoxPacker on a vanilla fresh laravel 5.2 installation.

BoxPacker Algorithm

Hi DvDoug, thanks for your BoxPacker source. I want to know, what is the name of the algorithm in this code? thanks before

Infinite loop

Hi

I am using your code around 2 month ago and with the last updates I found the following problem.
The problem is basically an infinite loop. I tried to get a simple sample of the code.

$packer = new Packer();
$packer->addBox(new TestBox('29x1x23Box', 29, 1, 23, 0, 29, 1, 23, 100));
$packer->addItem(new TestItem('13x1x10Item', 13, 1, 10, 1));
$packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1));
$packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1));
$packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1));
$packedBoxes = $packer->pack();

I've found the bug is in Packer.php function packIntoBox
else {
if ($remainingWidth >= min($itemWidth, $itemLength) && $layerDepth > 0) {
$this->logger->log(LogLevel::DEBUG, "No more fit in lengthwise, resetting for new row");
$remainingLength += $layerLength;
$remainingWidth -= $layerWidth;
$layerWidth = $layerLength = 0;
continue;
}
and as solution I've modified the code with this one
else {
if ($remainingWidth >= min($itemWidth, $itemLength) && $layerDepth > 0 && $layerLength > 0 && $layerWidth > 0) {
$this->logger->log(LogLevel::DEBUG, "No more fit in lengthwise, resetting for new row");
$remainingLength += $layerLength;
$remainingWidth -= $layerWidth;
$layerWidth = $layerLength = 0;
continue;
}

in the if statement I've asked by $layerLength > 0 && $layerWidth > 0 to avoid the infinite loop.
I am not sure if this should be the final solution but for me is working.

about unit of measurement

en_US

Hello good afternoon

I see that the example is being used as the unit of measurement mm if I will use as cm would cause a problem?

pt_BR

Ola Boa Tarde

Vejo que no exemplo está sendo usado a unidade de medida como milimetros, caso eu venha usar como centimetros acarretaria algum problema ?

Don't understand how to use.

I have never heard of composer, and don't want to install anything, mostly for portability reasons, and move between Mac, Windows and Linux servers almost daily.

Is there a normal way to use this, like just including a file?

I'm not sure why this is more complicated than other php classes I've seen, maybe it's just over my head, but I have no idea how to be able to start to use this, and I've been dealing with PHP for years!!

EDIT: Saw in another closed issue a similar comment about using standalone with any kind of composer, and the reply in general said to include all the files and then can use. I tried including the files and not doing anything else, and get "PHP Fatal error: Interface 'Psr\Log\LoggerAwareInterface' not found in /home/marine/public_html/crm/helpers/BoxPacker/Packer.php on line 20"

Maybe would be easier to try and implement this functionality myself, which is a shame because looks like a lot of effort went in to this, but don't think I will be able to get it to work :(

Weight limit possible bug

Thanks for the implementation. Looking through it, I just wanted to point out something that didn't quite look right to me, but it might just be my mistake.

In Packer.php, in the main While loop's conditions:

while(!$aItems->isEmpty() && $aItems->top()->getDepth() <= ($layerDepth ?: $remainingDepth) && $aItems->top()->getWeight() <= $remainingWeight) {

This seems to imply that if the item at the top is too heavy, then the rest of the items will be. But they're ordered by decreasing volume, so it's probably not true.

Constraints on items?

Not sure if this would even be in the same scope of program, but one feature that would be useful would be to express quantity limits for object classes. Lithium ion batteries cannot be shipped more than two to a package, but you could put other things in the package, for example.

An issue and a question

First of all, let me say "thank you" for so great job you've done.

I have a task to fit different 2d figures (squares and rectangles in to bigger rectangle).

So, i have an issue and a question:
Issue:
I know, that items №581, 578, 571, 389 must fit into box1:
$packer->addBox(new TestBox('BOX1', 2500, 1250, 2, 10, 2500, 1250, 2, 1000));
$packer->addItem(new TestItem('581', 425, 2369, 2, 0));
$packer->addItem(new TestItem('571', 305, 2353, 2, 0));
$packer->addItem(new TestItem('389', 248, 305, 2, 0));
$packer->addItem(new TestItem('578', 410, 1940, 2, 0));

But it doesn't in my code (389 goes to an extra Box).

Question:
Is it possible to use triangles? :)

Thank you.

testing results

Hi ,

While i was testing your code,found that execution of below-mentioned input combination ended with abnormal result.Maybe it is due to misunderstanding of algorithm but i would be glad if you help me .

$packer = new Packer();
$packer->addBox(new TestBox('Le petite box', 12, 12, 12, 10, 10, 10, 10, 1000));

$packer->addItem(new TestItem('Item 1', 5, 3, 2, 2));
$packer->addItem(new TestItem('Item 2', 5, 3, 2, 2));
$packer->addItem(new TestItem('Item 3', 3, 3, 3, 3));
$packedBoxes = $packer->pack();
echo("These items fitted into " . count($packedBoxes) . " box(es)" . PHP_EOL );

foreach ($packedBoxes as $packedBox) {
$boxType = $packedBox->getBox();
echo("This box is a {$boxType->getReference()}, it is {$boxType->getOuterWidth()}mm wide, {$boxType->getOuterLength()}mm long and {$boxType->getOuterDepth()}mm high" . PHP_EOL );
echo("The combined weight of this box and the items inside it is {$packedBox->getWeight()}g" . PHP_EOL );

echo("The items in this box are:" . PHP_EOL );;
$itemsInTheBox = $packedBox->getItems();;

foreach ($itemsInTheBox as $item) {
echo($item->getDescription() . PHP_EOL );
}
}

Results are something like that :

These items fitted into 2 box(es)
This box is a Le petite box, it is 12mm wide, 12mm long and 12mm high
The combined weight of this box and the items inside it is 14g
The items in this box are:
Item 1
Item 2

This box is a Le petite box, it is 12mm wide, 12mm long and 12mm high
The combined weight of this box and the items inside it is 13g
The items in this box are:
Item 3

is this normal ?

$packer->pack() extremelly slow

I've created a packer with 3 types of boxes and added 1000 items to it. When I packed them, it took more than 10 minutes to finish it. Is it like this or is this a recursion problem?

Bug says Item is too large to fit, but item is small why?

Bug says Item is too large to fit, but item is small why?
Code:
$packer->addBox(new TestBox('Le grande box', 100, 100, 300, 1, 100,100, 300, 1500));
$packer->addItem(new TestItem('Item 1', 150, 50, 50, 20));

Bug:
Fatal error: Uncaught exception 'RuntimeException' with message 'Item Item 1 is too large to fit into any box' in C:\xampp\htdocs\box\Box.php:511 Stack trace: #0 C:\xampp\htdocs\box\Box.php(467): Packer->doVolumePacking() #1 C:\xampp\htdocs\box\1.php(11): Packer->pack() #2 {main} thrown in C:\xampp\htdocs\box\Box.php on line 511

1

Also I saw issue No 18
Link: #18 - It is working

Available space

Hi,

Is there a way to know the available space (width/height) in a box after packing?

Wrong results

I found a case in which the results are not as expected:
Box:

  • 500 (w) X 1000 (l) X 500 (d)

Items:

  1. 500 (w) X 500 (l) X 500 (d)
  2. 500 (w) X 500 (l) X 250 (d), not keeping it flat
  3. 500 (w) X 500 (l) X 250 (d), not keeping it flat

It packs two first items in a box, and last one in another one, but actually they all fit in just one. If I set 2nd and 3rd items to keep flat, it works. Same as if I rotate the box to be 1000 (w) X 500 (l) X 500 (d) or 500 (w) X 500 (l) X 1000 (d).

Thanks

Layer Depth calculation

Hi,

I wanted to thank you for this script, it saved hours of headaches.

I noticed i bug in the calculation.

In the following situation

<?php
  $packer = new Packer();
  $packer->addBox(new TestBox('Le petite box', 292, 336, 60, 10, 292, 336, 60, 9000));
  $packer->addBox(new TestBox('Le grande box', 421, 548, 335, 100, 421, 548, 335, 10000));
  $packer->addItem(new TestItem('Item 1', 226, 200, 40, 440));
  $packer->addItem(new TestItem('Item 2', 200, 200, 155, 1660));
  $packedBoxes = $packer->pack();
?>

packer return me to use "Le petite box" for the smaller item and "Le grande box" for the bigger item.

However, both item should fit inside "Le grande box" (stacked on top of each other ).

If i change this line in Packer.php

$notTooMuchShallower = ($layerDepth ? $aItems->top()->getDepth() > ($layerDepth * 0.9) : true);

to

$notTooMuchShallower = ($layerDepth ? $aItems->top()->getDepth() < ($remainingDepth * 0.9) : true);

It seem to make them both fit in the box.

How can i get package postion information?

First thanks for your great algorithm..
How can i get information each box fit in big box postion?
For Eg:
Big Box- 500,500,500(W,L,H)
Package 1-100,100,100(W,L,H)
Package 2-200,200,200(W,L,H)
How can i get postion to place Pacakge 1 and Package 2 in Big Box

Travis build badge failing

On the GitHub page, the Travis badge shows the build is failing, although the latest build is passing. There might be a caching issue, or some other configuration issue.

Class 'PHPUnit_Framework_TestCase' not found

Hi thanks for this awesome library. I'm trying to make it work accessing to: tests/PackerTest.php
But i get the following error:

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in *_/boxpacker/tests/PackerTest.php on line _11

Seems that I don't have the Class PHPUnit_Framework_TestCase but I'm using PHP 5.4, any suggestions?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.