latuconsinafr/3d-bin-packager
Composer 安装命令:
composer require latuconsinafr/3d-bin-packager
包简介
PHP Library for 3D Bin Packing.
README 文档
README
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::ASCENDINGandSortType::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 theArrayIteratordata type. You can see the id, length, height and etc for the bins inside the iterable and also all the fitted items inside thefittedItemsproperty. - 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
unfittedItemsproperty and move to the next bin. You can also see the total fitted or unfitted volume and weight viagetTotalFittedVolume(),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 theRotationCombinationType::classfor 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.
latuconsinafr/3d-bin-packager 适用场景与选型建议
latuconsinafr/3d-bin-packager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 69.37k 次下载、GitHub Stars 达 28, 最近一次更新时间为 2021 年 11 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「bin-packing」 「2d-bin-packing」 「3d-bin-packing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 latuconsinafr/3d-bin-packager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 latuconsinafr/3d-bin-packager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 latuconsinafr/3d-bin-packager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
A lightweight plain-PHP framework for database-backed CRUD APIs.
bughq error tracking - PHP SDK
ABsurge PHP SDK for feature flags and A/B testing
Production-ready PHP 8.1+ package (CloudCastle Env).
统计信息
- 总下载量: 69.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 28
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-11-29