evenfurther / pathfinding

Pathfinding library for rust
859 stars 71 forks source link

Demo for Munkkres Algorithm #316

Closed jackpeters667 closed 2 years ago

jackpeters667 commented 2 years ago

Hi there, I'm playing around with the crate and I havent been able to get the munkres algorithm working, I suspect i'm missing something fundamentally. Please have a look

        let d2: Vec<Vec<i32>> = vec![vec![2;3];3];
        let matrix = Matrix::from_vec(
            d2.len(),
            d2.get(0).unwrap().len(),
            d2,
        )
        .unwrap();
        let res = kuhn_munkres(&matrix);

But i'm getting trait bound errors on passing matrix to the function. How should I be going about it?

samueltardieu commented 2 years ago

Matrix::from_vec() expects a flat vector, in your case that would be [2; 9]. In your case, you probably want to use Matrix::from_rows() which takes something that can be made into an iterator:

    let d2: Vec<Vec<i32>> = vec![vec![2;3];3];
    let matrix = Matrix::from_rows(d2).unwrap();
    let res = kuhn_munkres(&matrix);