oizys/hungarian 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

oizys/hungarian

最新稳定版本:1.0.2

Composer 安装命令:

composer require oizys/hungarian

包简介

Kuhn-Munkres (Hungarian) algorithm for the assignment problem

README 文档

README

Kuhn-Munkres (Hungarian) algorithm for the assignment problem in PHP. Solves optimal assignment in O(n^3) time.

Installation

composer require oizys/hungarian

Usage

use Oizys\Hungarian\Hungarian;

$solver = new Hungarian;

$result = $solver->solve([
    [82, 83, 69, 92],
    [77, 37, 49, 92],
    [11, 69,  5, 86],
    [ 8,  9, 98, 23],
]);

$result->cost();        // 140
$result->assignments(); // [[0, 2], [1, 1], [2, 0], [3, 3]]
$result->map();         // [0 => 2, 1 => 1, 2 => 0, 3 => 3]

count($result);         // 4
json_encode($result);   // {"assignments":[[0,2],[1,1],[2,0],[3,3]],"cost":140}
(string) $result;       // "4 assignments, cost: 140"

foreach ($result as $pair) {
    // [rowIndex, columnIndex]
}

Result implements Countable, IteratorAggregate, JsonSerializable, and Stringable.

Maximization

$solver = new Hungarian(Hungarian::MODE_MAXIMIZE);

Rectangular matrices

Matrices don't need to be square. Extra rows or columns are left unassigned automatically.

Forbidden assignments

Use INF to mark cells that must not be assigned:

$result = $solver->solve([
    [10,  2, INF, 15],
    [15, INF, INF,  2],
    [ 1, INF, INF,  4],
    [ 2, INF, INF, 10],
]);

Requirements

PHP 8.3+

License

MIT

统计信息

  • 总下载量: 110
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固