Skip to content

Commit 4eae631

Browse files
committed
add edge_to_way Dict
1 parent 53edab9 commit 4eae631

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/simplification.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,22 @@ function path_to_endpoint(g::AbstractGraph, (ep, ep_succ)::Tuple{T,T}) where {T<
4545
return path
4646
end
4747

48+
"""
49+
Return the total weight of a path given as a Vector of Ids.
50+
"""
4851
function total_weight(g::OSMGraph, path::Vector{<:Integer})
4952
sum((g.weights[path[[i, i+1]]...] for i in 1:length(path)-1))
5053
end
5154

55+
function ways_in_path(g::OSMGraph, path::Vector{<:Integer})
56+
ways = Set{Int}()
57+
for i in 1:(length(path)-1)
58+
edge = [g.index_to_node[path[i]], g.index_to_node[path[i+1]]]
59+
push!(ways, g.edge_to_way[edge])
60+
end
61+
return collect(ways)
62+
end
63+
5264
"""
5365
Build a new graph which simplifies the topology of osmg.graph.
5466
The resulting graph only contains intersections and dead ends from the original graph.
@@ -79,7 +91,6 @@ function simplify_graph(osmg::OSMGraph{U, T, W}) where {U, T, W}
7991
u = index_mapping[first(path)]
8092
v = index_mapping[last(path)]
8193
path_weight = total_weight(osmg, path)
82-
8394
if add_edge!(graph, (u, v))
8495
key = 0
8596
weights[u, v] = path_weight
@@ -92,12 +103,17 @@ function simplify_graph(osmg::OSMGraph{U, T, W}) where {U, T, W}
92103
edges[u,v,key] = path
93104
end
94105

106+
edge_to_way = Dict{NTuple{3,U}, Vector{T}}()
107+
for (edge, path) in edges
108+
edge_to_way[edge] = ways_in_path(osmg, path)
109+
end
110+
95111
return SimplifiedOSMGraph(
96112
osmg,
97113
node_coordinates,
98114
node_to_index,
99115
index_to_node,
100-
Dict{Vector{T}, Vector{T}}(),
116+
edge_to_way,
101117
graph,
102118
edges,
103119
weights,

0 commit comments

Comments
 (0)