pub fn get_route_distance(distance_matrix: &[Vec<f64>], route: &[usize]) -> f64
Expand description

Utility function to calculate the distance travelled following the specified route

distance_matrix is a &Vec<Vec<f64>> containing the distance matrix.

route is a &Vec<usize>, containing the route of the travelling salesman.

Returns an f64, representing the distance of the route travelled.

Examples

extern crate travelling_salesman;

fn main() {
    let cities = [
      (27.0, 78.0),
      (18.0, 24.0),
      (48.0, 62.0),
      (83.0, 77.0),
      (55.0, 56.0),
    ];

    let route_distance = travelling_salesman::get_route_distance(
      &travelling_salesman::get_distance_matrix(&cities),
      &vec![0, 2, 3, 4, 1, 0]
    );

    println!("The route distance for the tour [0, 2, 3, 4, 1, 0] is {}", route_distance);
}