-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.py
More file actions
226 lines (218 loc) · 11.1 KB
/
runner.py
File metadata and controls
226 lines (218 loc) · 11.1 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import argparse
import os
import re
from problems.facility_location_model import FacilityProblem
from problems.general_assignment_problem import APModel
from problems.knapsack_problem import KnapsackModel
from problems.land_conservation_problem import LandConModel
from utility.grid_class import Grid
from utility.tester import Tester
from utility.utility import create_folders
parser = argparse.ArgumentParser(description='Runner Anytime Enumeration')
parser.add_argument('-m', '--method', type=str, choices=['fwi','disjunction','rectangle', 'ozlen+', 'saugmecon', 'fi', 'tamby', 'tamby_lex', 'dpa'],
help='method', required=True)
parser.add_argument('-f', '--folder', type=str, help='folder input', required=True)
parser.add_argument('-p', '--problem', type=str, choices=['land', 'knap', 'ap','facility'],
help = 'problem type', required=True)
parser.add_argument('-s', '--solver', type=str, choices=['gurobi','gurobi_inc'],
help = 'solver', required=False, default='gurobi_inc')
parser.add_argument('-t', '--timeout', type=int, help='timeout', required=False, default=10000)
parser.add_argument('-k', '--top', type=int, help='top-k', required=False, default=100000)
parser.add_argument('-o','--objectives', help='objectives', nargs='+', default=[3,4,5,6,7,8,9,10], required=False)
args = parser.parse_args()
folder = args.folder
timeout = args.timeout
topk = args.top
solver = args.solver
objective_list = args.objectives
folder = os.path.join(os.getcwd(), folder)
if args.problem == 'land':
result_location = os.path.join(os.getcwd(),f'results/{solver}/land_conservation/')
tester = Tester(timeout,topk,solver)
folder_grid = os.path.join(folder,'grid')
for filename in os.listdir(folder_grid):
print(f'Start enumerating for {filename}')
number = re.search(r'\d+', filename).group()
file_grid = os.path.join(folder_grid, f'data_grid_{number}.csv')
folder_thr = os.path.join(folder, 'thr')
file_thr = os.path.join(folder_thr, f'data_thr_{number}.csv')
grid = Grid(path_grid=file_grid, path_threshold=file_thr)
for obj in objective_list:
print(f'Start enumerating for {obj} objectives')
maker = LandConModel(grid=grid, obj=obj)
if args.method == 'fwi':
print('Run fwi')
df = tester.test_fwi(maker)
elif args.method == 'disjunction':
print('Run disjunction')
df = tester.test_disjunction(maker)
elif args.method == 'rectangle':
print('Run rectangle')
df = tester.test_rectangle(maker)
elif args.method == 'ozlen+':
print('Run ozlen+')
df = tester.test_ozlen(maker)
elif args.method == 'saugmecon':
print('Run saugmecon')
df = tester.test_saugmecon(maker)
elif args.method == 'fi':
print('Run fi')
df = tester.test_fi(maker)
elif args.method == 'dpa':
print('Run fi')
df = tester.test_dpa(maker)
elif args.method == 'tamby':
print('Run fi')
df = tester.test_tamby(maker)
elif args.method == 'tamby_lex':
print('Run fi')
df = tester.test_tamby_lex(maker)
folder_results = os.path.join(result_location, f'{obj}K')
folder_results = os.path.join(folder_results, args.method)
create_folders(folder_results)
csv_file_name = os.path.join(folder_results, f'{number}.csv')
df.to_csv(csv_file_name)
elif args.problem == 'knap':
data_type = os.path.basename(folder)
result_location = os.path.join(os.getcwd(), f'results/{solver}/knapsack/{data_type}')
tester = Tester(timeout, topk, solver)
for root, dirs, files in os.walk(folder):
for subfolder in sorted(dirs):
match = re.match(r"(\d+)K", subfolder)
if str(match.group(1)) in objective_list:
print(f'Type:{subfolder}')
subfolder_path = os.path.join(root, subfolder)
for filename in os.listdir(subfolder_path):
print(f'Start enumerating for {filename}')
number = re.search(r'\d+', filename).group()
file_path = os.path.join(subfolder_path, filename)
maker = KnapsackModel(file_path)
if args.method == 'fwi':
print('Run fwi')
df = tester.test_fwi(maker)
elif args.method == 'disjunction':
print('Run disjunction')
df = tester.test_disjunction(maker)
elif args.method == 'rectangle':
print('Run rectangle')
df = tester.test_rectangle(maker)
elif args.method == 'ozlen+':
print('Run ozlen+')
df = tester.test_ozlen(maker)
elif args.method == 'saugmecon':
print('Run saugmecon')
df = tester.test_saugmecon(maker)
elif args.method == 'fi':
print('Run fi')
df = tester.test_fi(maker)
elif args.method == 'dpa':
print('Run fi')
df = tester.test_dpa(maker)
elif args.method == 'tamby':
print('Run fi')
df = tester.test_tamby(maker)
elif args.method == 'tamby_lex':
print('Run fi')
df = tester.test_tamby_lex(maker)
folder_results = os.path.join(result_location, subfolder)
folder_results = os.path.join(folder_results, args.method)
create_folders(folder_results)
csv_file_name = os.path.join(folder_results, f'{number}.csv')
df.to_csv(csv_file_name)
elif args.problem == 'ap':
data_type = os.path.basename(folder)
result_location = os.path.join(os.getcwd(), f'results/{solver}/assignment/{data_type}')
tester = Tester(timeout, topk, solver)
for root, dirs, files in os.walk(folder):
for subfolder in sorted(dirs):
match = re.match(r"(\d+)K", subfolder)
if str(match.group(1)) in objective_list:
print(f'Type:{subfolder}')
subfolder_path = os.path.join(root, subfolder)
for filename in os.listdir(subfolder_path):
print(f'Start enumerating for {filename}')
number = re.search(r'\d+', filename).group()
file_path = os.path.join(subfolder_path, filename)
maker = APModel(file_path)
if args.method == 'fwi':
print('Run fwi')
df = tester.test_fwi(maker)
elif args.method == 'disjunction':
print('Run disjunction')
df = tester.test_disjunction(maker)
elif args.method == 'rectangle':
print('Run rectangle')
df = tester.test_rectangle(maker)
elif args.method == 'ozlen+':
print('Run ozlen+')
df = tester.test_ozlen(maker)
elif args.method == 'saugmecon':
print('Run saugmecon')
df = tester.test_saugmecon(maker)
elif args.method == 'fi':
print('Run fi')
df = tester.test_fi(maker)
elif args.method == 'dpa':
print('Run fi')
df = tester.test_dpa(maker)
elif args.method == 'tamby':
print('Run fi')
df = tester.test_tamby(maker)
elif args.method == 'tamby_lex':
print('Run fi')
df = tester.test_tamby_lex(maker)
folder_results = os.path.join(result_location, subfolder)
folder_results = os.path.join(folder_results, args.method)
create_folders(folder_results)
csv_file_name = os.path.join(folder_results, f'{number}.csv')
df.to_csv(csv_file_name)
elif args.problem == 'facility':
data_type = os.path.basename(folder)
result_location = os.path.join(os.getcwd(), f'results/{solver}/facility/{data_type}')
tester = Tester(timeout, topk, solver)
for root, dirs, files in os.walk(folder):
for subfolder in sorted(dirs):
match = re.match(r"(\d+)K", subfolder)
if str(match.group(1)) in objective_list:
print(f'Type:{subfolder}')
subfolder_path = os.path.join(root, subfolder)
for filename in os.listdir(subfolder_path):
print(f'Start enumerating for {filename}')
number = re.search(r'\d+', filename).group()
match = re.compile(r'(\d+).*C(\d+)').match(subfolder)
objs = int(match.group(1))
clients = int(match.group(2))
file_path = os.path.join(subfolder_path, filename)
maker = FacilityProblem(file_path,clients=clients, objectives=objs)
if args.method == 'fwi':
print('Run fwi')
df = tester.test_fwi(maker)
elif args.method == 'disjunction':
print('Run disjunction')
df = tester.test_disjunction(maker)
elif args.method == 'rectangle':
print('Run rectangle')
df = tester.test_rectangle(maker)
elif args.method == 'ozlen+':
print('Run ozlen+')
df = tester.test_ozlen(maker)
elif args.method == 'saugmecon':
print('Run saugmecon')
df = tester.test_saugmecon(maker)
elif args.method == 'fi':
print('Run fi')
df = tester.test_fi(maker)
elif args.method == 'dpa':
print('Run fi')
df = tester.test_dpa(maker)
elif args.method == 'tamby':
print('Run fi')
df = tester.test_tamby(maker)
elif args.method == 'tamby_lex':
print('Run fi')
df = tester.test_tamby_lex(maker)
folder_results = os.path.join(result_location, subfolder)
folder_results = os.path.join(folder_results, args.method)
create_folders(folder_results)
csv_file_name = os.path.join(folder_results, f'{number}.csv')
df.to_csv(csv_file_name)