1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use City;
/// Calculates the total distance of a cycle path through cities.
///
/// # Arguments
/// * `path` - Slice of city indices representing the route (must be closed, first == last)
/// * `cities` - Slice of cities with coordinates
///
/// # Returns
/// * Total Euclidean distance of the cycle
///
/// # Example
/// ```
/// use smart_dynamic_gravity_tsp::{City, calculate_cycle_distance};
///
/// let cities = vec![
/// City { x: 0.0, y: 0.0 },
/// City { x: 1.0, y: 0.0 },
/// ];
/// let path = vec![0, 1, 0];
/// let dist = calculate_cycle_distance(&path, &cities);
/// assert_eq!(dist, 2.0);
/// ```
/// Computes a symmetric distance matrix for all city pairs.
///
/// # Arguments
/// * `cities` - Slice of cities with coordinates
///
/// # Returns
/// * A 2D vector where `matrix[i][j]` is the Euclidean distance between city i and j
///
/// # Example
/// ```
/// use smart_dynamic_gravity_tsp::{City, compute_dist_matrix};
///
/// let cities = vec![
/// City { x: 0.0, y: 0.0 },
/// City { x: 3.0, y: 4.0 },
/// ];
/// let matrix = compute_dist_matrix(&cities);
/// assert_eq!(matrix[0][1], 5.0);
/// ```