...
 
Commits (2)
......@@ -12,8 +12,10 @@ Lua5.3 is also supported. For plotting install `gnuplot` and R (`r-base`)
## Run
Edit `run.lua` and modify the `conf` configuration table.
```
$ luajit epitrace.lua
$ luajit run.lua
```
......@@ -21,6 +23,7 @@ $ luajit epitrace.lua
See LICENSE.
## Who?
jvisca@fing.edu.uy
......
......@@ -12,7 +12,7 @@ local model
local function w_states ()
local t = lib.esim.now
--w_eir('t E I Q R')
conf.f_eir:write(t, ' ', M.state_count.E, ' ', M.state_count.I, ' ',
conf.f_states:write(t, ' ', M.state_count.E, ' ', M.state_count.I, ' ',
M.state_count.R, ' ', M.state_count.quarantined, '\n')
end
local function w_log (t, ...)
......@@ -126,9 +126,9 @@ M.initialize = function ( c )
lib = conf.lib
M.state_count = {E=0, I=0, R=0, quarantined=0}
if not conf.f_eir then w_states = function() end end
if not conf.f_states then w_states = function() end end
if not conf.f_log then w_log = function() end end
if conf.f_eir then conf.f_eir:write('t L P I R quarantined\n') end
if conf.f_states then conf.f_states:write('t L P I R quarantined\n') end
end
return M
\ No newline at end of file
......@@ -12,9 +12,9 @@ local model
local function w_states ()
local t = lib.esim.now
--w_slir('t L P I Q R')
conf.f_eir:write(t, ' ', M.state_count.L, ' ', M.state_count.P, ' ',
conf.f_states:write(t, ' ', M.state_count.L, ' ', M.state_count.P, ' ',
M.state_count.I, ' ', M.state_count.R, ' ', M.state_count.quarantined, '\n')
conf.f_eir:flush()
conf.f_states:flush()
end
local function w_log (t, ...)
conf.f_log:write(t, ...)
......@@ -166,9 +166,9 @@ M.initialize = function ( c )
lib = conf.lib
M.state_count = {L=0, P=0, I=0, R=0, quarantined=0}
if not conf.f_eir then w_states = function() end end
if not conf.f_states then w_states = function() end end
if not conf.f_log then w_log = function() end end
if conf.f_eir then conf.f_eir:write('t L P I R quarantined\n') end
if conf.f_states then conf.f_states:write('t L P I R quarantined\n') end
end
return M
\ No newline at end of file
--------------------------------------------------------------------------
-- parameters
local conf = {
startExposed = {
[19220] = {t=0, count=10}, -- exposed at t=0 , TREINTA Y TRES
},
--stop conditions
stop_dpto = nil, --'MONTEVIDEO',
stop_localidad = nil, -- any
outbreak_threshold = 100, -- Max number of actives
---[[
disease = {
model = 'SLIR',
R0 = 2.5,
-- https://www.medrxiv.org/content/10.1101/2020.05.06.20092841v1
p = 0.25, --proportion of asymptomatic
_epsA = 5, --latent period
_eps = 3, --latent period
_gamma = 2, --pre-symptomatic period
_mu = 6, --2.5, --time to removed/home stay
k = 0.15, -- proportion of presymptomatic transmission
r = 0.5, -- relative infectiousness of asymptomatic individuals
T_q = 2.0, -- time to self quarantine
},
--]]
--[[
disease = {
model = 'SEIR',
R0 = 2,
T_E = 6, -- Duration of E state
T_I = 6, -- Duration of I state
T_q = 2.5, -- time to self quarantine
},
--]]
contacttracers = 0,
contact_t_find = 1,
contacttracing_time = 5,
}
local TMAX = math.huge --12*30 -- Simulation time limit
local NRUNS = 10000 -- Number of runs
--------------------------------------------------------------------------
--require('mobdebug').coro()
local lib = {}
lib.esim = require('lib.esim')
lib.agents = require('agents')
lib.disease = require('disease_'..conf.disease.model)
lib.contacttracer = require('contacttracer')
conf.lib = lib
--------------------------------------------------------------------------
-- process that sets the scenario up.
local scenario_process = function (conf)
local G = require('lib.graph')
for zoneId, Exposition in pairs(conf.startExposed) do
lib.esim.launch(function()
for i = 1, Exposition.count do
lib.esim.sleep_to(Exposition.t)
lib.agents.create_exposed (G.N[zoneId], nil)
end
end)
local M = {}
M.run = function ( conf )
local lib = {}
lib.esim = require('lib.esim')
lib.agents = require('agents')
lib.disease = require('disease_'..conf.disease.model)
lib.contacttracer = require('contacttracer')
conf.lib = lib
local sim_status_count = {outbreak=0, extinction=0, runout=0}
local function w_log (t, ...)
conf.f_log:write(t, ...)
conf.f_log:write('\n')
--conf.f_log:flush()
end
end
local sim_status_count = {outbreak=0, extinction=0, runout=0}
--os.execute('rm out/*.log out/*.txt')
for i = 1, NRUNS do
-- Log files
conf.f_eir = io.open('out/states'..i..'.log', 'w')
conf.f_log = io.open('out/epitrace'..i..'.log', 'w')
-- Seed the random generator independetly per run
math.randomseed(i) --os.time())
conf.f_log:write(0, ' randomseed ', i, '\n')
lib.esim.initialize( TMAX )
lib.agents.initialize( conf )
lib.disease.initialize( conf )
lib.contacttracer.initialize( conf )
lib.esim.launch( scenario_process or function() end, conf )
local event_count = 0
local t_now
local sim_status
repeat
local t, status = lib.esim.step()
if t then
event_count = event_count + 1
t_now = t
end
-- stop conditions
if not t then
sim_status = tostring(status)
for i = 1, conf.NRUNS do
-- Log files
if conf.out_path then
conf.f_states = io.open(conf.out_path..'states'..i..'.log', 'w')
conf.f_log = io.open(conf.out_path..'epitrace'..i..'.log', 'w')
else
w_log = function () end
end
until sim_status
conf.f_log:write(t_now, ' finished ',sim_status,' R: '..lib.disease.state_count.R..'\n')
conf.f_eir:close()
conf.f_log:close()
sim_status_count[sim_status] = (sim_status_count[sim_status] or 0) + 1
print (i, 'finished at t: '..t_now..' events: '
..event_count..' ('..sim_status ..')')
end
-- Seed the random generator independetly per run
math.randomseed(i) --os.time())
w_log(0, ' randomseed ', i)
lib.esim.initialize( conf.TMAX )
lib.agents.initialize( conf )
lib.disease.initialize( conf )
lib.contacttracer.initialize( conf )
lib.esim.launch( conf.scenario_process or function() end, conf )
local event_count = 0
local t_now
local sim_status
repeat
local t, status = lib.esim.step()
if t then
event_count = event_count + 1
t_now = t
end
-- stop conditions
if not t then
sim_status = tostring(status)
end
until sim_status
w_log(t_now, ' finished ',sim_status,' R: ', lib.disease.state_count.R)
if conf.f_states then conf.f_states:close() end
if conf.f_log then conf.f_log:close() end
sim_status_count[sim_status] = (sim_status_count[sim_status] or 0) + 1
print (i, 'finished at t: '..t_now..' events: '
..event_count..' ('..sim_status ..')')
end
-- Print run totals
for status, count in pairs(sim_status_count) do
print('runs', status, count, count/NRUNS)
return sim_status_count
end
-- Launch plotting (on background)
os.execute('gnuplot states.plot &')
os.execute('luajit parse_logs.lua '..NRUNS..' &')
return M
\ No newline at end of file
local NRUNS = assert(tonumber(arg[1]), 'missing count parameter')
local MIN_EXPOS_TO_PLOT = 30 --NRUNS/50
local MIN_EXPOS_TO_PLOT = NRUNS/100
local mathutil = require('lib.mathutil')
......
local epitrace = require('epitrace')
--require('mobdebug').coro()
--------------------------------------------------------------------------
-- parameters
local conf = {
TMAX = math.huge, --12*30 -- Simulation time limit
NRUNS = 100, -- Number of runs
out_path = 'out/', -- nil to disable logging
startExposed = {
[19220] = {t=0, count=20}, -- exposed at t=0 , RIVERA-MASOLLER
},
--stop conditions
stop_dpto = 'MONTEVIDEO',
stop_localidad = nil, -- any
outbreak_threshold = 100, -- Max number of actives
---[[
disease = {
model = 'SLIR',
R0 = 2.5,
-- https://www.medrxiv.org/content/10.1101/2020.05.06.20092841v1
p = 0.25, --proportion of asymptomatic
_epsA = 5, --latent period
_eps = 3, --latent period
_gamma = 2, --pre-symptomatic period
_mu = 6, --2.5, --time to removed/home stay
k = 0.15, -- proportion of presymptomatic transmission
r = 0.5, -- relative infectiousness of asymptomatic individuals
T_q = 2.5, -- time to self quarantine
},
--]]
--[[
disease = {
model = 'SEIR',
R0 = 2,
T_E = 6, -- Duration of E state
T_I = 6, -- Duration of I state
T_q = 2.5, -- time to self quarantine
},
--]]
contacttracers = 0,
contact_t_find = 1,
contacttracing_time = 5,
}
-- process that sets the scenario up.
conf.scenario_process = function (conf)
local G = require('lib.graph')
local lib = conf.lib
for zoneId, Exposition in pairs(conf.startExposed) do
lib.esim.launch(function()
for i = 1, Exposition.count do
lib.esim.sleep_to(Exposition.t)
lib.agents.create_exposed (G.N[zoneId], nil)
end
end)
end
end
local sim_status_count = epitrace.run(conf)
-- Print run totals
for status, count in pairs(sim_status_count) do
print('runs', status, count, count/conf.NRUNS)
end
-- Launch plotting (on background)
os.execute('gnuplot states.plot &')
os.execute('luajit parse_logs.lua '..conf.NRUNS..' &')
local epitrace = require('epitrace')
--require('mobdebug').coro()
--------------------------------------------------------------------------
-- parameters
local conf = {
TMAX = math.huge, --12*30 -- Simulation time limit
NRUNS = 1000, -- Number of runs
out_path = nil,
startExposed = {
[13943] = {t=0, count=20}, -- exposed at t=0 , RIVERA-MASOLLER
[19220] = {t=0, count=20}, -- exposed at t=0 , 33 capital
},
--stop conditions
stop_dpto = 'MONTEVIDEO',
stop_localidad = nil, -- any
......@@ -44,24 +50,10 @@ local conf = {
contacttracing_time = 5,
}
local TMAX = math.huge --12*30 -- Simulation time limit
local NRUNS = 1000 -- Number of runs
--------------------------------------------------------------------------
--require('mobdebug').coro()
local lib = {}
lib.esim = require('lib.esim')
lib.agents = require('agents')
lib.disease = require('disease_'..conf.disease.model)
lib.contacttracer = require('contacttracer')
conf.lib = lib
--------------------------------------------------------------------------
-- process that sets the scenario up.
local scenario_process = function (conf)
conf.scenario_process = function (conf)
local G = require('lib.graph')
local lib = conf.lib
for zoneId, Exposition in pairs(conf.startExposed) do
lib.esim.launch(function()
for i = 1, Exposition.count do
......@@ -72,82 +64,23 @@ local scenario_process = function (conf)
end
end
--os.execute('rm out/*.log out/*.txt')
local function runsim()
local sim_status_count = {outbreak=0, extinction=0, runout=0}
for i = 1, NRUNS do
-- Log files
--conf.f_eir = io.open('out/states'..i..'.log', 'w')
--conf.f_log = io.open('out/epitrace'..i..'.log', 'w')
-- Seed the random generator independetly per run
math.randomseed(i) --os.time())
--conf.f_log:write(0, ' randomseed ', i, '\n')
lib.esim.initialize( TMAX )
lib.agents.initialize( conf )
lib.disease.initialize( conf )
lib.contacttracer.initialize( conf )
lib.esim.launch( scenario_process or function() end, conf )
local event_count = 0
local t_now
local sim_status
repeat
local t, status = lib.esim.step()
if t then
event_count = event_count + 1
t_now = t
end
-- stop conditions
if not t then
sim_status = tostring(status)
end
until sim_status
--conf.f_log:write(t_now, ' finished ',sim_status,' R: '..lib.disease.Rcount..'\n')
--conf.f_eir:close()
--conf.f_log:close()
sim_status_count[sim_status] = (sim_status_count[sim_status] or 0) + 1
print (i, 'finished at t: '..t_now..' events: '
..event_count..' ('..sim_status ..')')
end
-- Print run totals
--for status, count in pairs(sim_status_count) do
-- print('runs', status, count, count/NRUNS)
--end
-- Launch plotting (on background)
--os.execute('gnuplot states.plot &')
--os.execute('luajit parse_logs.lua '..NRUNS..' &')
return sim_status_count
end
local frunlog = io.open('out/contacttracing.log', 'w')
frunlog:write('tracers runout outbreak extinction hitstop\n')
for ntracers = 0, 20, 2 do
conf.contacttracers = ntracers
local s = runsim()
local s = epitrace.run(conf)
frunlog:write(
ntracers, ' ',
s.runout/NRUNS, ' ',
s.outbreak/NRUNS, ' ',
s.extinction/NRUNS, ' ',
s.hit_stop/NRUNS, '\n'
s.runout/conf.NRUNS, ' ',
s.outbreak/conf.NRUNS, ' ',
s.extinction/conf.NRUNS, ' ',
s.hit_stop/conf.NRUNS, '\n'
)
end
frunlog:write()
frunlog:close()
os.execute('gnuplot contacttracing.plot &')