...
 
Commits (2)
**/out/
*.eps
*.odt#
*.od?#
local M = {}
local mathutil = require('lib.mathutil')
local conf
local lib
local function w_log (t, ...)
conf.f_log:write(t, ...)
conf.f_log:write('\n')
--conf.f_log:flush()
end
M.models = {}
M.models.forward1 = function ( case )
local t = lib.esim.now
if math.random()<conf.ca_p then
for i=1, #case.exposed_to do
local contact = case.exposed_to[i]
if (not contact.disease.quarantined) and (math.random()<conf.ca_p) then
w_log(t, ' app case: ', case.id, ' contact: ', contact.id )
contact.disease.quarantined = true
end
end
end
end
M.initialize = function ( c )
conf = assert(c)
lib = conf.lib
if not conf.ca_model then
M.new_case=function() end
return
end
M.new_case = assert(M.models[conf.ca_model],
'unknown ca model: '..tostring(conf.ca_model))
if not conf.f_log then w_log = function() end end
end
return M
\ No newline at end of file
reset
clear
#set title ""
#set xrange [0:200]
set yrange [0:1]
set xlabel 'ca_p'
set ylabel 'p'
#set key top right
set key autotitle columnhead
set term post size 5in, 2in eps enhanced color
#set term png size 700,400
filename = 'out/contactapp.log'
stats filename nooutput
set out "contactapp.eps"
plot for [i=5:STATS_columns] filename using 1:i w l
set out "contactappRe.eps"
set ylabel 'R_e'
unset yrange
set yrange [0:]
plot filename using 1:2:3 w e t '', \
filename using 1:2 w l t '', \
unset output
......@@ -24,10 +24,10 @@ local function tracer_process ( t, tracer_id )
local case = M.cases:popleft()
w_log(t, ' trace_start tid: ', tracer_id, ' id: ', case.id )
local t_end = t + conf.contacttracing_time
local t_end = t + conf.ct_trace_t
local i = 1
while t<t_end do
t = lib.esim.sleep_to(t+conf.contact_t_find)
t = lib.esim.sleep_to(t+conf.ct_hit_t)
if i<=#case.exposed_to then
local contact = case.exposed_to[i]
if not contact.disease.quarantined then
......@@ -54,7 +54,7 @@ M.initialize = function ( c )
if not conf.f_log then w_log = function() end end
M.cases = queue:new()
for i = 1, c.contacttracers or 0 do
for i = 1, c.ct_count or 0 do
M.create_tracer(0, i)
end
end
......
......@@ -7,7 +7,7 @@ local mathutil = require('lib.mathutil')
local conf
local lib
local model
local ds_model
local function w_states ()
local t = lib.esim.now
......@@ -61,7 +61,7 @@ M.infector = function (person, to_t)
local infgen = d.infgen + 1
d.infgen = infgen
local next_infection = t+mathutil.sample_exp_distribution( model.R0/model.T_I )
local next_infection = t+mathutil.sample_exp_distribution( ds_model.R0/ds_model.T_I )
while next_infection<to_t and person.disease.state~='R'
and not d.quarantined do
t = lib.esim.sleep_to(next_infection)
......@@ -71,22 +71,23 @@ M.infector = function (person, to_t)
if person.disease.state == 'I' and not d.quarantined then
lib.agents.create_exposed(zone, person)
end
next_infection = t+mathutil.sample_exp_distribution( model.R0/model.T_I )
next_infection = t+mathutil.sample_exp_distribution( ds_model.R0/ds_model.T_I )
end
return lib.esim.sleep_to(to_t)
end
local selfQuarantineProcess = function ( person )
local t = lib.esim.now
if not model._q then return end
if not ds_model._q then return end
local d = person.disease
local tq = t+model._q
local tq = t+ds_model._q
lib.esim.sleep_to(tq)
if not d.quarantined then
d.quarantined = true
w_log(t, ' selfquarantined id:', person.id)
lib.contacttracer.cases:pushright(person)
end
lib.contacttracer.cases:pushright(person)
lib.contactapp.new_case(person)
end
M.process = function ( person )
......@@ -99,11 +100,14 @@ M.process = function ( person )
d.state = 'E'
t = lib.esim.sleep_to( t+model.T_E )
t = lib.esim.sleep_to( t+ds_model.T_E )
d.state = 'I'
lib.esim.launch(selfQuarantineProcess, person)
if math.random()<ds_model.qp then
lib.esim.launch(selfQuarantineProcess, person)
d.selfq = true
end
local time_start_R = t+model.T_I
local time_start_R = t+ds_model.T_I
t = M.infector(person, time_start_R)
d.state = 'R'
......@@ -122,7 +126,7 @@ end
M.initialize = function ( c )
conf = assert(c)
model = c.disease
ds_model = c.disease
lib = conf.lib
M.state_count = {E=0, I=0, R=0, quarantined=0}
......
......@@ -7,7 +7,7 @@ local mathutil = require('lib.mathutil')
local conf
local lib
local model
local ds_model
local function w_states ()
local t = lib.esim.now
......@@ -60,12 +60,12 @@ local function compute_beta_SLIR (d)
local beta
if d.state == 'I' then
if d.symptomatic then
beta = model.R0 / model._mu
beta = ds_model.R0 / ds_model._mu
else
beta = model.p * model.R0 / model._mu
beta = ds_model.p * ds_model.R0 / ds_model._mu
end
elseif d.state == 'P' then
beta = model.k * model.R0 / model._mu
beta = ds_model.k * ds_model.R0 / ds_model._mu
end
return beta
end
......@@ -103,15 +103,16 @@ end
local selfQuarantineProcess = function ( person )
local t = lib.esim.now
if not model._q then return end
if not ds_model._q then return end
local d = person.disease
local tq = t+model._q
local tq = t+ds_model._q
lib.esim.sleep_to(tq)
if not d.quarantined then
d.quarantined = true
w_log(t, ' selfquarantined id:', person.id)
lib.contacttracer.cases:pushright(person)
end
lib.contacttracer.cases:pushright(person)
lib.contactapp.new_case(person)
end
M.process = function ( person )
......@@ -124,25 +125,28 @@ M.process = function ( person )
local d = person.disease
d.state = 'L'
d.symptomatic = math.random()>model.p
d.symptomatic = math.random()>ds_model.p
if d.symptomatic then
t = lib.esim.sleep_to( t+model._eps )
t = lib.esim.sleep_to( t+ds_model._eps )
d.state = 'P'
local time_start_I = t+model._gamma
local time_start_I = t+ds_model._gamma
t = M.infector(person, time_start_I)
d.state = 'I'
lib.esim.launch(selfQuarantineProcess, person)
if math.random()<ds_model.qp then
lib.esim.launch(selfQuarantineProcess, person)
d.selfq = true
end
local time_start_R = t+model._mu
local time_start_R = t+ds_model._mu
t = M.infector(person, time_start_R)
d.state = 'R'
else --asymptomatic
t = lib.esim.sleep_to( t+model._epsA )
t = lib.esim.sleep_to( t+ds_model._epsA )
d.state = 'I'
local time_start_R = t+model._mu
local time_start_R = t+ds_model._mu
t = M.infector(person, time_start_R)
d.state = 'R'
end
......@@ -162,7 +166,7 @@ end
M.initialize = function ( c )
conf = assert(c)
model = c.disease
ds_model = c.disease
lib = conf.lib
M.state_count = {L=0, P=0, I=0, R=0, quarantined=0}
......
No preview for this file type
No preview for this file type
......@@ -8,6 +8,7 @@ M.run = function ( conf )
lib.agents = require('agents')
lib.disease = require('disease_'..conf.disease.model)
lib.contacttracer = require('contacttracer')
lib.contactapp = require('contactapp')
conf.lib = lib
local sim_status_count = {outbreak=0, extinction=0, runout=0}
......@@ -39,6 +40,7 @@ M.run = function ( conf )
lib.agents.initialize( conf )
lib.disease.initialize( conf )
lib.contacttracer.initialize( conf )
lib.contactapp.initialize( conf )
lib.esim.launch( conf.scenario_process or function() end, conf )
local event_count = 0
......
local confname = assert(arg[1], 'pass conf file as parameter')
local conf
do
local conffile = assert(io.open(confname), 'r')
local confstring = 'return {'
..conffile:read('*a')
..'}'
conf = assert(loadstring(confstring, 'confstring'))()
end
local epitrace = require('epitrace')
--require('mobdebug').coro()
-- process that sets the scenario up.
conf.scenario_process = conf.scenario_process or function (conf)
local G = require('lib.graph')
local lib = conf.lib
--for zoneId, Exposition in pairs(conf.startExposed) do
for _, Exposition in ipairs(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[Exposition.zone], nil)
end
end)
end
end
local frunlog = io.open('out/contactapp.log', 'w')
frunlog:write('ca_p Re ReStd runout outbreak extinction hitstop\n')
-- run simulations
for ca_p = 0, 1, 0.1 do
conf.ca_p = ca_p -- set sim. scenario
local s = epitrace.run(conf) -- run
frunlog:write(
ca_p, ' ',
s.R_e_avg, ' ',
s.R_e_std, ' ',
(s.status_count.runout or 0)/conf.NRUNS, ' ',
(s.status_count.outbreak or 0)/conf.NRUNS, ' ',
(s.status_count.extinction or 0)/conf.NRUNS, ' ',
(s.status_count.hit_stop or 0)/conf.NRUNS, '\n'
)
end
frunlog:close()
print('generating contactapp.eps and contactappRe.eps')
os.execute('gnuplot contactapp.plot')
......@@ -33,8 +33,8 @@ local frunlog = io.open('out/contacttracing.log', 'w')
frunlog:write('tracers Re ReStd runout outbreak extinction hitstop\n')
-- run simulations
for ntracers = 0, 15, 2 do
conf.contacttracers = ntracers -- set sim. scenario
for ntracers = 0, 16, 2 do
conf.ct_count = ntracers -- set sim. scenario
local s = epitrace.run(conf) -- run
......
......@@ -47,8 +47,15 @@ disease = {
r = 0.5, -- relative infectiousness of asymptomatic individuals
_q = 2, -- time to self quarantine
qp = 1, -- probability of entering self quarantine
},
contacttracers = 0,
contact_t_find = 1,
contacttracing_time = 5,
-- contact tracers behavior
ct_count = 0, -- number if contact tracers working
ct_hit_t = 1, -- time to hitting an exposed
ct_trace_t = 5, -- time attending a single case
-- contact app behavior
ca_p = 0, -- probability of having the app installed
ca_model = 'forward1',
-- Basic execution parameters ----------------------------------
TMAX = math.huge,
NRUNS = 1000,
out_path = nil, --disabled logging
startExposed = {
{zone=19220, t=0, count=20},
},
outbreak_threshold = 200,
stop_dpto = 'MONTEVIDEO',
stop_localidad = nil, -- any
disease = {
model = 'SLIR',
R0 = 2.5,
p = 0.25,
_epsA = 5,
_eps = 3,
_gamma = 2,
_mu = 6,
k = 0.15,
r = 0.5,
_q = 3, -- slightly bigger than default 2
qp = 1,
},
ct_count = 0,
ca_p = 0, -- this will be changed by script
ca_model = 'forward1',
\ No newline at end of file
......@@ -12,6 +12,8 @@ startExposed = {
outbreak_threshold = 200,
stop_dpto = 'MONTEVIDEO',
stop_localidad = nil, -- any
disease = {
model = 'SLIR',
......@@ -25,9 +27,10 @@ disease = {
k = 0.15,
r = 0.5,
_q = 3, -- slighly bigger than default 2
_q = 3, -- slightly bigger than default 2
qp = 1,
},
contacttracers = 0, -- this will be changed by script
contact_t_find = 1,
contacttracing_time = 5,
ct_count = 0, -- this will be changed by script
ct_hit_t = 1,
ct_trace_t = 5,