Overview
kap provides Python and Rust solvers for k-partite assignment from pairwise cost matrices. It includes heuristic searches, an optimum bound for equal-size parts, and a linear assignment solver; Python also provides an exact MILP solver.
Documentation
Example
import numpy as np
import kap
costs = [np.array([[4, 1], [2, 3]]) for _ in range(3)]
result = kap.ils(costs, max_iter=10, random_state=0)
print(result.cliques, result.costs)
use kap::{Algo, MatrixView, Options, k_assignment};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let data = [4i64, 1, 2, 3];
let matrix = MatrixView::from_row_major(&data, 2, 2)?;
let costs = [matrix, matrix, matrix];
let result = k_assignment(&costs, Algo::Ils, &Options::default())?;
println!("{:?} {:?}", result.cliques, result.costs);
Ok(())
}
Python output:
[[(0, 0), (1, 1), (2, 1)], [(0, 1), (1, 0), (2, 0)]] [5, 8]
The Rust example prints the same cliques and costs in the same format.
Initial solutions
Use a warm start to supply a complete assignment to ILS or local search. For implementation details and the original algorithms, see the algorithms reference.
Reference
B. Gabrovšek, T. Novak, J. Povh, D. Rupnik Poklukar, and J. Žerovnik, “Multiple Hungarian Method for k-Assignment Problem,” Mathematics 8(11), 2050, 2020. doi:10.3390/math8112050.
The papers behind the other methods are listed in the algorithms reference.