Skip to content
Snippets Groups Projects
Commit bf7e270e authored by Bentriou Mahmoud's avatar Bentriou Mahmoud
Browse files

Same changes for ER model

parent d690d6b9
No related branches found
No related tags found
No related merge requests found
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
......@@ -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"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment