Munkres (aka Hungarian) algorithm for JS
Switch branches/tags
Clone or download
Latest commit a5d0542 May 30, 2017

README.md

Munkres implementation for Javascript

Bower Version NPM Version NPM Downloads Build Status Coverage Status Dependency Status devDependency Status

Introduction

The Munkres module provides an O(n³) implementation of the Munkres algorithm (also called the Hungarian algorithm or the Kuhn-Munkres algorithm). The algorithm models an assignment problem as an N×M cost matrix, where each element represents the cost of assigning the ith worker to the jth job, and it figures out the least-cost solution, choosing a single item from each row and column in the matrix, such that no row and no column are used more than once.

Usage

var munkres = require('munkres-js');

munkres([
  [400, 150, 400],
  [400, 450, 600],
  [300, 225, 300]
])
// => [ [ 0, 1 ], [ 1, 0 ], [ 2, 2 ] ]

Returns the list of matrix indices corresponding to the optimal assignment.

When used in the browser, the global computeMunkres function is exposed.

See the docs in munkres.js for more details.

Meta

This module is a translation of a Python implementation by Brian Clapper.

The original implementation is based on http://csclab.murraystate.edu/~bob.pilgrim/445/munkres.html.

It is available via bower and npm as munkres-js.

Copyright

© 2014 Anna Henningsen (Conversion to JS)

© 2008 Brian M. Clapper

License

Apache License 2.0. See accompanying LICENSE file.