hrdf_routing_engine/
debug.rs

1use std::time::Instant;
2
3use chrono::Duration;
4use hrdf_parser::Hrdf;
5
6use crate::{
7    routing::{find_reachable_stops_within_time_limit, plan_journey},
8    utils::create_date_time,
9};
10
11pub fn run_debug(hrdf: Hrdf) {
12    println!();
13    println!(
14        "------------------------------------------------------------------------------------------------"
15    );
16    println!("--- Debug");
17    println!(
18        "------------------------------------------------------------------------------------------------"
19    );
20
21    test_plan_journey(&hrdf);
22    test_find_reachable_stops_within_time_limit(&hrdf);
23}
24
25#[allow(dead_code)]
26pub fn test_plan_journey(hrdf: &Hrdf) {
27    // ------------------------------------------------------------------------------------------------
28    // --- 2.0.5
29    // ------------------------------------------------------------------------------------------------
30
31    let max_num_explorable_connections = 10;
32    let verbose = true;
33
34    println!();
35    let start_time = Instant::now();
36
37    // 1. Petit-Lancy, Les Esserts => Onex, Bandol
38    plan_journey(
39        hrdf,
40        8587418,
41        8593027,
42        create_date_time(2025, 6, 1, 12, 30),
43        max_num_explorable_connections,
44        verbose,
45    );
46
47    // 2. Petit-Lancy, Les Esserts => Genève-Aéroport
48    plan_journey(
49        hrdf,
50        8587418,
51        8501026,
52        create_date_time(2025, 2, 9, 14, 2),
53        max_num_explorable_connections,
54        verbose,
55    );
56
57    // 3. Avully, village => Pont-Céard, gare
58    plan_journey(
59        hrdf,
60        8587031,
61        8593189,
62        create_date_time(2025, 7, 13, 16, 43),
63        max_num_explorable_connections,
64        verbose,
65    );
66
67    // 4. Petit-Lancy, Les Esserts => Vevey, Palud
68    plan_journey(
69        hrdf,
70        8587418,
71        8595120,
72        create_date_time(2025, 9, 17, 5, 59),
73        max_num_explorable_connections,
74        verbose,
75    );
76
77    // 5. Genève, gare Cornavin => Avusy, village
78    plan_journey(
79        hrdf,
80        8587057,
81        8587032,
82        create_date_time(2025, 10, 18, 20, 10),
83        max_num_explorable_connections,
84        verbose,
85    );
86
87    // 6. Genève => Bern, Bierhübeli
88    plan_journey(
89        hrdf,
90        8501008,
91        8590028,
92        create_date_time(2025, 11, 22, 6, 59),
93        max_num_explorable_connections,
94        verbose,
95    );
96
97    // 7. Genève => Zürich HB
98    plan_journey(
99        hrdf,
100        8501008,
101        8503000,
102        create_date_time(2025, 4, 9, 8, 4),
103        max_num_explorable_connections,
104        verbose,
105    );
106
107    // 8. Zürich HB => Lugano, Genzana
108    plan_journey(
109        hrdf,
110        8503000,
111        8575310,
112        create_date_time(2025, 6, 15, 12, 10),
113        max_num_explorable_connections,
114        verbose,
115    );
116
117    // 9. Chancy, Douane => Campocologno
118    plan_journey(
119        hrdf,
120        8587477,
121        8509368,
122        create_date_time(2025, 5, 29, 17, 29),
123        max_num_explorable_connections,
124        verbose,
125    );
126
127    // 10. Chancy, Douane => Sevelen, Post
128    plan_journey(
129        hrdf,
130        8587477,
131        8581989,
132        create_date_time(2025, 9, 10, 13, 37),
133        max_num_explorable_connections,
134        true,
135    );
136
137    //11. Genève => Paris gare de Lyon
138    plan_journey(
139        hrdf,
140        8501008,
141        8768600,
142        create_date_time(2025, 4, 28, 8, 29),
143        max_num_explorable_connections,
144        true,
145    );
146
147    //12. Genève => Lausanne
148    plan_journey(
149        hrdf,
150        8501008,
151        8501120,
152        create_date_time(2025, 4, 28, 8, 20),
153        max_num_explorable_connections,
154        true,
155    );
156
157    println!("\n{:.2?}", start_time.elapsed());
158}
159
160#[allow(dead_code)]
161pub fn test_find_reachable_stops_within_time_limit(hrdf: &Hrdf) {
162    let max_num_explorable_connections = 10;
163    // 1. Petit-Lancy, Les Esserts (8587418)
164    let departure_stop_id = 8587418;
165    let departure_at = create_date_time(2025, 6, 1, 12, 30);
166
167    // 2. Sevelen, Post (8588197)
168    // let departure_stop_id = 8588197;
169    // let departure_at = create_date_time(2025, 9, 2, 14, 2);
170
171    // 3. Avully, village (8587031)
172    // let departure_stop_id = 8587031;
173    // let departure_at = create_date_time(2025, 7, 13, 16, 43);
174
175    // 4. Bern, Bierhübeli (8590028)
176    // let departure_stop_id = 8590028;
177    // let departure_at = create_date_time(2025, 9, 17, 5, 59);
178
179    // 5. Genève, gare Cornavin (8587057)
180    // let departure_stop_id = 8587057;
181    // let departure_at = create_date_time(2025, 10, 18, 20, 10);
182
183    // 6. Villmergen, Zentrum (8587554)
184    // let departure_stop_id = 8587554;
185    // let departure_at = create_date_time(2025, 11, 22, 6, 59);
186
187    // 7. Lugano, Genzana (8575310)
188    // let departure_stop_id = 8575310;
189    // let departure_at = create_date_time(2025, 4, 9, 8, 4);
190
191    // 8. Zürich HB (8503000)
192    // let departure_stop_id = 8503000;
193    // let departure_at = create_date_time(2025, 6, 15, 12, 10);
194
195    // 9. Campocologno (8509368)
196    // let departure_stop_id = 8509368;
197    // let departure_at = create_date_time(2025, 5, 29, 17, 29);
198
199    // 10. Chancy, Douane (8587477)
200    // let departure_stop_id = 8587477;
201    // let departure_at = create_date_time(2025, 9, 10, 13, 37);
202
203    let start_time = Instant::now();
204    for time_limit in [60, 120, 180] {
205        let routes = find_reachable_stops_within_time_limit(
206            hrdf,
207            departure_stop_id,
208            departure_at,
209            Duration::minutes(time_limit),
210            max_num_explorable_connections,
211            false,
212        );
213
214        println!("\n{}", routes.len());
215    }
216
217    println!("{:.2?}", start_time.elapsed());
218}
219#[cfg(test)]
220mod tests {
221    use crate::debug::{test_find_reachable_stops_within_time_limit, test_plan_journey};
222
223    use hrdf_parser::{Hrdf, Version};
224    use test_log::test;
225
226    #[test(tokio::test)]
227    async fn debug() {
228        let hrdf = Hrdf::new(
229            Version::V_5_40_41_2_0_7,
230            "https://data.opentransportdata.swiss/en/dataset/timetable-54-2025-hrdf/permalink",
231            false,
232            None,
233        )
234        .await
235        .unwrap();
236
237        test_plan_journey(&hrdf);
238        test_find_reachable_stops_within_time_limit(&hrdf);
239    }
240}