-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_experiment.py
62 lines (49 loc) · 1.89 KB
/
run_experiment.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
import argparse
import os
import subprocess
from tqdm import tqdm
from shapely.geometry import Polygon
def read_cgal_polygon(file_name):
def convert_number(string):
if '/' in string:
n, d = string.split('/')
return float(n) / float(d)
else:
return float(string)
polygon = []
with open(file_name, 'r') as f:
f.seek(0)
content = f.readline().split()
n = int(content[0])
for i in range(n):
x = content[2 * i + 1]
y = content[2 * i + 2]
polygon.append((convert_number(x), convert_number(y)))
return polygon
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--dir', required=True)
parser.add_argument('-o', '--out-dir', required=True)
parser.add_argument('-e', '--executable', required=True)
parser.add_argument('-i', '--iterations', default=2, type=int)
parser.add_argument('-t', '--time', default=1000, type=float)
parser.add_argument('-r', '--radius', default=1, type=float)
args = parser.parse_args()
if not os.path.exists(args.out_dir):
os.makedirs(args.out_dir)
for file in tqdm([f for f in os.listdir(args.dir) if f.endswith('.poly')]):
input_file = os.path.join(args.dir, file)
"""
polygon = Polygon(read_cgal_polygon(input_file))
print(polygon.area)
continue
"""
output_file = os.path.join(args.out_dir, file.replace('.poly', '_raw.out'))
output_json = os.path.join(args.out_dir, file.replace('.poly', '.json'))
if os.path.isfile(output_json):
print("Output for", output_json, "already present")
continue
if os.path.isfile(output_file):
os.remove(output_file)
print("Removed output file", output_file)
with open(output_file, "w") as f:
subprocess.Popen([args.executable, input_file, output_json, str(args.iterations), str(args.time), str(args.radius)], stdout=f, stderr=f).communicate()