Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to expand the networks line segments #73

Open
ghost opened this issue Sep 22, 2023 · 2 comments
Open

A way to expand the networks line segments #73

ghost opened this issue Sep 22, 2023 · 2 comments

Comments

@ghost
Copy link

ghost commented Sep 22, 2023

@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
@pszufe
Copy link
Owner

pszufe commented Sep 22, 2023

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

  1. 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))

@ghost
Copy link
Author

ghost commented Sep 22, 2023

Thanks a million @pszufe!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant