-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilterHeuristicSolutions.py
More file actions
33 lines (30 loc) · 1.22 KB
/
filterHeuristicSolutions.py
File metadata and controls
33 lines (30 loc) · 1.22 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
import os
path = "C:/Users/Jan/Dropbox/Bachelorarbeit/Programm/Ergebnisse"
test_sets = [file for file in os.listdir(path) if "cap" in file]
elements = []
solution_val = 0.0
optimal_solution_val = 0.0
for testset in test_sets:
sol_file = path+"/"+testset+"/"+"_solution"+testset+".sol"
with open(sol_file) as f:
for line in f:
if "# Objective value = " in line:
optimal_solution_val = float(line.split(" ")[-1])
files = [file for file in os.listdir(path+"/"+testset) if "solution" not in file]
for file in files:
with open(path+"/"+testset+"/"+file, 'r') as f:
for line in f:
if "Soltuion:" in line:
solution_val = float(line.split(" ")[-1])
if solution_val != 0.0:
gap = (solution_val - optimal_solution_val) / optimal_solution_val
if gap > 0.02:
try:
if os.path.exists(path+"/"+testset+"/"+file):
os.remove(path+"/"+testset+"/"+file)
except:
print("Cant remove")
with open(path+"/"+testset+"/"+file, "a") as f:
f.write("\n")
f.write("GAP : "+ str(gap))
solution_val = 0.0