-
Notifications
You must be signed in to change notification settings - Fork 0
/
Checker.py
72 lines (58 loc) · 1.91 KB
/
Checker.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
63
64
65
66
67
68
69
70
71
import math
from Node import Node
NODES = []
T_MAX = []
def read_file(file_name):
file_path = "Instances/" + file_name + ".txt"
file = open(file_path, "r")
lines = file.readlines()
lines_len = len(lines)
for i in range (lines_len):
line_list = [float(x) for x in lines[i].split()]
if(i == 0):
T_MAX.append(line_list[0])
continue
else:
node = Node(i, line_list[0], line_list[1], line_list[2])
NODES.append(node)
def distance(node1, node2):
return math.sqrt((node1.x - node2.x)**2 + (node1.y- node2.y)**2)
def unique_checker(solution):
for i in range(len(solution)):
for j in range(len(solution)):
if i != j:
if solution[i] == solution[j]:
return False
return True
def checker(solution):
if(solution[0]!= 1):
print("Not correct")
return
if(not unique_checker(solution)):
print("Solution does not contain unique elements")
return
t_max = T_MAX[0]
time = 0
profit = 0
for index in range (len(solution)):
node_id = solution[index]
current_node = NODES[node_id - 1]
if(time > t_max):
print("Can't visit", node_id)
break
print("We can visit node", node_id)
profit += current_node.profit
if(index < len(solution) - 1):
next_node_id = solution[index + 1]
next_node = NODES[next_node_id - 1]
travel_time = distance(current_node, next_node)
print("Travel time from", node_id, "to", next_node_id,":",travel_time)
time += travel_time
print("Time unitll now", time)
print("Profit", profit)
print("Time", time)
# read file and initalise data
read_file("set_66_1_050")
# put solution here
solution_array = [1,3,5,6,7,9]
checker(solution_array)