11import DynamicalSystemsBase: get_state, set_state!
22
33using AbstractTrees: Leaves
4- using DynamicalSystemsBase: ArbitrarySteppable
4+ using DynamicalSystemsBase: ArbitrarySteppable, current_parameters, initial_state
55using HerbConstraints: addconstraint!, DomainRuleNode, VarNode, Ordered, Forbidden
66using HerbCore: AbstractGrammar, RuleNode, get_rule
77using HerbGrammar: add_rule!, rulenode2expr, @csgrammar
88using HerbSearch: rand
99using MLStyle: @match
1010using MetaGraphsNext: MetaGraph, SimpleDiGraph, add_edge!, nv, labels
11+ import SciMLBase
12+ using StaticArrays: MVector
1113
1214base_qn_grammar = @csgrammar begin
1315 Val = Val + Val
@@ -202,11 +204,11 @@ with an [`ArbitrarySteppable`](https://juliadynamics.github.io/DynamicalSystems.
202204from [`DynamicalSystems`](https://juliadynamics.github.io/DynamicalSystems.jl/stable/).
203205See [`aqn`](@ref) for an example.
204206"""
205- struct QualitativeNetwork
207+ struct QualitativeNetwork{N,C}
206208 " Graph containing the topology and target functions of the network"
207209 graph:: MetaGraph
208210 " State of the network"
209- state:: AbstractVector{ Int}
211+ state:: MVector{C, Int}
210212 " The maximum activation level/state value of any component"
211213 N:: Int
212214
@@ -215,7 +217,7 @@ struct QualitativeNetwork
215217 error (" All values in state must be <= N (N=$N )" )
216218 end
217219
218- return new (g, s, N)
220+ return new {N,length(s)} (g, s, N)
219221 end
220222end
221223
306308"""
307309 $(TYPEDSIGNATURES)
308310"""
309- function limit_change (prev_value, next_value, N:: Int )
311+ function limit_change (prev_value, next_value, N:: Integer )
310312 if next_value > prev_value
311313 limited_value = min (prev_value + 1 , N)
312314 elseif next_value < prev_value
@@ -315,7 +317,7 @@ function limit_change(prev_value, next_value, N::Int)
315317 limited_value = next_value
316318 end
317319
318- return round (Int, limited_value)
320+ return limited_value
319321end
320322
321323"""
@@ -335,6 +337,17 @@ extract_state(model::QN) = model.state
335337extract_parameters (model:: QN ) = model. graph
336338reset_model! (model:: QN , u, _) = model. state .= u
337339
340+ function SciMLBase. reinit! (
341+ ds:: ArbitrarySteppable{<:AbstractVector{<:Real},<:QualitativeNetwork} ,
342+ u:: AbstractVector{<:Real} = initial_state (ds);
343+ p = current_parameters (ds),
344+ t0 = 0 , # t0 is not used but required for downstream.
345+ )
346+ ds. reinit (ds. model, u, p)
347+ ds. t[] = 0
348+ return ds
349+ end
350+
338351"""
339352 $(TYPEDSIGNATURES)
340353
0 commit comments