-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultitest.py
executable file
·81 lines (68 loc) · 2.29 KB
/
multitest.py
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
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
import multiprocessing
# Setup
DATA_DIR = 'final/maps'
OUTPUT_DIR = 'final/paths'
NUM_PROC = 10
# Stuff to permutate
scoremaps = ['500x500_'+str(s)+'_'+str(n) for s in range(5,31,5) for n in range(5,51,5)]
budgets = [25000]
algorithms = ['lm', 'rh']
lookaheads = [2]
rand_fracs = [0.2, 0.4, 0.6, 0.8, 1.0]
thresholds = [0.0, 0.05, 0.10, 0.15, 0.20, 0.25]
def args2fn(arglist):
return OUTPUT_DIR + "/" + arglist['sm'] \
+ "_" + arglist['alg'] \
+ "_b" + str(arglist['budget']) \
+ "_la" + str(arglist['la']) \
+ "_rf" + str(arglist['frac']) \
+ "_th" + str(arglist['thres']) + ".path"
def args2cmd(arglist):
return './treemower ' \
+ DATA_DIR + "/" + arglist['sm'] + ".map" \
+ " " + arglist['alg'] \
+ " " + str(arglist['budget']) \
+ " " + str(arglist['la']) \
+ " " + str(arglist['frac']) \
+ " " + str(arglist['thres']) \
+ " " + args2fn(arglist)
def args2csv(arglist):
return arglist['sm'] + ', ' \
+ str(arglist['budget']) + ', ' \
+ str(arglist['la']) + ', ' \
+ str(arglist['frac'])
def run(mp_args):
score = 0
cmd = args2cmd(mp_args)
if not os.path.isfile(args2fn(mp_args)):
score = os.popen(cmd).read()
# Print progress
with mp_lock:
print(str(mp_progress.value)+'/'+str(len(p_list))+':', cmd)
mp_progress.value += 1
return score
# Permute arguments
p_list = []
for sm in scoremaps:
for bu in budgets:
for alg in algorithms:
if alg == 'lm':
arglist = {'sm': sm, 'alg': alg, 'budget': bu, 'la': 1, 'frac': 1.0, 'thres': 0}
p_list.append(arglist.copy())
continue
for la in lookaheads:
for f in rand_fracs:
for th in thresholds:
arglist = {'sm': sm, 'alg': alg, 'budget': bu, 'la': la, 'frac': f, 'thres': th}
p_list.append(arglist.copy())
# Run algorithms
mp_lock = multiprocessing.Lock()
mp_progress = multiprocessing.Value('i', 1)
mp = multiprocessing.Pool(NUM_PROC)
mp_results = mp.map(run, p_list)
mp.close()
mp.join()