-
Notifications
You must be signed in to change notification settings - Fork 5
/
mainHelpers.jl
98 lines (64 loc) · 2.57 KB
/
mainHelpers.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Some common infrastructure for setting up and running the model.
"""
include("lib/loadLibsPath.jl")
# add various directories to Julia's model search path
addToLoadPath!(String(@__DIR__) * "/.",
String(@__DIR__) * "/lib",
String(@__DIR__) * "/src",
String(@__DIR__) * "/src/common",
String(@__DIR__) * "/src/agents",
String(@__DIR__) * "/src/agents/agent_modules",
String(@__DIR__) * "/src/agents/interactions",
String(@__DIR__) * "/src/simulate",
String(@__DIR__) * "/src/fullModel"
)
using ArgParse
using Utilities
using FullModelPars
using FullModel
include("src/fullModel/data.jl")
include("src/handleParams.jl")
"Generate and return a usable model object."
function setupModel(pars)
datp = pars.datapars
dir = datp.datadir
demoData = loadDemographyData(dir * "/" * datp.iniAgeFName,
dir * "/" * datp.pre51FertFName,
dir * "/" * datp.fertFName,
dir * "/" * datp.pre51DeathsFName,
dir * "/" * datp.deathFFName,
dir * "/" * datp.deathMFName)
workData = loadWorkData(dir * "/" * datp.unemplFName,
dir * "/" * datp.wealthFName)
model = createModel!(demoData, workData, pars)
initializeModel!(model, pars.poppars, pars.workpars, pars.carepars, pars.taskcarepars, pars.mappars, pars.lhapars)
model
end
"Prepare and return output file or nothing."
function setupLogging(simPars; FS = "\t")
if simPars.logfile == ""
return nothing
end
file = open(simPars.logfile, "w")
print_header(file, Data; FS)
file
end
"Run fully initialised model non-interactively from start to finish."
function runModel!(model, simPars, pars, logfile = nothing; FS = "\t")
curTime = pars.poppars.startTime
simPars.verbose ? setVerbose!() : unsetVerbose!()
setDelay!(simPars.sleeptime)
# no point in continuing with the simulation if we are not recording results
finishTime = min(pars.poppars.finishTime, simPars.endLogTime)
while curTime <= finishTime
stepModel!(model, curTime, pars)
if logfile != nothing && curTime >= simPars.startLogTime
results = observe(Data, model, curTime, pars)
log_results(logfile, results; FS)
end
#nWorkers = work_by_time(model.pop)
#println(nWorkers)
curTime += simPars.dt
end
end