20 lines
505 B
Python
20 lines
505 B
Python
import numpy as np
|
|
|
|
|
|
def compute_length(solution, dist_matrix):
|
|
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
|
|
|
|
|
|
def distance_euc(point_i, point_j):
|
|
rounding=0
|
|
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)
|