This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
AICup/src/utils.py

20 lines
507 B
Python
Raw Normal View History

2020-09-25 11:20:28 +00:00
import numpy as np
2020-09-25 09:15:15 +00:00
def compute_length(solution, dist_matrix):
2019-11-10 09:42:13 +00:00
total_length = 0
starting_node = solution[0]
from_node = starting_node
for node in solution[1:]:
total_length += dist_matrix[from_node, node]
from_node = node
return total_length
2020-09-25 09:15:15 +00:00
2020-10-12 09:43:27 +00:00
def distance_euc(point_i, point_j):
2020-11-01 18:24:26 +00:00
rounding = 0
2020-10-12 09:43:27 +00:00
x_i, y_i = point_i[0], point_i[1]
x_j, y_j = point_j[0], point_j[1]
distance = np.sqrt((x_i - x_j) ** 2 + (y_i - y_j) ** 2)
return round(distance, rounding)