|
|
|
@ -154,30 +154,27 @@ risk_map = tile_map(risk_map)
|
|
|
|
#println()
|
|
|
|
#println()
|
|
|
|
#exit()
|
|
|
|
#exit()
|
|
|
|
|
|
|
|
|
|
|
|
function neighbor_idx(nrows, ncols, y, x)
|
|
|
|
function relax(nrows, ncols, R, costs, row, col; first=false)
|
|
|
|
v = CartesianIndex[]
|
|
|
|
c1 = costs[row, col]
|
|
|
|
if x > 1
|
|
|
|
c = c1
|
|
|
|
push!(v, CartesianIndex(y, x-1))
|
|
|
|
if col > 1
|
|
|
|
end
|
|
|
|
c = min(c, costs[row, col-1] + R[row, col])
|
|
|
|
if x < ncols
|
|
|
|
|
|
|
|
push!(v, CartesianIndex(y, x+1))
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if y > 1
|
|
|
|
if col < ncols
|
|
|
|
push!(v, CartesianIndex(y-1, x))
|
|
|
|
c = min(c, costs[row, col+1] + R[row, col])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if y < nrows
|
|
|
|
if row > 1
|
|
|
|
push!(v, CartesianIndex(y+1, x))
|
|
|
|
c = min(c, costs[row-1, col] + R[row, col])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return v
|
|
|
|
if row < nrows
|
|
|
|
|
|
|
|
c = min(c, costs[row+1, col] + R[row, col])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function relax(nrows, ncols, R, costs, row, col; first=false)
|
|
|
|
if c < c1
|
|
|
|
idx = neighbor_idx(nrows, ncols, row, col)
|
|
|
|
|
|
|
|
c = minimum(costs[i] for i in idx) + R[row, col]
|
|
|
|
|
|
|
|
if first || c < costs[row, col]
|
|
|
|
|
|
|
|
costs[row, col] = c
|
|
|
|
costs[row, col] = c
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@ -233,7 +230,7 @@ function get_costs(R)
|
|
|
|
return costs, dirs
|
|
|
|
return costs, dirs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
costs, dirs = get_costs(risk_map)
|
|
|
|
@time costs, dirs = get_costs(risk_map)
|
|
|
|
|
|
|
|
|
|
|
|
if length(costs) < 1000
|
|
|
|
if length(costs) < 1000
|
|
|
|
display(costs)
|
|
|
|
display(costs)
|
|
|
|
|