#![feature(test)]
extern crate nalgebra as na;
extern crate test;
extern crate linear_assignment;
use std::collections::HashSet;
use na::Transpose;
use test::Bencher;
use linear_assignment::*;
trait LinearAssignmentProblem {
fn munkres(&self) -> HashSet<Edge>;
}
impl LinearAssignmentProblem for na::DMat<u32> {
fn munkres(&self) -> HashSet<Edge> {
let mut matrix = &mut na::DMat::<u32>::new_zeros(self.nrows(), self.ncols());
matrix.clone_from(self);
let transposed = self.nrows() > self.ncols();
if transposed {
matrix.transpose_mut();
}
let size = MatrixSize { rows: matrix.nrows(), columns: matrix.ncols() };
assert!(size.columns >= size.rows);
let edges = solver::<na::DMat<u32>>(&mut matrix, &size);
if transposed {
edges.iter().map(|&(v, u)| (u, v)).collect()
} else {
edges
}
}
}
#[bench]
fn bench_square(b: &mut Bencher) {
let matrix = na::DMat::<u32>::from_fn(50, 50, |x, y| x as u32 * y as u32);
b.iter(|| matrix.munkres());
}