#routing #tsp #solver #dynamic-programming

concorde_rs

A Rust binding to Concorde TSP Solver

1 unstable release

0.1.1 Oct 25, 2023
0.1.0 Oct 19, 2023

#2584 in Algorithms

MIT license

305KB
6.5K SLoC

C 6.5K SLoC // 0.1% comments Rust 298 SLoC

concorde-rs

A Rust binding to Concorde TSP Solver that allows for directly calling the solver instead of communicating the problem via TSP.lib file. At the moment, this package only supports the call to two routines of the Concorde TSP Solver:

  1. Held-Karp: an exact solver based on dynamic programming
  2. Lin-Kernighan: a heuristic solver

Usage

use concorde_rs::{solver, Distance, LowerDistanceMatrix};

fn main() {
    struct Node(i32, i32);

    impl Distance for Node {
        fn calc_shortest_dist(&self, other: &Self) -> u32 {
            self.0.abs_diff(other.0) + self.1.abs_diff(other.1)
        }
    }

    let nodes: Vec<Node> = vec![Node(0, 0), Node(0, 3), Node(5, 6), Node(9, 1)];
    let dist_mat = LowerDistanceMatrix::from(nodes.as_ref());
    let solution = solver::tsp_hk(&dist_mat).unwrap();

    assert_eq!(solution.length, 30);
}

License

The Rust binding code is licensed under MIT license. For the Concorde TSP Solver code, please check Concorde TSP Solver.

No runtime deps