Skip to content

Commit d7f7f3a

Browse files
committed
update example: test toplogy with shortest_path on random source and destination samples
1 parent f3ab9d2 commit d7f7f3a

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

example.jl

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
using LightOSM, Plots, GeoInterfaceRecipes
2+
using StatsBase: sample
23

34
g = graph_from_download(
45
:place_name,
56
place_name="tiergarten, berlin germany",
6-
network_type=:bike
7+
network_type=:drive
78
)
89
sg = simplify_graph(g)
910

10-
# check for missing edges
11-
plot(g, color=:red, linewidth=0.8, size=(800, 800))
12-
plot!(sg, linewidth=1.1, color=:black)
13-
savefig("edge_validation")
11+
# Set plot size
12+
size = (1920, 1080)
1413

15-
# show original nodes
16-
plot(sg)
17-
plot!(node_gdf(g).geom, color=:red, markersize=2.2)
14+
# Show original nodes
15+
plot(g; size)
1816
savefig("original_nodes")
1917

20-
# show relevant nodes
21-
plot(sg)
22-
plot!(node_gdf(sg).geom, color=:green, markersize=2.2)
23-
savefig("relevant_nodes")
18+
# Show relevant nodes
19+
plot(sg; size)
20+
savefig("relevant_nodes")
21+
22+
23+
24+
osm_ids = sample(collect(values(sg.nodes)), 200)
25+
for source in osm_ids
26+
for target in osm_ids
27+
path = shortest_path(g, source, target)
28+
path_simplified = shortest_path(sg, source, target)
29+
if isnothing(path) || isnothing(path_simplified)
30+
continue
31+
end
32+
path_length = total_path_weight(g, path)
33+
path_simplified_length = total_path_weight(sg, path_simplified)
34+
if !isapprox(path_length, path_simplified_length)
35+
println("Path from $source to $target is $path_length in the original graph and $path_simplified_length in the simplified graph")
36+
end
37+
end
38+
end

0 commit comments

Comments
 (0)