forked from robinbb77/DCA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_solutions.py
More file actions
47 lines (37 loc) · 1.35 KB
/
fix_solutions.py
File metadata and controls
47 lines (37 loc) · 1.35 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
import math
from functions import read_instance, lookup_travel_distance, write_instance
import pathlib
import csv
import pandas as pd
# Directory path
directory = str(pathlib.Path().resolve())
def fix_solution(instance):
# Instance
W, H, N, w_i, v_i, S, alpha, u, mean_u = read_instance(instance)
# Current csv
path = directory + "/output/sol" + str(instance) + ".csv"
with open(path, newline='') as f:
reader = csv.reader(f)
group = next(reader)[0]
i = int(next(reader)[0])
obj_value = float(next(reader)[0])
total_distance = 0
i = 0
coordinates = []
for row in reader:
x,y,n,k = row
x = int(x)
y = float(y)
n = int(n)
k = int(k)
travel_distance = round(2 * y * (1 + alpha[i]),2) + round(alpha[i],2) * lookup_travel_distance(n, k, 1, S[i], w_i, v_i) + lookup_travel_distance(n, k, u[i], S[i], w_i, v_i)
total_distance = total_distance + round(travel_distance,2)
coordinates.append([x,y,n,k])
i = i + 1
print(total_distance)
if total_distance is math.inf or total_distance == 0:
write_instance(instance, -1, [], force=True)
else:
write_instance(instance, round(total_distance, 2), coordinates, force=True)
for i in range(1,450):
fix_solution(i)