OpenStreetMapX.jl
OpenStreetMapX.jl copied to clipboard
A way to expand the networks line segments
@pszufe I would like to know if openstreetMapX has any internal function that allows to have more than a one edge with the same node id as source and target? I mean let's say we have created 20 random paths as below. Could we associates new time and distance to them while keeping the previous edges in place? I mean like having an edge like 1 to 2 with time 10 and distance 100. And then having another edge 1 to 2 parallel to the previous one (with name start and end lable 1 and 2) but different time; like 15 second and 150 distance.
node_ids = collect(keys(m.nodes))
routes = Vector{Vector{Int}}()
for k in 1:20
a,b = rand(1:nv(m.g), 2)
route, route_time = OpenStreetMapX.shortest_route(m,m.n[a],m.n[b])
push!(routes, route)
end
I am not sure whether you are looking at k-shortest paths or dynamically changing weights. Since other people might use it, I will answer both cases.
k-shortest paths
OpenStreetMapX exposes the map as a Graphs.jl directed graph object.
Hence what you could do, assuming that m
is of type MapData
is to use Yen algorithm:
yen_k_shortest_paths(m.g, source, target, m.w, number_of_shortest_paths)
So in this way you could have different numbers of shortest paths between two points.
shortest path but changing weights (e.g. due to traffic)
Here you have two options
-
MapData
is mutable so you could do:
w = m.w
w2 = calculate_traffic(w)
m.w = w2
OpenStreetMapX.shortest_route(m,m.n[a],m.n[b])
#perhaps apply back the original w
Or you can use the Graphs.jl based code as above.
a_star(m.g, source, target, calculate_traffic(m.w))
Thanks a million @pszufe!!