@@ -90,7 +90,7 @@ function apply_geography(graph, geography; kwargs...)
9090 end
9191
9292 # Remove edges where geographical barriers are (rivers)
93- remove_edge = false
93+ # remove_edge = false
9494 if obstacles != = nothing
9595
9696 # Store initial delta matrics (avoid double counting)
@@ -102,9 +102,9 @@ function apply_geography(graph, geography; kwargs...)
102102 across_obstacle = falses (graph. J, graph. J)
103103 along_obstacle = falses (graph. J, graph. J)
104104 remove_edge = isinf (op. across_obstacle_delta_i) || isinf (op. across_obstacle_delta_tau) # remove the edge
105- if remove_edge
106- rm_nodes = falses (graph. J)
107- end
105+ # if remove_edge
106+ # rm_nodes = falses(graph.J)
107+ # end
108108
109109 for i in 1 : graph. J
110110 neighbors = graph. nodes[i]
@@ -135,16 +135,16 @@ function apply_geography(graph, geography; kwargs...)
135135 rmi = findfirst (== (i), nodes_new[j])
136136 if rmi != = nothing
137137 deleteat! (nodes_new[j], rmi)
138- if isempty (nodes_new[j])
139- rm_nodes[j] = true # deleteat!(nodes_new, j)
140- end
138+ # if isempty(nodes_new[j])
139+ # rm_nodes[j] = true # deleteat!(nodes_new, j)
140+ # end
141141 end
142142 rmj = findfirst (== (j), nodes_new[i])
143143 if rmj != = nothing
144144 deleteat! (nodes_new[i], rmj)
145- if isempty (nodes_new[i])
146- rm_nodes[i] = true # deleteat!(nodes_new, i)
147- end
145+ # if isempty(nodes_new[i])
146+ # rm_nodes[i] = true # deleteat!(nodes_new, i)
147+ # end
148148 end
149149
150150 adjacency_new[i, j] = false
@@ -174,16 +174,16 @@ function apply_geography(graph, geography; kwargs...)
174174 rmio = findfirst (== (io), nodes_new[jo])
175175 if rmio != = nothing
176176 deleteat! (nodes_new[jo], rmio)
177- if isempty (nodes_new[jo])
178- rm_nodes[jo] = true # deleteat!(nodes_new, jo)
179- end
177+ # if isempty(nodes_new[jo])
178+ # rm_nodes[jo] = true # deleteat!(nodes_new, jo)
179+ # end
180180 end
181181 rmjo = findfirst (== (jo), nodes_new[io])
182182 if rmjo != = nothing
183183 deleteat! (nodes_new[io], rmjo)
184- if isempty (nodes_new[io])
185- rm_nodes[io] = true # deleteat!(nodes_new, io)
186- end
184+ # if isempty(nodes_new[io])
185+ # rm_nodes[io] = true # deleteat!(nodes_new, io)
186+ # end
187187 end
188188 adjacency_new[io, jo] = false
189189 adjacency_new[jo, io] = false
@@ -206,47 +206,60 @@ function apply_geography(graph, geography; kwargs...)
206206 # Creating new object
207207 graph_new = namedtuple_to_dict (graph)
208208
209- if remove_edge && any (rm_nodes)
210- keep = findall (.! rm_nodes)
211- graph_new[:delta_i ] = delta_i_new[keep, keep]
212- graph_new[:delta_tau ] = delta_tau_new[keep, keep]
213- graph_new[:nodes ] = nodes_new[keep]
214- graph_new[:adjacency ] = adjacency_new[keep, keep]
215- # make sure that the degrees of freedom of the updated graph match the # of links
216- graph_new[:ndeg ] = sum (tril (graph_new[:adjacency ]))
217- graph_new[:across_obstacle ] = across_obstacle[keep, keep]
218- graph_new[:along_obstacle ] = along_obstacle[keep, keep]
209+ # if remove_edge && any(rm_nodes)
210+ # keep = findall(.!rm_nodes)
211+ # graph_new[:x_orig] = graph[:x]
212+ # graph_new[:x] = graph[:x][keep]
213+ # graph_new[:y_orig] = graph[:y]
214+ # graph_new[:y] = graph[:y][keep]
215+ # graph_new[:J] = length(graph_new[:x])
216+ # graph_new[:rm_nodes] = rm_nodes
217+ # graph_new[:delta_i] = delta_i_new[keep, keep]
218+ # graph_new[:delta_tau] = delta_tau_new[keep, keep]
219+ # nodes_new = nodes_new[keep]
220+ # for i in keep
221+ # for k in 1:length(nodes_new)
222+ # node_k = filter(x -> x != i, nodes_new[k])
223+ # nodes_new[k] = ifelse.(node_k .> i, node_k .- 1, node_k) # reindex nodes k > i to k-1
224+ # end
225+ # end
226+ # graph_new[:nodes] = nodes_new
227+ # graph_new[:adjacency] = adjacency_new[keep, keep]
228+ # # make sure that the degrees of freedom of the updated graph match the # of links
229+ # graph_new[:ndeg] = sum(tril(graph_new[:adjacency]))
230+ # graph_new[:across_obstacle] = across_obstacle[keep, keep]
231+ # graph_new[:along_obstacle] = along_obstacle[keep, keep]
219232
220- if haskey (graph, :Lj )
221- graph_new[:Lj ] = graph[:Lj ][keep]
222- end
223- if haskey (graph, :Hj )
224- graph_new[:Hj ] = graph[:Hj ][keep]
225- end
226- if haskey (graph, :hj )
227- graph_new[:hj ] = graph_new[:Hj ] ./ graph_new[:Lj ]
228- end
229- if haskey (graph, :omegaj )
230- graph_new[:omegaj ] = graph[:omegaj ][keep]
231- end
232- if haskey (graph, :Zjn )
233- graph_new[:Zjn ] = graph[:Zjn ][keep, :]
234- end
235- if haskey (graph, :region )
236- graph_new[:region ] = graph[:region ][keep]
237- end
238- else
239- graph_new[:delta_i ] = delta_i_new
240- graph_new[:delta_tau ] = delta_tau_new
241- if obstacles != = nothing
242- graph_new[:nodes ] = nodes_new
243- graph_new[:adjacency ] = adjacency_new
244- # make sure that the degrees of freedom of the updated graph match the # of links
245- graph_new[:ndeg ] = sum (tril (adjacency_new))
246- graph_new[:across_obstacle ] = across_obstacle
247- graph_new[:along_obstacle ] = along_obstacle
248- end
233+ # if haskey(graph, :Lj)
234+ # graph_new[:Lj] = graph[:Lj][keep]
235+ # end
236+ # if haskey(graph, :Hj)
237+ # graph_new[:Hj] = graph[:Hj][keep]
238+ # end
239+ # if haskey(graph, :hj)
240+ # graph_new[:hj] = graph_new[:Hj] ./ graph_new[:Lj]
241+ # end
242+ # if haskey(graph, :omegaj)
243+ # graph_new[:omegaj] = graph[:omegaj][keep]
244+ # end
245+ # if haskey(graph, :Zjn)
246+ # graph_new[:Zjn] = graph[:Zjn][keep, :]
247+ # end
248+ # if haskey(graph, :region)
249+ # graph_new[:region] = graph[:region][keep]
250+ # end
251+ # else
252+ graph_new[:delta_i ] = delta_i_new
253+ graph_new[:delta_tau ] = delta_tau_new
254+ if obstacles != = nothing
255+ graph_new[:nodes ] = nodes_new
256+ graph_new[:adjacency ] = adjacency_new
257+ # make sure that the degrees of freedom of the updated graph match the # of links
258+ graph_new[:ndeg ] = sum (tril (adjacency_new))
259+ graph_new[:across_obstacle ] = across_obstacle
260+ graph_new[:along_obstacle ] = along_obstacle
249261 end
262+ # end
250263
251264 return graph_new
252265end
0 commit comments