-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.jl
86 lines (62 loc) · 1.62 KB
/
run.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
#!/usr/bin/env julia
using Random
push!(LOAD_PATH, pwd())
using Analysis
include("base/world.jl")
include("base/init.jl")
include("base/simulation.jl")
include("base/setup.jl")
function run(p, n_steps, log_file)
Random.seed!(p.rand_seed_world)
w = create_world(p);
Random.seed!(p.rand_seed_sim)
m = Model(w, Agent[], Agent[]);
for i in 1:n_steps
step_simulation!(m, i, p)
analyse_log(m, log_file)
println(i)
flush(stdout)
end
m
end
include(get_parfile())
const arg_settings = ArgParseSettings("run simulation", autofix_names=true)
@add_arg_table arg_settings begin
"--n-steps", "-n"
help = "number of simulation steps"
arg_type = Int
default = 300
"--par-file", "-p"
help = "file name for parameters"
default = "params.txt"
"--out-file", "-o"
help = "file name for data output"
default = "output.txt"
"--city-file"
help = "file name for city output"
default = "cities.txt"
"--link-file"
help = "file name for link output"
default = "links.txt"
"--log-file", "-l"
help = "file name for log"
default = "log.txt"
end
add_arg_group(arg_settings, "simulation parameters")
fields_as_args!(arg_settings, Params)
const args = parse_args(arg_settings, as_symbols=true)
const p = create_from_args(args, Params)
save_params(args[:par_file], p)
const n_steps = args[:n_steps]
const logf = open(args[:log_file], "w")
const cityf = open(args[:city_file], "w")
const linkf = open(args[:link_file], "w")
#const outf = open(args[:out_file], "w")
prepare_log(logf)
#prepare_out(outf)
const m = run(p, n_steps, logf)
analyse_world(m, cityf, linkf)
#close(outf)
close(logf)
close(cityf)
close(linkf)