diff --git a/models/ER.jl b/models/ER.jl index e6f63ace4af939805f6bec0dff3c5331cdf8ba1c..eb0d4676a929a93bc51e6d2eeb73ed1afc3ad5d3 100644 --- a/models/ER.jl +++ b/models/ER.jl @@ -1,5 +1,4 @@ - import StaticArrays: SVector, SMatrix, @SMatrix d=4 @@ -7,11 +6,12 @@ k=3 dict_var = Dict("E" => 1, "S" => 2, "ES" => 3, "P" => 4) dict_p = Dict("k1" => 1, "k2" => 2, "k3" => 3) l_tr = ["R1","R2","R3"] -p = SVector{3, Float64}(1.0, 1.0, 1.0) -x0 = SVector{4, Int}(100, 100, 0, 0) +p = [1.0, 1.0, 1.0] +x0 = [100, 100, 0, 0] t0 = 0.0 -function f(xn::SVector{4, Int}, tn::Float64, p::SVector{3, Float64}) +function f!(xnplus1::Vector{Int}, tnplus1::Vector{Float64}, tr::Vector{String}, + xn::Vector{Int}, tn::Float64, p::Vector{Float64}) a1 = p[1] * xn[1] * xn[2] a2 = p[2] * xn[3] a3 = p[3] * xn[3] @@ -35,17 +35,18 @@ function f(xn::SVector{4, Int}, tn::Float64, p::SVector{3, Float64}) b_sup += l_a[i+1] end - nu = l_nu[:,reaction] - xnplus1 = SVector{4, Int}(xn[1]+nu[1], xn[2]+nu[2], xn[3]+nu[3], xn[4]+nu[4]) - tnplus1 = tn + tau - transition = "R$(reaction)" - - return xnplus1, tnplus1, transition + nu = @view l_nu[:,reaction] + xnplus1[1] = xn[1]+nu[1] + xnplus1[2] = xn[2]+nu[2] + xnplus1[3] = xn[3]+nu[3] + xnplus1[4] = xn[4]+nu[4] + tnplus1[1] = tn + tau + tr[1] = "R$(reaction)" end -is_absorbing_er(p::SVector{3, Float64},xn::SVector{4, Int}) = - (p[1]*xn[1]*xn[2] + (p[2]+p[3])*xn[3]) == 0.0 -g = SVector("P") +is_absorbing_er(p::Vector{Float64},xn::Vector{Int}) = + (p[1]*xn[1]*xn[2] + (p[2]+p[3])*xn[3]) === 0.0 +g = ["P"] -ER = CTMC(d,k,dict_var,dict_p,l_tr,p,x0,t0,f,is_absorbing_er; g=g) +ER = CTMC(d,k,dict_var,dict_p,l_tr,p,x0,t0,f!,is_absorbing_er; g=g) export ER diff --git a/models/SIR.jl b/models/SIR.jl index 476e3da8edf627b573fe8923c5e7ad2912d7dfb7..7416631b94d471155178b23f2195376b4173ba29 100644 --- a/models/SIR.jl +++ b/models/SIR.jl @@ -40,8 +40,6 @@ function f!(xnplus1::Vector{Int}, tnplus1::Vector{Float64}, tr::Vector{String}, xnplus1[3] = xn[3]+nu[3] tnplus1[1] = tn + tau tr[1] = "R$(reaction)" - - #return xnplus1, tnplus1, transition end is_absorbing_sir(p::Vector{Float64}, xn::Vector{Int}) = (p[1]*xn[1]*xn[2] + p[2]*xn[2]) === 0.0 g = ["I"]