This package contains a PHP implementation to solve 3D bin packing problems.

Overview

3D Bin Packager

build codecov

This package contains a PHP implementation to solve 3d bin packing problems based on gedex implementation on Go and enzoruiz implementation on Python with some modifications to make it more modular.

Installation

Install by adding the package as a Composer requirement:

$ composer require latuconsinafr/3d-bin-packager

Usage

There's an example inside the root project example.php. Just simply type the command php example.php in the project's root and it would display the time elapsed and corresponding results with the number of lower bounds and the list of the bins (support for json encode cause every class implements the \JsonSerializable interface).

First of all, you have to initialize the packager object:

$packager = new Packager(2, SortType::DESCENDING);

The packager constructor takes two parameters:

  • Precision: The number of digits after the decimal point. It will be used for number of digits to round to.
  • Sort type: With two types available SortType::ASCENDING and SortType::DESCENDING. This sort type will be used to sort the bins and the items volume inside the packager based on the chosen sort type (whether it is ascending or descending)

After you initialized the packager, you can start to add the bin(s) or the item(s) into the packager with these 4 following methods:

// To add the bin one by one
$packager->addBin(new Bin('your-bin-identifier', 4, 4.5, 5.221, 50));

// Or if you wish to add all the bins at once
$packager->addBins([
    new Bin('your-first-bin-identifier', 2.22, 5.4, 20, 100),
    new Bin('your-second-bin-identifier', 1, 2, 1.5, 10)
]);

// It would be the same for the item(s)
$packager->addItem(new Item('item-id-1', 2, 2, 2, 5));

$packager->addItems([
    new Item('item-id-2', 1, 4.225, 2, 5),
    new Item('item-id-3', 2, 5, 2, 2.525),
    new Item('item-id-4', 1, 3.5, 3, 10),
    new Item('item-id-5', 3.551, 2, 2, 12.5)
]);

Then to pack all the item(s) to all the bin(s):

$packager->withFirstFit()->pack()

To get the result and other details after the packing are listed below:

  • To get all the bin(s) after the packing you can use either the $packager->getBins() or the $packager->getIterableBins() to return the ArrayIterator data type. You can see the id, length, height and etc for the bins inside the iterable and also all the fitted items inside the fittedItems property.
  • Due to the first fit method, the packing process would try to fit as much items as possible to the first bin and if there's no more space inside the bin, all the remaining items would be listed inside the unfittedItems property and move to the next bin. You can also see the total fitted or unfitted volume and weight via getTotalFittedVolume(), getTotalFittedWeight(), etc.
  • The identifier is used to make every single bin and item unique.
  • You can also see the total of all bin(s) and item(s) from the Packager class with getTotalBinsVolume(), getTotalBinsWeight(), etc.
  • You can get further detailed information about the fitted item inside the bin such as the current rotation type which is applied to fit the item into the bin via getRotationType() (you can see the RotationCombinationType::class for the rotation list).
  • You can serialize the resulted bins to see something like this:
{
    "bin-id": {
        "id": "bin-id",
        "length": 8,
        "breadth": 5,
        "height": 8,
        "volume": 320,
        "weight": 100,
        "fittedItems": [
            {
                "id": "item-id",
                "length": 3.1,
                "breadth": 5,
                "height": 4,
                "volume": 62,
                "weight": 2,
                "rotationType": 0, // You can get the rotation type of any item inside the bin
                "position": { // You can also get the detailed position of any item inside the bin
                    "x-axis": 0,
                    "y-axis": 0,
                    "z-axis": 0
                }
            }
            ...
        ],
        "totalFittedVolume": 212.23,
        "totalFittedWeight": 65.83,
        ...
    }
}
  • You can also get the corresponding position of any item inside the bin which is represented by the x-axis, y-axis and z-axis using getPosition(). In case you want to plot or use it for further analysis.
  • You can check the phpdoc or the code for further information.

Credits

License

This package is under MIT license.

You might also like...
This repository contains the codebase PHP bridge using RoadRunner Jobs plugin.

RoadRunner Jobs Plugin This repository contains the codebase PHP bridge using RoadRunner Jobs plugin. Installation To install application server and J

Messaging solutions for PHP - It contains advanced features build on top of a transport component

It contains advanced features build on top of a transport component. Client component kind of plug and play things or consumption component that simplify message processing a lot. Read more about it in documentation.

This repository contains research materials and dev notes for the DSM research

DSM Research This repository contains a loosely-organized information regarding the processes of DSM loading. A lot of information present here was co

Contains a few tools usefull for making your test-expectations agnostic to operating system specifics

