From 70407040f13c8a89effa73acc60fc63d5efdec39 Mon Sep 17 00:00:00 2001 From: Mahmoud Bentriou <mahmoud.bentriou@centralesupelec.fr> Date: Sat, 5 Dec 2020 13:04:28 +0100 Subject: [PATCH] Modification of sir_tauleap for new simulate functions + add of simulation tests for sir_tauleap and poisson. --- models/SIR_tauleap.jl | 4 ++++ tests/run_simulation.jl | 2 ++ tests/simulation/sim_poisson.jl | 10 ++++++++++ tests/simulation/sim_sir_tauleap.jl | 10 ++++++++++ 4 files changed, 26 insertions(+) create mode 100644 tests/simulation/sim_poisson.jl create mode 100644 tests/simulation/sim_sir_tauleap.jl diff --git a/models/SIR_tauleap.jl b/models/SIR_tauleap.jl index b5dfd51..6dac452 100644 --- a/models/SIR_tauleap.jl +++ b/models/SIR_tauleap.jl @@ -17,6 +17,10 @@ function SIR_tauleap_f!(xnplus1::Vector{Int}, l_t::Vector{Float64}, l_tr::Vector a2 = p[2] * xn[2] l_a = SVector(a1, a2) asum = sum(l_a) + if asum == 0.0 + copyto!(xnplus1, xn) + return nothing + end # column-major order nu_1 = SVector(-1, 1, 0) nu_2 = SVector(0, -1, 1) diff --git a/tests/run_simulation.jl b/tests/run_simulation.jl index 5dee590..80d3cb3 100644 --- a/tests/run_simulation.jl +++ b/tests/run_simulation.jl @@ -14,5 +14,7 @@ if !isdir(str_dir_pics) mkdir(str_dir_pics) end @test include("simulation/sim_er_row_buffer_bounded.jl") @test include("simulation/sim_pm_er.jl") @test include("simulation/sim_pm_sync_er.jl") + @test include("simulation/sim_sir_tauleap.jl") + @test include("simulation/sim_poisson.jl") end diff --git a/tests/simulation/sim_poisson.jl b/tests/simulation/sim_poisson.jl new file mode 100644 index 0000000..40aa61d --- /dev/null +++ b/tests/simulation/sim_poisson.jl @@ -0,0 +1,10 @@ + +using MarkovProcesses +load_plots() + +load_model("poisson") +σ = simulate(poisson) +MarkovProcesses.plot(σ; filename = get_module_path() * "/tests/simulation/res_pics/sim_poisson.png") + +return true + diff --git a/tests/simulation/sim_sir_tauleap.jl b/tests/simulation/sim_sir_tauleap.jl new file mode 100644 index 0000000..a1fa7cf --- /dev/null +++ b/tests/simulation/sim_sir_tauleap.jl @@ -0,0 +1,10 @@ + +using MarkovProcesses +load_plots() + +load_model("SIR_tauleap") +σ = simulate(SIR_tauleap) +MarkovProcesses.plot(σ; filename = get_module_path() * "/tests/simulation/res_pics/sim_sir_tauleap.png") + +return true + -- GitLab