PHPackages                             kick-in/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. [Localization &amp; i18n](/categories/localization)
4. /
5. kick-in/hungarian

ActiveLibrary[Localization &amp; i18n](/categories/localization)

kick-in/hungarian
=================

0.3.1(3y ago)213.7k↓41.7%1[5 issues](https://github.com/Kick-In/hungarian/issues)MITPHPPHP &gt;=7.2CI failing

Since Dec 7Pushed 3y ago6 watchersCompare

[ Source](https://github.com/Kick-In/hungarian)[ Packagist](https://packagist.org/packages/kick-in/hungarian)[ RSS](/packages/kick-in-hungarian/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (12)Used By (0)

Kick-In/Hungarian
=================

[](#kick-inhungarian)

*PHP implementation of various algorithms for the Linear Assignment Problem.*

[![Build status](https://camo.githubusercontent.com/4404b187348b64903457a25c877c179c86e353274e328beac2d327a6b03ae476/68747470733a2f2f7472617669732d63692e6f72672f4b69636b2d496e2f68756e67617269616e2e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/4404b187348b64903457a25c877c179c86e353274e328beac2d327a6b03ae476/68747470733a2f2f7472617669732d63692e6f72672f4b69636b2d496e2f68756e67617269616e2e7376673f6272616e63683d6d6173746572)

Documentation
-------------

[](#documentation)

The original paper by Jonker and Volgenant can be found [SpringerLink](https://link.springer.com/article/10.1007%2FBF02278710) or in the [`doc/` folder](https://github.com/Kick-In/hungarian/blob/master/doc/).

Usage
-----

[](#usage)

The hungarian library contains the fundamentals needed to solve a linear assignment problem, as well as some abstractions to make integration easier.

### Basic usage

[](#basic-usage)

The plain matrix object is indexed by integer and allows getting and setting of values, it is always a square matrix. To fill a three by three matrix, you might do the following.

```
use Kickin\Hungarian\Matrix\Matrix;

$matrix = new Matrix(3);
$matrix->set(0, 0, 10);
$matrix->set(1, 0, 15);
$matrix->set(2, 0, 12);
$matrix->set(0, 1, 12);
$matrix->set(1, 1, 13);
$matrix->set(2, 1, 14);
$matrix->set(0, 2, 15);
$matrix->set(1, 2, 17);
$matrix->set(2, 2, 25);
```

Using the matrix above, we can use the Hungarian method.

```
use Kickin\Hungarian\Algo\Hungarian;

$solver = new Hungarian();
$result = $solver->solve($matrix);
```

Or, if you'd want to find the highest scoring assignment, you can call use `solveMax()`.

```
$result = $solver->solveMax($matrix);
```

Under the hood, this is equivalent to solving the matrix after calling `invert()`.

This result can then be used as a list of tuples.

```
foreach($result as [$row, $col]){
  echo $row . ": " . $col . "\n";
}
```

### Alternate types of matrices

[](#alternate-types-of-matrices)

In most cases, you're not actually trying to pair integers, instead you might want to assign users to tasks. One way to do this, is by using string labels

```
use Kickin\Hungarian\Matrix\StringMatrix;

$matrix = new StringMatrix(["Alice", "Bob", "Carol"], ["Bathroom", "Kitchen", "Windows"]);
$matrix->set("Alice", "Bathroom", 10);
$matrix->set("Bob",   "Bathroom", 15);
$matrix->set("Carol", "Bathroom", 12);
$matrix->set("Alice", "Kitchen",  12);
$matrix->set("Bob",   "Kitchen",  13);
$matrix->set("Carol", "Kitchen",  14);
$matrix->set("Alice", "Windows",  15);
$matrix->set("Bob",   "Windows",  17);
$matrix->set("Carol", "Windows",  25);
```

Another option is by using objects as labels, for example using Eloquent

```
use Kickin\Hungarian\Matrix\LabeledMatrix;

$matrix = new LabeledMatrix(User::all(), Task::all());
```

### MatrixBuilder

[](#matrixbuilder)

Finally, it is likely you don't have a square matrix or need to write quite some boilerplate code to create a proper matrix. To help in this, you can use the `MatrixBuilder` class. This will automatically ensure your matrix is square, augmenting it where needed.

```
use Kickin\Hungarian\Matrix\MatrixBuilder;

$builder = new MatrixBuilder();
$builder->setRowSource(["Alice", "Bob", "Carol", "Dave"]);
$builder->setColSource(["Garbage", "Sweep floor"]);
$builder->setDefaultValue(1);
$builder->setAugmentValue(10);
$builder->setMappingFunction(function($row, $col){
  return 1; // Define your own scoring for any assignment pair
});

$matrix = $builder->build();
```

If desired, you can easily remove unassigned rows and columns from the results

```
$result = $solver->solve($matrix);
$assignedOnly = $result->withoutUnassigned();
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.1% 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 ~121 days

Recently: every ~251 days

Total

11

Last Release

1186d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1835343?v=4)[Bob van de Vijver](/maintainers/bobvandevijver)[@bobvandevijver](https://github.com/bobvandevijver)

![](https://avatars.githubusercontent.com/u/3901745?v=4)[Tobias Feijten](/maintainers/tobias-93)[@tobias-93](https://github.com/tobias-93)

---

Top Contributors

[![CerebralFart](https://avatars.githubusercontent.com/u/11133931?v=4)](https://github.com/CerebralFart "CerebralFart (49 commits)")[![bobvandevijver](https://avatars.githubusercontent.com/u/1835343?v=4)](https://github.com/bobvandevijver "bobvandevijver (1 commits)")[![VXLs](https://avatars.githubusercontent.com/u/31586178?v=4)](https://github.com/VXLs "VXLs (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1927.0k1](/packages/smmoosavi-php-gettext)

PHPackages © 2026

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