PHPackages                             oizys/hungarian - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. oizys/hungarian

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

oizys/hungarian
===============

Kuhn-Munkres (Hungarian) algorithm for the assignment problem

1.0.2(3mo ago)138MITPHPPHP ^8.3CI passing

Since Feb 6Pushed 3mo agoCompare

[ Source](https://github.com/syzio/hungarian-php)[ Packagist](https://packagist.org/packages/oizys/hungarian)[ Docs](https://github.com/syzio/hungarian-php)[ RSS](/packages/oizys-hungarian/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Hungarian
=========

[](#hungarian)

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

Installation
------------

[](#installation)

```
composer require oizys/hungarian
```

Usage
-----

[](#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

[](#maximization)

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

### Rectangular matrices

[](#rectangular-matrices)

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

### Forbidden assignments

[](#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
------------

[](#requirements)

PHP 8.3+

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance88

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

91d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e3d6b92e664d44e3aa8af4fc805a54c84390211c0c9e7f907a108f206e59f28f?d=identicon)[syzio](/maintainers/syzio)

---

Top Contributors

[![syzio](https://avatars.githubusercontent.com/u/26165164?v=4)](https://github.com/syzio "syzio (13 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/oizys-hungarian/health.svg)

```
[![Health](https://phpackages.com/badges/oizys-hungarian/health.svg)](https://phpackages.com/packages/oizys-hungarian)
```

###  Alternatives

[symfony/polyfill-uuid

Symfony polyfill for uuid functions

688335.4M63](/packages/symfony-polyfill-uuid)[spatie/error-solutions

This is my package error-solutions

6853.2M11](/packages/spatie-error-solutions)[phpflo/phpflo

Flow-based programming for PHP

2173.3k4](/packages/phpflo-phpflo)[eftec/autoloadone

AutoloadOne is a program that generates an autoload class for PHP.

403.4k](/packages/eftec-autoloadone)[ys-tools/default-theme-configuration-bundle

OroCommerce Default Theme Configuration Bundle

124.2k](/packages/ys-tools-default-theme-configuration-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
