Skip to content

Commit a0d22c2

Browse files
committed
cleanup digraph generation
1 parent 909c6a8 commit a0d22c2

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

src/systems/dependency_graphs.jl

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,20 @@ end
7070

7171
# convert BipartiteGraph to LightGraph.SimpleDiGraph
7272
function digraph(g::BipartiteGraph, sys::AbstractSystem; variables = states(sys), equationsfirst = true)
73-
neqs = length(equations(sys))
74-
nvars = length(variables)
75-
73+
neqs = length(equations(sys))
74+
nvars = length(variables)
7675
fadjlist = deepcopy(g.fadjlist)
7776
badjlist = deepcopy(g.badjlist)
78-
if equationsfirst
79-
# variable indices must be incremented by neqs
80-
for i = 1:neqs
81-
fadjlist[i] .+= neqs
82-
end
83-
84-
# variables do not connect to anything
85-
append!(fadjlist, [Vector{Int}() for i=1:nvars])
86-
87-
# eqs have nothing that mapped to them
88-
prepend!(badjlist, [Vector{Int}() for i=1:neqs])
89-
else
90-
# equation indices must be incremented by nvars
91-
for i = 1:nvars
92-
fadjlist[i] .+= nvars
93-
end
9477

95-
# equations do not connect to anything
96-
append!(fadjlist, [Vector{Int}() for i=1:neqs])
97-
98-
# vars have nothing that mapped to them
99-
prepend!(badjlist, [Vector{Int}() for i=1:nvars])
78+
# offset is for determining indices for the second set of vertices
79+
offset = equationsfirst ? neqs : nvars
80+
for i = 1:offset
81+
fadjlist[i] .+= offset
10082
end
10183

84+
# add empty rows for vertices without connections
85+
append!(fadjlist, [Vector{Int}() for i=1:(equationsfirst ? nvars : neqs)])
86+
prepend!(badjlist, [Vector{Int}() for i=1:(equationsfirst ? neqs : nvars)])
87+
10288
SimpleDiGraph(g.ne, fadjlist, badjlist)
10389
end

0 commit comments

Comments
 (0)