forked from open-energy-transition/solver-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter-benchmarks.py
More file actions
executable file
·45 lines (37 loc) · 1.32 KB
/
filter-benchmarks.py
File metadata and controls
executable file
·45 lines (37 loc) · 1.32 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
#!/usr/bin/env python
"""
A script to (smartly) run Highs on all sizes of a benchmark and find the ones that
solve in under a timeout (1h).
"""
import csv
import sys
from pathlib import Path
from runner.run_benchmarks import benchmark_solver, download_benchmark_file
benchmark = sys.argv[1]
timeout = 60 * 60
resolutions = ["24h", "12h", "3h", "1h"]
clusters = list(range(2, 11))
end_early = False
results_csv = Path(f"filter-{benchmark}.csv")
if not results_csv.exists():
with open(results_csv, mode="w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["benchmark", "status", "runtime"])
for r in resolutions:
for n in clusters:
lp_file = f"{benchmark}-{n}-{r}.lp"
gcp_url = "https://storage.googleapis.com/solver-benchmarks/" + lp_file
lp_path = Path("./runner/benchmarks/") / lp_file
download_benchmark_file(gcp_url, lp_path)
print(f"Solving {lp_file}..", flush=True)
m = benchmark_solver(lp_path, "highs", timeout, None)
print(m, flush=True)
with open(results_csv, mode="a", newline="") as file:
writer = csv.writer(file)
writer.writerow([lp_file, m["status"], m["runtime"]])
if m["status"] == "TO":
if n == 2:
end_early = True
break
if end_early:
break