@@ -2419,30 +2419,32 @@ end
2419
2419
computes the connected components of the network graph
2420
2420
returns a set of sets of bus ids, each set is a connected component
2421
2421
"""
2422
- function calc_connected_components (data:: Dict{String,<:Any} ; edges= [" branch" , " dcline" ])
2422
+ function calc_connected_components (data:: Dict{String,<:Any} ; edges= [" branch" , " dcline" , " switch " ])
2423
2423
if InfrastructureModels. ismultinetwork (data)
2424
2424
Memento. error (_LOGGER, " connected_components does not yet support multinetwork data" )
2425
2425
end
2426
2426
2427
2427
active_bus = Dict (x for x in data[" bus" ] if x. second[" bus_type" ] != 4 )
2428
2428
active_bus_ids = Set {Int64} ([bus[" bus_i" ] for (i,bus) in active_bus])
2429
2429
2430
- neighbors = Dict (i => [] for i in active_bus_ids)
2431
- for line_type in edges
2432
- for line in values (get (data, line_type, Dict ()))
2433
- if get (line, " br_status" , 1 ) != 0 && line[" f_bus" ] in active_bus_ids && line[" t_bus" ] in active_bus_ids
2434
- push! (neighbors[line[" f_bus" ]], line[" t_bus" ])
2435
- push! (neighbors[line[" t_bus" ]], line[" f_bus" ])
2430
+ neighbors = Dict (i => Int[] for i in active_bus_ids)
2431
+ for comp_type in edges
2432
+ status_key = get (pm_component_status, comp_type, " status" )
2433
+ status_inactive = get (pm_component_status_inactive, comp_type, 0 )
2434
+ for edge in values (get (data, comp_type, Dict ()))
2435
+ if get (edge, status_key, 1 ) != status_inactive && edge[" f_bus" ] in active_bus_ids && edge[" t_bus" ] in active_bus_ids
2436
+ push! (neighbors[edge[" f_bus" ]], edge[" t_bus" ])
2437
+ push! (neighbors[edge[" t_bus" ]], edge[" f_bus" ])
2436
2438
end
2437
2439
end
2438
2440
end
2439
2441
2440
- component_lookup = Dict (i => Set {Int64 } ([i]) for i in active_bus_ids)
2442
+ component_lookup = Dict (i => Set {Int } ([i]) for i in active_bus_ids)
2441
2443
touched = Set {Int64} ()
2442
2444
2443
2445
for i in active_bus_ids
2444
2446
if ! (i in touched)
2445
- _dfs (i, neighbors, component_lookup, touched)
2447
+ _cc_dfs (i, neighbors, component_lookup, touched)
2446
2448
end
2447
2449
end
2448
2450
@@ -2453,17 +2455,19 @@ end
2453
2455
2454
2456
2455
2457
"""
2456
- perModels DFS on a graph
2458
+ DFS on a graph
2457
2459
"""
2458
- function _dfs (i, neighbors, component_lookup, touched)
2460
+ function _cc_dfs (i, neighbors, component_lookup, touched)
2459
2461
push! (touched, i)
2460
2462
for j in neighbors[i]
2461
2463
if ! (j in touched)
2462
- new_comp = union (component_lookup[i], component_lookup[j])
2463
- for k in new_comp
2464
- component_lookup[k] = new_comp
2464
+ for k in component_lookup[j]
2465
+ push! (component_lookup[i], k)
2465
2466
end
2466
- _dfs (j, neighbors, component_lookup, touched)
2467
+ for k in component_lookup[j]
2468
+ component_lookup[k] = component_lookup[i]
2469
+ end
2470
+ _cc_dfs (j, neighbors, component_lookup, touched)
2467
2471
end
2468
2472
end
2469
2473
end
0 commit comments