Skip to content

Commit 3c92143

Browse files
committed
refactor simplify_graph: create edge_to_way in the same loop
1 parent 0b55c94 commit 3c92143

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/simplification.jl

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,31 @@ Build a new graph which simplifies the topology of osmg.graph.
6666
The resulting graph only contains intersections and dead ends from the original graph.
6767
The geometry of the contracted nodes is kept in the edge_gdf DataFrame
6868
"""
69-
function simplify_graph(osmg::OSMGraph{U, T, W}) where {U, T, W}
70-
g = osmg.graph
71-
relevant_nodes = collect(endpoints(g))
69+
function simplify_graph(g::OSMGraph{U, T, W}) where {U, T, W}
70+
relevant_nodes = collect(endpoints(g.graph))
7271
n_relevant = length(relevant_nodes)
7372
graph = DiGraph(n_relevant)
74-
weights = similar(osmg.weights, (n_relevant, n_relevant))
73+
weights = similar(g.weights, (n_relevant, n_relevant))
7574
node_coordinates = Vector{Vector{W}}(undef, n_relevant)
7675
node_to_index = OrderedDict{T,U}()
7776
index_to_node = OrderedDict{U,T}()
7877

7978
index_mapping = Dict{U,U}()
8079
for (new_i, old_i) in enumerate(relevant_nodes)
8180
index_mapping[old_i] = new_i
82-
node_coordinates[new_i] = osmg.node_coordinates[old_i]
83-
node = osmg.index_to_node[old_i]
81+
node_coordinates[new_i] = g.node_coordinates[old_i]
82+
node = g.index_to_node[old_i]
8483
index_to_node[new_i] = node
8584
node_to_index[node] = new_i
8685
end
8786

8887
edges = Dict{NTuple{3,U}, Vector{U}}()
88+
edge_to_way = Dict{NTuple{3,U}, Vector{T}}()
8989
edge_count = Dict{Tuple{U,U}, Int}()
90-
for path in paths_to_reduce(g)
90+
for path in paths_to_reduce(g.graph)
9191
u = index_mapping[first(path)]
9292
v = index_mapping[last(path)]
93-
path_weight = total_weight(osmg, path)
93+
path_weight = total_weight(g, path)
9494
if add_edge!(graph, (u, v))
9595
key = 0
9696
weights[u, v] = path_weight
@@ -101,15 +101,11 @@ function simplify_graph(osmg::OSMGraph{U, T, W}) where {U, T, W}
101101
weights[u, v] = min(path_weight, weights[u, v])
102102
end
103103
edges[u,v,key] = path
104-
end
105-
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)
104+
edge_to_way[u,v,key] = ways_in_path(g, path)
109105
end
110106

111107
return SimplifiedOSMGraph(
112-
osmg,
108+
g,
113109
node_coordinates,
114110
node_to_index,
115111
index_to_node,

0 commit comments

Comments
 (0)