PHPackages                             elgigi/hungarian-algorithm - 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. elgigi/hungarian-algorithm

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

elgigi/hungarian-algorithm
==========================

An implementation of the Hungarian algorithm in PHP.

v1.1.0(2y ago)126.4k↑25.1%1MITPHPPHP ^8.0CI passing

Since Nov 15Pushed 5mo agoCompare

[ Source](https://github.com/ElGigi/HungarianAlgorithm)[ Packagist](https://packagist.org/packages/elgigi/hungarian-algorithm)[ RSS](/packages/elgigi-hungarian-algorithm/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Hungarian Algorithm
===================

[](#hungarian-algorithm)

[![Latest Version](https://camo.githubusercontent.com/f189f4e1edcc0c95cdbe8ae0b8353f4070a56dc77913333fac7bb1f7a9ae8e27/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c676967692f68756e67617269616e2d616c676f726974686d2e7376673f7374796c653d666c61742d737175617265)](https://github.com/ElGigi/HungarianAlgorithm/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/8880578fc4f70f2df8ff4bf7e587bc11aca11c11916c31bebf81e239fab00e4d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f456c476967692f48756e67617269616e416c676f726974686d2f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/ElGigi/HungarianAlgorithm/actions/workflows/tests.yml?query=branch%3Amain)[![Codacy Grade](https://camo.githubusercontent.com/a4d805e25bb770afe699cd42a71ad6e189acfb4b3a399468630c4e4e5cd864c8/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f67726164652f34633461356430353862353834373562623662653034363535356365623039662f6d61696e2e7376673f7374796c653d666c61742d737175617265)](https://app.codacy.com/gh/ElGigi/HungarianAlgorithm)[![Total Downloads](https://camo.githubusercontent.com/8450dcae6d30882f4aa5c6009f762c0f176332dff9e48e3b3895794e43796e42/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c676967692f68756e67617269616e2d616c676f726974686d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elgigi/hungarian-algorithm)

An implementation of the Hungarian algorithm in PHP. The Hungarian algorithm can be used to find the optimal (minimal cost) assignment between two types of entities given a cost matrix. The Hungarian algorithm is also known as the Kuhn–Munkres algorithm or Munkres assignment algorithm.

**This fork is based on [rpfk's](https://github.com/rpfk/Hungarian) implementation. Addition of original repository is visible on changelog.**

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

[](#installation)

You can install the library with [Composer](https://getcomposer.org/):

```
composer require elgigi/hungarian-algorithm
```

Usage
-----

[](#usage)

Define a square matrix with scores as input for the Hungarian class. A square matrix must be an array consisting of n arrays (rows), with each array consisting of n scores. The key of each element in the row array must be equal to the key of the column.

```
// Define the score matrix as n arrays consisting of n numerical values
$array = [
    [1, ··· ,1],
    ···
    [3, ··· ,0],
];

// Create a new Hungarian problem using the score matrix as input
$hungarian  = new Hungarian($array);

// Solve the problem using the Hungarian algorithm and get the solution as an array with the row and column as key and value, respectively
$allocation = $hungarian->solve();
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance48

Moderate activity, may be stable

Popularity32

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~426 days

Total

2

Last Release

854d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18268216?v=4)[Ronan Giron](/maintainers/ElGigi)[@ElGigi](https://github.com/ElGigi)

---

Top Contributors

[![rpfk](https://avatars.githubusercontent.com/u/11407536?v=4)](https://github.com/rpfk "rpfk (22 commits)")[![ElGigi](https://avatars.githubusercontent.com/u/18268216?v=4)](https://github.com/ElGigi "ElGigi (11 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[structurizr-php/structurizr-php

Structurizr for PHP

170137.7k](/packages/structurizr-php-structurizr-php)[torifat/cake-menu_builder

A dynamic menu building helper for CakePHP 2.x

755.6k](/packages/torifat-cake-menu-builder)[backstage/laravel-og-image

Laravel package to generate dynamic Open Graph images

723.2k](/packages/backstage-laravel-og-image)[alrik11es/calendar

An structured calendar generator in array, object or json format

131.1k](/packages/alrik11es-calendar)

PHPackages © 2026

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