Skip to content

Commit 2a64a93

Browse files
committed
Use BipartiteGraph interface in contract_variables
1 parent 0a74983 commit 2a64a93

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/structural_transformation/tearing.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,24 @@ function contract_variables(graph::BipartiteGraph, var_eq_matching::Matching, el
3838
[var_rename[v′] for v′ in neighborhood(dig, v, Inf; dir=:in) if var_rename[v′] != 0]
3939
end
4040

41-
new_fadjlist = Vector{Int}[
42-
let new_list = Vector{Int}()
43-
for v in graph.fadjlist[i]
44-
if var_rename[v] != 0
45-
push!(new_list, var_rename[v])
46-
else
47-
append!(new_list, var_deps[v])
41+
nelim = length(eliminated_variables)
42+
newgraph = BipartiteGraph(nsrcs(graph) - nelim, ndsts(graph) - nelim)
43+
for e in 𝑠vertices(graph)
44+
ne = eq_rename[e]
45+
ne == 0 && continue
46+
for v in 𝑠neighbors(graph, e)
47+
newvar = var_rename[v]
48+
if newvar != 0
49+
add_edge!(newgraph, ne, newvar)
50+
else
51+
for nv in var_deps[v]
52+
add_edge!(newgraph, ne, nv)
4853
end
4954
end
50-
new_list
51-
end for i = 1:nsrcs(graph) if eq_rename[i] != 0]
55+
end
56+
end
5257

53-
return BipartiteGraph(new_fadjlist, ndsts(graph) - length(eliminated_variables))
58+
return newgraph
5459
end
5560

5661
"""

0 commit comments

Comments
 (0)