-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun.py
74 lines (54 loc) · 1.85 KB
/
run.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
import os
import subprocess
import multiprocessing
from subprocess import Popen, PIPE
import numpy as np
import pygsheets
INPUT_DIRS = ["./VRP/A", "./VRP/B", "./VRP/E", "./VRP/F", "./VRP/G", "./VRP/M", "./VRP/P", "./VRP/V"]
client = pygsheets.authorize(service_file='growsimplee-374918-39a3d1fb0df3.json')
sh = client.open('Optimisation Experiments')
wks = sh.sheet1
def run_each(index):
global wks
params = algo_combs[index]
print("Starting process with params: {}",params)
s_proc = subprocess.Popen(["./hgs", params["input"], "-seed 1 -t 30"],
stdout = PIPE, stderr = PIPE)
stdout, stderr = s_proc.communicate()
metrics = [-1, -1, -1]
try:
metrics = [float(x) for x in stdout.decode("utf-8").split('\n')[-3:-1]]
except:
print("Decoding error")
# print(stdout)
# print(stderr,stdout)
print(metrics)
data = [1, params["input"], params["clustering"], params["routing"], params["binpacking"], str(metrics[1])+" , "+str(metrics[0]), metrics[2], str(metrics[3])+"/"+str(metrics[4])]
# print(wks)
wks.append_table(data)
return metrics
def create_algo_combs():
params = []
for data_dir in INPUT_DIRS:
filenames = os.listdir(data_dir)
filenames = [x for x in filenames if "vrp" in x]
for fname in filenames:
param = {
"input": data_dir + "/" + fname
}
print(param)
params.append(param)
return params
algo_combs = create_algo_combs()
num_combs = len(algo_combs)
num_combs = 2
def main():
# print("HAKUNAA MATATA")
POOL_COUNT = multiprocessing.cpu_count()
pool = multiprocessing.Pool(POOL_COUNT)
cost_lists = pool.map(run_each, range(num_combs))
pool.close()
pool.join()
for i in range(num_combs):
print(algo_combs[i], cost_lists[i])
main()