|
70 | 70 |
|
71 | 71 | # convert BipartiteGraph to LightGraph.SimpleDiGraph
|
72 | 72 | 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) |
76 | 75 | fadjlist = deepcopy(g.fadjlist)
|
77 | 76 | 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 |
94 | 77 |
|
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 |
100 | 82 | end
|
101 | 83 |
|
| 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 | + |
102 | 88 | SimpleDiGraph(g.ne, fadjlist, badjlist)
|
103 | 89 | end
|
0 commit comments