Skip to content

Munkres (aka Hungarian) algorithm for JS

License

Notifications You must be signed in to change notification settings

dcmn-com/munkres-js

 
 

Repository files navigation

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.

About

Munkres (aka Hungarian) algorithm for JS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 91.8%
  • HTML 8.2%