PHPUnit Tools to ease cross operating system Testing make assertEquals* comparisons end-of-line (aka PHP_EOL) character agnostic Make use of EolAgnost

WordPress plugin which contains a collection of modules to apply theme-agnostic front-end modifications

Soil A WordPress plugin which contains a collection of modules to apply theme-agnostic front-end modifications. Soil is a commercial plugin available

This Repository contains a custom Workflow for Alfred which provides the function to instantly search in the Magento 2 DevDocs
This Repository contains a custom Workflow for Alfred which provides the function to instantly search in the Magento 2 DevDocs

Introduction Add the custom search to your Alfred Workflow and have a quicker access to the Magento 2 DevDocs. Installation Just download the alfredwo

The module for my life story project that contains my ProtonDrive screenshots.

By: Top README.md Read this article in a different language Sorted by: A-Z Sorting options unavailable ( af Afrikaans Afrikaans | sq Shqiptare Albania

This repository contains academic codes from experiments and labs I did during my academic years.

Table Of Content Semester 3 Business Communication Skills Computer Graphics Digital Electronics and Logic Design Fundamentals of Data Structures Human

Main ABRouter product repository that contains docker-compose file and orchestrates the project containers.

ABRouter-Compose 📟 ABRouter is the open-source tool to perform and track A/B tests which is also known as the experiments. Additionally, feature flag

Comments
  • Option to have Multiple of the same item, quantity parameter for new Item

    Option to have Multiple of the same item, quantity parameter for new Item

    Is it possible to use multiple of the same items, for adding them easily to addItems function. Instead of the following:

    $packager->addItems([
        new Item("Visitekaart 85x51mm sulfaatkarton", 85, 0.345, 51, 1.3)
    ])
    

    Something more like this, with the addition of a quantity for example: 1000 (for 1000 of the same items)

    $packager->addItems([
        new Item("Visitekaart 85x51mm sulfaatkarton", 85, 0.345, 51, 1.3, 1000)
    ])
    
    enhancement 
    opened by JeroenSteen 1
Releases(v1.0)
Owner
Farista Latuconsina
Farista Latuconsina
Do you want CronJob to follow the solar date?You need this package to solve this problem.

Shamsic Maybe it happened to you that you wanted to use CronJob in your project and you realized that you cannot manage the exact dates that are in th

Amin Ghaninia 5 Jul 19, 2022
Debug with Ray to fix problems faster

Debug with Ray to fix problems faster This package can be installed in any PHP application to send messages to the Ray app. The desktop app: can be us

Spatie 458 Dec 27, 2022
Magento 2 module which can find potential url related problems in your catalog data

Url data integrity checker module for Magento 2 Purpose The purpose of this module is to give store owners of a Magento 2 shop insight into what url-r

Baldwin 218 Jan 1, 2023
A Composer Package which installs the PhantomJS binary (Linux, Windows, Mac) into /bin of your project.

phantomjs-installer A Composer package which installs the PhantomJS binary (Linux, Windows, Mac) into /bin of your project. Table of Contents Installa

Jens A. Koch 149 Nov 8, 2022
Set a customer password with bin/magento.

Set a customer password Since Magento 2 no longer provides facilities to set a customers password, this command can come in handy during development w

Vinai Kopp 25 Mar 8, 2022
bin/magento command to display configured preferences for classes or interfaces

bin/magento command to display configured preferences for classes or interfaces A bin/magento command that will show you the configured preferences fo

David Manners 14 Jul 18, 2022
A faster drop in replacement for bin/magento cache:clean with file watcher

"You know, hope is a mistake. If you can't fix what's broken, you'll, uh... you'll go insane." - Max Rockatansky Magento 2 Cache Clean A faster drop i

mage2tv 460 Dec 26, 2022
Opinionated version of Wikimedia composer-merge-plugin to work in pair with Bamarni composer-bin-plugin.

Composer Inheritance Plugin Opinionated version of Wikimedia composer-merge-plugin to work in pair with bamarni/composer-bin-plugin. Usage If you are

Théo FIDRY 25 Dec 2, 2022
The package contains a bootstrap for running Yii3 console application.

Yii Console Runner The package contains a bootstrap for running Yii3 console application. Requirements PHP 8.0 or higher. Installation The package cou

Yii Software 4 Oct 15, 2022
📦 "PHP type names" contains the list of constants for the available PHP data types.

PHP type names PHP type names ?? Description Simple library containing the list of constants for the available PHP data types. Use those constant type

♚ PH⑦ de Soria™♛ 4 Dec 15, 2022