Skip to content

Commit de9e6b0

Browse files
committed
Misc improvements.
1 parent 87535f7 commit de9e6b0

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/main/apply_geography.jl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ and similarly for graph traversal costs `delta_tau`.
1212
# Arguments
1313
- `graph`: Dict or NamedTuple that contains the network graph to which the geographical features will be applied.
1414
- `geography`: Dict or NamedTuple representing the geographical features, with the following fields:\n
15-
- `z::Vector{Float64}`: A J x 1 vector containing the z-coordinate (elevation) for each node, or `nothing` if no elevation data.\n
15+
- `z::Vector{Float64}`: (Optional) J x 1 vector containing the z-coordinate (elevation) for each node, or `nothing` if no elevation data.\n
1616
- `z_is_friction::Bool`: (Optional) logical value indicate that `z` represents friction rather than elevation. In that case, the measure of building cost is the average friction of the two nodes mean(Z1,Z2) rather than the difference Z2-Z1.\n
17-
- `obstacles::Matrix{Int64}`: An Nobs x 2 matrix specifying (i, j) pairs of nodes that are connected by obstacles, where Nobs is the number of obstacles, or `nothing` if no obstacles.
17+
- `obstacles::Matrix{Int64}`: (Optional) Nobs x 2 matrix specifying (i, j) pairs of nodes that are connected by obstacles, where Nobs is the number of obstacles, or `nothing` if no obstacles.
1818
1919
# Keyword Arguments
2020
- `across_obstacle_delta_i::Float64=Inf`: Rescaling parameter for building cost that crosses an obstacle.
@@ -61,8 +61,16 @@ function apply_geography(graph, geography; kwargs...)
6161
end
6262

6363
op = dict_to_namedtuple(options)
64-
geography = dict_to_namedtuple(geography)
65-
z, obstacles = geography.z, geography.obstacles
64+
if haskey(geography, :z)
65+
z = geography[:z]
66+
else
67+
z = nothing
68+
end
69+
if haskey(geography, :obstacles)
70+
obstacles = geography[:obstacles]
71+
else
72+
obstacles = nothing
73+
end
6674
z_is_friction = haskey(geography, :z_is_friction) && geography.z_is_friction === true
6775

6876
# New graph object components
@@ -172,9 +180,9 @@ function apply_geography(graph, geography; kwargs...)
172180
delta_tau_new[jo, io] *= op.along_obstacle_delta_tau
173181
along_obstacle[io, jo] = true
174182
along_obstacle[jo, io] = true
175-
# This should be redundant if the above block works as intended
176-
# across_obstacle[io, jo] = false
177-
# across_obstacle[jo, io] = false
183+
# This should be redundant if the above block works as intended:
184+
across_obstacle[io, jo] = false
185+
across_obstacle[jo, io] = false
178186
end
179187
end
180188
end

0 commit comments

Comments
 (0)