Repository is archived
No release in over 3 years
Low commit activity in last 3 years
A Ruby gem that evaluates the Hungarian algorithm in C
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

HungarianAlgorithmC

A Ruby gem that computes the Hungarian Algorithm in C.

Installation

Add the following to your Gemfile:

# Gemfile
gem 'hungarian_algorithm_c', github: 'deliveroo/hungarian_algorithm_c'

Run bundle install.

Usage

Find the best pairings for elements with costs like so:

costs = [
  [4, 3],
  [3, 0]
]

HungarianAlgorithmC.find_pairings(costs)

#=> [[0, 0], [1, 1]]

The output will be an array of arrays; each sub-array will have the first element as the row index and the second element as the column index for the costs matrix. The indices together will select the lowest-cost combination.

Another example:

costs = [
  [2, 3, 3],
  [3, 3, 2],
  [3, 2, 3]
]

HungarianAlgorithmC.find_pairings(costs)

#=> [[0, 0], [1, 2], [2, 1]]

Note: Your cost matrix should not have Float::INFINITY or very very large numbers as those will not be interpreted appropriately here.

Acknowledgements

The C code uses the implementation by Cyrill Stachniss. The one change made is that all exit(0) calls are commented out.