@@ -23,22 +23,22 @@ rxs = [Reaction(β, [S,I], [I], [1,1], [2]),
23
23
rs = ReactionSystem(rxs, t, [S,I,R], [β,γ,κ,η])
24
24
25
25
# ODEs:
26
- os = convert(ODESystem, rs)
26
+ odesys = convert(ODESystem, rs)
27
27
28
28
# dependency of each ODE on state variables
29
- equation_dependencies(os )
29
+ equation_dependencies(odesys )
30
30
31
31
# dependency of each ODE on parameters
32
- equation_dependencies(os , variables=parameters(os ))
32
+ equation_dependencies(odesys , variables=parameters(odesys ))
33
33
34
34
# Jumps
35
- js = convert(JumpSystem, rs)
35
+ jumpsys = convert(JumpSystem, rs)
36
36
37
37
# dependency of each jump rate function on state variables
38
- equation_dependencies(js )
38
+ equation_dependencies(jumpsys )
39
39
40
40
# dependency of each jump rate function on parameters
41
- equation_dependencies(js , variables=parameters(js ))
41
+ equation_dependencies(jumpsys , variables=parameters(jumpsys ))
42
42
```
43
43
"""
44
44
function equation_dependencies (sys:: AbstractSystem ; variables= states (sys))
@@ -104,7 +104,7 @@ asgraph(eqdeps, vtois)
104
104
```
105
105
106
106
Convert a collection of equation dependencies, for example as returned by
107
- `equation_dependencies`, to a `BipartiteGraph`.
107
+ `equation_dependencies`, to a [ `BipartiteGraph`](@ref) .
108
108
109
109
Notes:
110
110
- `vtois` should provide `Dict` like mapping from variable dependency in `eqdeps`
@@ -113,7 +113,7 @@ Notes:
113
113
Example:
114
114
Continuing the example started in [`equation_dependencies`](@ref)
115
115
```julia
116
- digr = asgraph(equation_dependencies(os ), Dict(s => i for (i,s) in enumerate(states(os ))))
116
+ digr = asgraph(equation_dependencies(odesys ), Dict(s => i for (i,s) in enumerate(states(odesys ))))
117
117
```
118
118
"""
119
119
function asgraph (eqdeps, vtois)
@@ -140,35 +140,47 @@ asgraph(sys::AbstractSystem; variables=states(sys),
140
140
variablestoids=Dict(convert(Variable, v) => i for (i,v) in enumerate(variables)))
141
141
```
142
142
143
- Convert an `AbstractSystem` to a `BipartiteGraph` mapping equations
143
+ Convert an `AbstractSystem` to a [ `BipartiteGraph`](@ref) mapping equations
144
144
to variables they depend on.
145
145
146
146
Notes:
147
147
- Defaults for kwargs creating a mapping from `equations(sys)` to `states(sys)`
148
148
they depend on.
149
149
- `variables` should provide the list of variables to use for generating
150
150
the dependency graph.
151
- - `variablestoids` should provide `Dict` like mapping from a variable to its
152
- integer index within `variables`.
151
+ - `variablestoids` should provide `Dict` like mapping from a `Variable` to its
152
+ `Int` index within `variables`.
153
153
154
154
Example:
155
155
Continuing the example started in [`equation_dependencies`](@ref)
156
156
```julia
157
- digr = asgraph(os )
157
+ digr = asgraph(odesys )
158
158
```
159
159
"""
160
160
function asgraph (sys:: AbstractSystem ; variables= states (sys),
161
161
variablestoids= Dict (convert (Variable, v) => i for (i,v) in enumerate (variables)))
162
162
asgraph (equation_dependencies (sys, variables= variables), variablestoids)
163
163
end
164
- # function asgraph(sys::AbstractSystem; variables=nothing, variablestoids=nothing)
165
- # vs = isnothing(variables) ? states(sys) : variables
166
- # eqdeps = equation_dependencies(sys, variables=vs)
167
- # vtois = isnothing(variablestoids) ? Dict(convert(Variable, v) => i for (i,v) in enumerate(vs)) : variablestoids
168
- # asgraph(eqdeps, vtois)
169
- # end
170
-
171
- # for each variable determine the equations that modify it
164
+
165
+ """
166
+ ```julia
167
+ variable_dependencies(sys::AbstractSystem; variables=states(sys), variablestoids=nothing)
168
+ ```
169
+
170
+ For each variable determine the equations that modify it and return as a [`BipartiteGraph`](@ref).
171
+
172
+ Notes:
173
+ - Dependencies are returned as a [`BipartiteGraph`](@ref) mapping variable
174
+ indices to the indices of equations that map to them.
175
+ - `variables` denotes the list of variables to determine dependencies for.
176
+ - `variablestoids` denotes a `Dict` mapping `Variable`s to `Int`s.
177
+
178
+ Example:
179
+ Continuing the example of [`equation_dependencies`](@ref)
180
+ ```julia
181
+ variable_dependencies(odesys)
182
+ ```
183
+ """
172
184
function variable_dependencies (sys:: AbstractSystem ; variables= states (sys), variablestoids= nothing )
173
185
eqs = equations (sys)
174
186
vtois = isnothing (variablestoids) ? Dict (convert (Variable, v) => i for (i,v) in enumerate (variables)) : variablestoids
@@ -192,12 +204,30 @@ function variable_dependencies(sys::AbstractSystem; variables=states(sys), varia
192
204
end
193
205
194
206
"""
207
+ ```julia
208
+ asdigraph(g::BipartiteGraph, sys::AbstractSystem; variables = states(sys), equationsfirst = true)
209
+ ```
210
+
211
+ Convert a [`BipartiteGraph`](@ref) to a `LightGraph.SimpleDiGraph`.
212
+
213
+ Notes:
195
214
- The resulting `SimpleDiGraph` unifies the two sets of vertices (equations
196
- and then states in the case `eqdeps` comes from `equation_dependencies`), producing
197
- one ordered set of integer vertices (as `SimpleDiGraph` does not support two distinct
198
- collections of nodes.
215
+ and then states in the case it comes from [`asgraph`](@ref)), producing one
216
+ ordered set of integer vertices (`SimpleDiGraph` does not support two distinct
217
+ collections of vertices so they must be merged).
218
+ - `variables` gives the variables that `g` is associated with (usually the
219
+ `states` of a system).
220
+ - `equationsfirst` (default is `true`) gives whether the [`BipartiteGraph`](@ref)
221
+ gives a mapping from equations to variables they depend on (`true`), as calculated
222
+ by [`asgraph`](@ref), or whether it gives a mapping from variables to the equations
223
+ that modify them, as calculated by [`variable_dependencies`](@ref).
224
+
225
+ Example:
226
+ Continuing the example in [`asgraph`](@ref)
227
+ ```julia
228
+ dg = asdigraph(digr)
229
+ ```
199
230
"""
200
- # convert BipartiteGraph to LightGraph.SimpleDiGraph
201
231
function asdigraph (g:: BipartiteGraph , sys:: AbstractSystem ; variables = states (sys), equationsfirst = true )
202
232
neqs = length (equations (sys))
203
233
nvars = length (variables)
@@ -217,7 +247,25 @@ function asdigraph(g::BipartiteGraph, sys::AbstractSystem; variables = states(sy
217
247
SimpleDiGraph (g. ne, fadjlist, badjlist)
218
248
end
219
249
220
- # maps the i'th eq to equations that depend on it
250
+ """
251
+ ```julia
252
+ eqeq_dependencies(eqdeps::BipartiteGraph{T}, vardeps::BipartiteGraph{T}) where {T <: Integer}
253
+ ```
254
+
255
+ Calculate a `LightGraph.SimpleDiGraph` that maps each equation to equations they depend on.
256
+
257
+ Notes:
258
+ - The `fadjlist` of the `SimpleDiGraph` maps from an equation to the equations that
259
+ modify variables it depends on.
260
+ - The `badjlist` of the `SimpleDiGraph` maps from an equation to equations that
261
+ depend on variables it modifies.
262
+
263
+ Example:
264
+ Continuing the example of `equation_dependencies`
265
+ ```julia
266
+ eqeqdep = eqeq_dependencies(asgraph(odesys), variable_dependencies(odesys))
267
+ ```
268
+ """
221
269
function eqeq_dependencies (eqdeps:: BipartiteGraph{T} , vardeps:: BipartiteGraph{T} ) where {T <: Integer }
222
270
g = SimpleDiGraph {T} (length (eqdeps. fadjlist))
223
271
@@ -232,5 +280,23 @@ function eqeq_dependencies(eqdeps::BipartiteGraph{T}, vardeps::BipartiteGraph{T}
232
280
g
233
281
end
234
282
235
- # maps the i'th variable to variables that depend on it
283
+ """
284
+ ```julia
285
+ varvar_dependencies(eqdeps::BipartiteGraph{T}, vardeps::BipartiteGraph{T}) where {T <: Integer} = eqeq_dependencies(vardeps, eqdeps)
286
+ ```
287
+
288
+ Calculate a `LightGraph.SimpleDiGraph` that maps each variable to variables they depend on.
289
+
290
+ Notes:
291
+ - The `fadjlist` of the `SimpleDiGraph` maps from a variable to the variables that
292
+ depend on it.
293
+ - The `badjlist` of the `SimpleDiGraph` maps from a variable to variables on which
294
+ it depends.
295
+
296
+ Example:
297
+ Continuing the example of `equation_dependencies`
298
+ ```julia
299
+ varvardep = varvar_dependencies(asgraph(odesys), variable_dependencies(odesys))
300
+ ```
301
+ """
236
302
varvar_dependencies (eqdeps:: BipartiteGraph{T} , vardeps:: BipartiteGraph{T} ) where {T <: Integer } = eqeq_dependencies (vardeps, eqdeps)
0 commit comments