Skip to content

Commit 1dc5392

Browse files
committed
struggling with gtfs
1 parent d843074 commit 1dc5392

9 files changed

+217
-5
lines changed

Diff for: src/main.rs

+42-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ struct Args {
3030
/// Number of times to greet
3131
#[arg(long, default_value_t = true)]
3232
makequerygraph: bool,
33+
#[arg(long, default_value_t = true)]
3334
debugmode: bool,
3435
}
3536

3637
#[tokio::main]
3738
async fn main() {
3839
let mut args = Args::parse();
39-
40-
args.debugmode = true;
40+
let preset_distance = 250.0;
4141

4242
if !args.debugmode {
4343
args.makequerygraph = false;
@@ -64,8 +64,6 @@ async fn main() {
6464
//see following link, anything but first option (which includes walking between stations, hasnt been implemented yet)
6565
//https://www.google.com/maps/dir/Bloomfield,+Connecticut+06002/77+Forest+St,+Hartford,+CT+06105/@41.823207,-72.7745391,34082m/data=!3m1!1e3!4m20!4m19!1m5!1m1!1s0x89e7001af40714d7:0xc4be608b22d7e4a8!2m2!1d-72.7197095!2d41.8683576!1m5!1m1!1s0x89e653502e880197:0xc1f0096f7d179457!2m2!1d-72.7005256!2d41.7671825!2m4!4e3!6e0!7e2!8j1727241000!3e3!5i1
6666

67-
let preset_distance = 250.0;
68-
6967
if (args.makequerygraph) {
7068
//pepperidge farm to harriet beecher stowe center
7169
let (source, target) = make_points_from_coords(
@@ -133,6 +131,7 @@ async fn main() {
133131
}
134132

135133
else {
134+
println!("debug mode");
136135
let gtfs = read_from_gtfs_zip("test2.zip");
137136

138137
//overhead for cloning these strings is very low, it's just for displaying anyway
@@ -142,5 +141,44 @@ async fn main() {
142141

143142
let (transit_graph, connections) = TimeExpandedGraph::new(gtfs, "Wednesday".to_string(), 0);
144143
let (mut router, mut paths) = TransitDijkstra::new(transit_graph);
144+
145+
let (source, target) = make_points_from_coords(
146+
0.0, //always 0
147+
0.0,
148+
0.0, //always 0
149+
5.0,
150+
);
151+
152+
let now = Instant::now();
153+
let graph = query_graph_construction(
154+
&mut router,
155+
&mut paths,
156+
source,
157+
target,
158+
21600, //5:10 AM
159+
86400, //24 hour searchspace
160+
preset_distance,
161+
);
162+
163+
let output = File::create("test.json").unwrap();
164+
println!("query graph constructed in {:?}", now.elapsed());
165+
serde_json::to_writer(output, &graph).unwrap();
166+
167+
let run_query = query_graph_search(connections, graph, &mut paths);
168+
169+
if let Some(stuff) = run_query {
170+
let path = stuff.1.get_tp(stuff.0, &paths, &trips);
171+
for (node, route) in path.0 {
172+
println!("{:?}", node);
173+
if let Some(route) = route {
174+
println!("via {:?}", routes.get(&route).unwrap().short_name);
175+
} else {
176+
println!("start {}", stops.get(&node.station_id.to_string()).unwrap());
177+
}
178+
}
179+
} else {
180+
println!("no path");
181+
}
182+
145183
}
146184
}

Diff for: src/transit_dijkstras.rs

-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ impl TransitDijkstra {
181181
//stop conditions
182182
//cost or # of settled nodes goes over limit
183183
if pathed_node.cost_from_start > self.cost_upper_bound {
184-
println!("cost over");
185184
return visited_nodes;
186185
}
187186

Diff for: test.json

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"source": {
3+
"x": 0.0,
4+
"y": 0.0
5+
},
6+
"target": {
7+
"x": 5.0,
8+
"y": 0.0
9+
},
10+
"edges": {},
11+
"source_stations": [
12+
{
13+
"id": 5,
14+
"lat": 0,
15+
"lon": 0
16+
}
17+
],
18+
"target_stations": [
19+
{
20+
"id": 4,
21+
"lat": 0,
22+
"lon": 500000000000000
23+
}
24+
],
25+
"hubs": [
26+
3
27+
],
28+
"source_nodes": [
29+
"Departure,5,21900,5",
30+
"Arrival,5,21600,9",
31+
"Departure,5,21900,8",
32+
"Arrival,5,21600,5",
33+
"Transfer,5,21600,6",
34+
"Transfer,5,21600,8",
35+
"Transfer,5,21600,5",
36+
"Arrival,5,21600,6",
37+
"Transfer,5,21600,9",
38+
"Departure,5,21900,12",
39+
"Arrival,5,21600,8",
40+
"Transfer,5,21600,12",
41+
"Departure,5,21900,6",
42+
"Departure,5,21900,9",
43+
"Arrival,5,21600,12"
44+
],
45+
"target_nodes": [
46+
"Transfer,4,21600,10",
47+
"Departure,4,21900,10",
48+
"Arrival,4,21600,10"
49+
],
50+
"station_map": {
51+
"C": {
52+
"id": 2,
53+
"lat": 0,
54+
"lon": 200000000000000
55+
},
56+
"B": {
57+
"id": 0,
58+
"lat": 0,
59+
"lon": 100000000000000
60+
},
61+
"G": {
62+
"id": 1,
63+
"lat": 0,
64+
"lon": 600000000000000
65+
},
66+
"F": {
67+
"id": 4,
68+
"lat": 0,
69+
"lon": 500000000000000
70+
},
71+
"D": {
72+
"id": 3,
73+
"lat": 0,
74+
"lon": 300000000000000
75+
},
76+
"A": {
77+
"id": 5,
78+
"lat": 0,
79+
"lon": 0
80+
},
81+
"E": {
82+
"id": 6,
83+
"lat": 0,
84+
"lon": 400000000000000
85+
}
86+
}
87+
}

Diff for: test/agency.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
agency_url,agency_name,agency_timezone,agency_id
2+
http://www.thebus.org,TheBus,Pacific/Honolulu,1

Diff for: test/calendar.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
service_id,start_date,end_date,monday,tuesday,wednesday,thursday,friday,saturday,sunday
2+
1,20250101,20251231,1,1,1,1,1,1,1
3+

Diff for: test/routes.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
route_long_name,route_id,route_type,route_text_color,agency_id,route_color,route_url,route_desc,route_short_name
2+
AE,AE,0,,1,,,,
3+
ABE,ABE,0,,1,,,,
4+
ABC,ABC,0,,1,,,,
5+
ABDE,ABDE,0,,1,,,,
6+
ABCDE,ABCDE,0,,1,,,,
7+
CFG,CFG,0,,1,,,,
8+

Diff for: test/stop_times.txt

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_type,drop_off_type,shape_dist_traveled
2+
a1,06:00:00,06:05:00,A,1,,,,
3+
a1,06:10:00,06:15:00,E,2,,,,
4+
5+
b1,07:00:00,07:05:00,E,1,,,,
6+
b1,07:10:00,07:15:00,A,2,,,,
7+
8+
d1,06:00:00,06:05:00,A,1,,,,
9+
d1,06:10:00,06:15:00,B,2,,,,
10+
d1,06:20:00,06:25:00,E,3,,,,
11+
12+
e1,07:00:00,07:05:00,E,1,,,,
13+
e1,07:10:00,07:15:00,B,2,,,,
14+
e1,07:20:00,07:25:00,A,3,,,,
15+
16+
17+
g1,06:00:00,06:05:00,A,1,,,,
18+
g1,06:10:00,06:15:00,B,2,,,,
19+
g1,06:20:00,06:25:00,C,3,,,,
20+
21+
h1,07:00:00,07:05:00,C,1,,,,
22+
h1,07:10:00,07:15:00,B,2,,,,
23+
h1,07:20:00,07:25:00,A,3,,,,
24+
25+
j1,06:00:00,06:05:00,A,1,,,,
26+
j1,06:10:00,06:15:00,B,2,,,,
27+
j1,06:20:00,06:25:00,D,3,,,,
28+
j1,06:30:00,06:35:00,E,4,,,,
29+
30+
k1,07:00:00,07:05:00,E,1,,,,
31+
k1,07:10:00,07:15:00,D,2,,,,
32+
k1,07:20:00,07:25:00,B,3,,,,
33+
k1,07:30:00,07:35:00,A,4,,,,
34+
35+
m1,06:00:00,06:05:00,A,1,,,,
36+
m1,06:10:00,06:15:00,B,2,,,,
37+
m1,06:20:00,06:25:00,C,3,,,,
38+
m1,06:30:00,06:35:00,D,4,,,,
39+
m1,06:40:00,06:45:00,E,5,,,,
40+
41+
n1,07:00:00,07:05:00,E,1,,,,
42+
n1,07:10:00,07:15:00,D,2,,,,
43+
n1,07:20:00,07:25:00,C,3,,,,
44+
n1,07:30:00,07:35:00,B,4,,,,
45+
n1,07:40:00,07:45:00,A,5,,,,
46+
47+
p1,06:20:00,06:25:00,C,1,,,,
48+
p1,07:20:00,07:25:00,F,2,,,,
49+
p1,08:20:00,08:25:00,G,3,,,,
50+
51+
q1,05:00:00,05:05:00,G,1,,,,
52+
q1,06:00:00,06:05:00,F,2,,,,
53+
q1,07:00:00,07:05:00,C,3,,,,
54+

Diff for: test/stops.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
stop_id,stop_code,stop_name,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station,stop_timezone,wheelchair_boarding
2+
A,,,33.0,-117.00001,,,,,,0
3+
B,,,33.0,-117.00002,,,,,,0
4+
C,,,33.0,-117.00003,,,,,,0
5+
D,,,33.0,-117.00004,,,,,,0
6+
E,,,33.0,-117.00005,,,,,,0
7+
F,,,33.0,-117.00006,,,,,,0
8+
G,,,33.0,-117.00007,,,,,,0

Diff for: test/trips.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
block_id,route_id,direction_id,trip_headsign,shape_id,service_id,trip_id
2+
0,AE,0,xxxx,,1,a1
3+
0,AE,1,xxxx,,1,b1
4+
0,ABE,0,xxxx,,1,d1
5+
0,ABE,1,xxxx,,1,e1
6+
0,ABC,0,xxxx,,1,g1
7+
0,ABC,1,xxxx,,1,h1
8+
0,ABDE,0,xxxx,,1,j1
9+
0,ABDE,1,xxxx,,1,k1
10+
0,ABCDE,0,xxxx,,1,m1
11+
0,ABCDE,1,xxxx,,1,n1
12+
0,CFG,0,xxxx,,1,p1
13+
0,CFG,1,xxxx,,1,q1

0 commit comments

Comments
 (0)