-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
63 lines (57 loc) · 1.4 KB
/
Copy pathRakefile
File metadata and controls
63 lines (57 loc) · 1.4 KB
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
require 'yaml'
# TODO: Improve this script
def build_configurations(keys, matrix)
conf = []
for k in keys
if conf.empty?
for v in matrix[k]
conf << ({ k => v })
end
else
new_conf = []
for v in matrix[k]
for c in conf
new_conf << c.merge({ k => v })
end
end
conf = new_conf
end
end
conf
end
def run_conf(conf, runid, exe, outdir)
filename = [
"g[#{conf['generations']}]",
"d[#{conf['dna']}]",
"m[#{conf['mutation']}]",
"c[#{conf['crossover']}]",
"t[#{conf['tournament']}]",
"p[#{conf['population']}]",
"mr[#{conf['mutation-rate']}]",
"id[#{runid}]"
].join '_'
outpath = File.join(outdir, filename + '.csv')
params = conf.merge({ output: outpath }).to_a.map do |k,v|
"--#{k}=#{v}"
end.join ' '
puts `#{exe} --csv #{params}`
end
def run_matrix(matrix)
exe = matrix['executable']
runs = matrix['runs']
outdir = matrix['outdir']
mkdir_p outdir
params = matrix['params']
keys = ['generations', 'dna', 'mutation', 'crossover', 'tournament', 'population', 'mutation-rate']
conf = build_configurations keys, params
puts "Number of executions of #{exe}: #{runs * conf.length}"
for c in conf
runs.times do |n|
run_conf c, n, exe, outdir
end
end
end
task :matrix, [:matrix_path] do |t, args|
matrix = YAML.load File.read args.matrix_path
run_matrix matrix
end