@@ -45,7 +45,6 @@ function asgraph(sys::AbstractSystem; variables=nothing, variablestoids=nothing)
45
45
asgraph (eqdeps, vtois)
46
46
end
47
47
48
-
49
48
# for each variable determine the equations that modify it
50
49
function variable_dependencies (sys:: AbstractSystem ; variables= states (sys), variablestoids= nothing )
51
50
eqs = equations (sys)
@@ -62,10 +61,43 @@ function variable_dependencies(sys::AbstractSystem; variables=states(sys), varia
62
61
fadjlist = [Vector {Int} () for i = 1 : length (variables)]
63
62
ne = 0
64
63
for (eqidx,vidxs) in enumerate (badjlist)
65
- println (vidxs)
66
64
foreach (vidx -> push! (fadjlist[vidx], eqidx), vidxs)
67
65
ne += length (vidxs)
68
66
end
69
67
70
68
BipartiteGraph (ne, fadjlist, badjlist)
71
- end
69
+ end
70
+
71
+ # convert BipartiteGraph to LightGraph.SimpleDiGraph
72
+ function digraph (g:: BipartiteGraph , sys:: AbstractSystem ; variables = states (sys), equationsfirst = true )
73
+ neqs = length (equations (sys))
74
+ nvars = length (variables)
75
+
76
+ fadjlist = deepcopy (g. fadjlist)
77
+ 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
+
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])
100
+ end
101
+
102
+ SimpleDiGraph (g. ne, fadjlist, badjlist)
103
+ end
0 commit comments