@@ -103,6 +103,7 @@ function DiffEqBase.DiscreteProblem(sys::AbstractSystem, u0map, tspan::Tuple,
103
103
DiscreteProblem (df, u0, tspan, p; kwargs... )
104
104
end
105
105
106
+
106
107
"""
107
108
```julia
108
109
function DiffEqBase.JumpProblem(js::JumpSystem, prob, aggregator; kwargs...)
@@ -111,59 +112,34 @@ function DiffEqBase.JumpProblem(js::JumpSystem, prob, aggregator; kwargs...)
111
112
Generates a JumpProblem from a JumpSystem.
112
113
"""
113
114
function DiffEqJump. JumpProblem (js:: JumpSystem , prob, aggregator; kwargs... )
114
- vrjs = Vector {VariableRateJump} ()
115
- crjs = Vector {ConstantRateJump} ()
116
- majs = Vector {MassActionJump} ()
117
- pvars = parameters (js)
118
- statetoid = Dict (convert (Variable,state) => i for (i,state) in enumerate (states (js)))
119
- parammap = map ((x,y)-> Pair (x (),y),pvars,prob. p)
120
- eqs = equations (js)
121
115
122
- foreach (j -> push! (majs, assemble_maj (js, j, statetoid, parammap)), eqs . x[ 1 ])
123
- foreach (j -> push! (crjs, assemble_crj (js, j, statetoid)), eqs . x[ 2 ])
124
- foreach (j -> push! (vrjs, assemble_vrj (js, j, statetoid)), eqs . x[ 3 ])
116
+ statetoid = Dict ( convert (Variable,state) => i for (i,state) in enumerate ( states (js)))
117
+ parammap = map ((x,y) -> Pair ( x (),y), parameters (js), prob . p)
118
+ eqs = equations (js)
125
119
120
+ majs = MassActionJump[assemble_maj (js, j, statetoid, parammap) for j in eqs. x[1 ]]
121
+ crjs = ConstantRateJump[assemble_crj (js, j, statetoid) for j in eqs. x[2 ]]
122
+ vrjs = VariableRateJump[assemble_vrj (js, j, statetoid) for j in eqs. x[3 ]]
126
123
((prob isa DiscreteProblem) && ! isempty (vrjs)) && error (" Use continuous problems such as an ODEProblem or a SDEProblem with VariableRateJumps" )
124
+
127
125
jset = JumpSet (Tuple (vrjs), Tuple (crjs), nothing , isempty (majs) ? nothing : majs)
128
126
JumpProblem (prob, aggregator, jset)
129
127
end
130
128
131
129
132
- # ## Functions to determine which jumps depend on a given state
130
+ # ## Functions to determine which states a jump depends on
133
131
134
- function ratevars ! (dep, jump:: Union{ConstantRateJump,VariableRateJump} , sts)
132
+ function extract_variables ! (dep, jump:: Union{ConstantRateJump,VariableRateJump} , sts)
135
133
foreach (st -> (convert (Variable,st) in sts) && push! (dep,st), vars (jump. rate))
134
+ dep
136
135
end
137
136
138
- function ratevars! (dep, jump:: MassActionJump , args... )
139
- foreach (st -> push! (dep,convert (Variable,st[1 ])), jump. reactant_stoch)
140
- end
141
-
142
- function ratevars (jump, sts)
143
- dep = Set {Variable} ()
144
- ratevars! (dep,jump,sts)
137
+ function extract_variables! (dep, jump:: MassActionJump , args... )
138
+ foreach (st -> push! (dep,convert (Variable,st[1 ])), jump. reactant_stoch)
145
139
dep
146
140
end
147
141
148
- # map each state (as an Int index) to the jumps with a rate that depend on it
149
- function statetojump_depgraph (js:: JumpSystem , statestoids = nothing )
150
- sts = states (js)
151
- stoi = isnothing (statestoids) ? Dict (convert (Variable,state) => i for (i,state) in enumerate (sts)) : statestoids
152
142
153
- # map from jump to states (as Variables) it depends on through the rate
154
- deps = [ratevars (eq,sts) for eq in equations (js)]
155
-
156
- # reverse map and switch to integer indices of states
157
- dg = [Vector {Int} () for i = 1 : length (sts)]
158
- for (k,dep) in enumerate (deps)
159
- for state in dep
160
- push! (dg[stoi[state]],k)
161
- end
162
- end
163
- foreach (dep -> sort! (dep), dg)
164
-
165
- dg
166
- end
167
143
168
144
# ## Functions to determine which states are modified by a given jump
169
145
0 commit comments