@@ -355,17 +355,17 @@ function add_indexed_restrictions!(g::OSMGraph{U,T,W}) where {U <: DEFAULT_OSM_I
355
355
end
356
356
357
357
"""
358
- add_weights! (g::OSMGraph, weight_type::Symbol=:distance)
358
+ generate_weights (g::OSMGraph; weight_type::Symbol=:distance)
359
359
360
- Adds edge weights to `OSMGraph`.
360
+ Generates a sparse weights matrix for the graph.
361
361
"""
362
- function add_weights! (g:: OSMGraph , weight_type:: Symbol = :distance )
362
+ function generate_weights (g:: OSMGraph ; weight_type:: Symbol = :distance )
363
363
n_edges = length (g. edge_to_way)
364
364
o_indices = Vector {Int} (undef, n_edges) # edge origin node indices
365
365
d_indices = Vector {Int} (undef, n_edges) # edge destination node indices
366
366
weights = Vector {Float64} (undef, n_edges)
367
367
368
- W = DEFAULT_OSM_EDGE_WEIGHT_TYPE
368
+ W = LightOSM . DEFAULT_OSM_EDGE_WEIGHT_TYPE
369
369
370
370
@inbounds for (i, edge) in enumerate (keys (g. edge_to_way))
371
371
o_loc = g. nodes[edge[1 ]]. location
@@ -377,23 +377,35 @@ function add_weights!(g::OSMGraph, weight_type::Symbol=:distance)
377
377
dist = distance (o_loc, d_loc, :haversine )
378
378
if weight_type == :time || weight_type == :lane_efficiency
379
379
highway = g. edge_to_way[edge]
380
- maxspeed = g. ways[highway]. tags[" maxspeed" ]:: DEFAULT_OSM_MAXSPEED_TYPE
380
+ maxspeed = g. ways[highway]. tags[" maxspeed" ]:: LightOSM. DEFAULT_OSM_MAXSPEED_TYPE
381
381
if weight_type == :time
382
382
weight = dist / maxspeed
383
383
else
384
- lanes = g. ways[highway]. tags[" lanes" ]:: DEFAULT_OSM_LANES_TYPE
385
- lane_efficiency = get (LANE_EFFICIENCY[], lanes, 1.0 )
384
+ lanes = g. ways[highway]. tags[" lanes" ]:: LightOSM. DEFAULT_OSM_LANES_TYPE
385
+ lane_efficiency = get (LightOSM . LANE_EFFICIENCY[], lanes, 1.0 )
386
386
weight = dist / (maxspeed * lane_efficiency)
387
387
end
388
- else
389
- # Distance
388
+ elseif weight_type == :distance
390
389
weight = dist
390
+ else
391
+ weight = Float64[]
391
392
end
392
393
weights[i] = max (weight, eps (W))
393
394
end
394
395
395
396
n = length (g. nodes)
396
- g. weights = sparse (o_indices, d_indices, weights, n, n)
397
+ weights_matrix = sparse (o_indices, d_indices, weights, n, n)
398
+
399
+ weights_matrix
400
+ end
401
+
402
+ """
403
+ add_weights!(g::OSMGraph, weight_type::Symbol=:distance)
404
+
405
+ Adds edge weights to `OSMGraph`.
406
+ """
407
+ function add_weights! (g:: OSMGraph , weight_type:: Symbol = :distance )
408
+ g. weights = generate_weights (g; weight_type)
397
409
g. weight_type = weight_type
398
410
return g
399
411
end
0 commit comments