Skip to content

Commit 4fb102f

Browse files
authored
Fix biconnected_components loses some edges (#100)
1 parent 075a01e commit 4fb102f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/biconnectivity/biconnect.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ function visit!(g::AbstractGraph, state::Biconnections{E}, u::Integer, v::Intege
3838
visit!(g, state, v, w)
3939
state.low[v] = min(state.low[v], state.low[w])
4040

41-
#Checking the root, and then the non-roots if they are articulation points
41+
# Checking the root, and then the non-roots if they are articulation points
4242
if (u == v && children > 1) || (u != v && state.low[w] >= state.depth[v])
43-
e = E(0, 0) #Invalid Edge, used for comparison only
43+
e = E(0, 0) # Invalid Edge, used for comparison only
4444
st = Vector{E}()
4545
while e != E(min(v, w), max(v, w))
4646
e = pop!(state.stack)
@@ -49,9 +49,13 @@ function visit!(g::AbstractGraph, state::Biconnections{E}, u::Integer, v::Intege
4949
push!(state.biconnected_comps, st)
5050
end
5151

52-
elseif w != u && state.low[v] > state.depth[w]
53-
push!(state.stack, E(min(v, w), max(v, w)))
54-
state.low[v] = state.depth[w]
52+
elseif w != u
53+
if state.depth[v] > state.depth[w]
54+
push!(state.stack, E(min(v, w), max(v, w)))
55+
end
56+
if state.low[v] > state.depth[w]
57+
state.low[v] = state.depth[w]
58+
end
5559
end
5660
end
5761
end

test/biconnectivity/biconnect.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,10 @@
4949
@test bcc == a
5050
@test typeof(bcc) === Vector{Vector{Edge{eltype(g)}}}
5151
end
52+
53+
# Non regression test for #13
54+
g = complete_graph(4)
55+
a = [[Edge(2,4), Edge(1,4), Edge(3,4), Edge(1,3), Edge(2,3), Edge(1,2)]]
56+
bcc = @inferred(biconnected_components(g))
57+
@test bcc == a
5258
end

0 commit comments

Comments
 (0)