Download the PHP package nawebco/box-packer without Composer
On this page you can find all versions of the php package nawebco/box-packer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nawebco/box-packer
More information about nawebco/box-packer
Files in nawebco/box-packer
Package box-packer
Short Description Yet another solution to the packing/knapsack problem.
License MIT
Informations about the package box-packer
Yet Another Box Packer Package
This module implements a rough solution to the bin packing problem. It was originally developed to support an e-commerce merchant's desire to offer a shipping option only if all the items in an order would fit into a certain box. This implementation supports multiple boxes as well.
The bin-packing problem is NP hard. This implementation is a heuristic that won't always provide an optimal solution, but it is fast and it's unlikely to provide a solution that's too difficult for a human to replicate when packing a box with real (physical) items.
Briefly, this algorithm works as follows:
- Largest (by volume) items are packed first.
- Items are packed in layers. Layers are as wide and long as the box and are as tall as the tallest object in the layer.
- Items are packed alongside each other in each layer with the longest edge on the bottom, oriented in a way that yields the largest remaining area.
- If an item doesn't fit in any existing layers, the algorithm starts a new layer.
- Each time an item is added, the algorithm attempts to add it to the lower layers in any remaining spaces (including above other items), unless doing so would increase the height of the layer.
- Each time a new layer is started, the algorithm checks to make sure the total height of the layers hasn't exceeded the box height.
Using NAWebCo\BoxPacker
To install, run in your project's root directory. If you aren't already using
Composer's autoloader, be sure to require vendor/autoload.php
wherever you need access to the BoxPacker.
Usage example:
In the example above, packable items are represented by the Solid
class. Any class that implements the SolidInterface
can be run through the Packer.
Requirements
- PHP version 5.6 or higher
License
NAWebCo\BoxPacker is MIT-licensed.
All versions of box-packer with dependencies
ext-json Version *