Мне удалось выполнить упражнение, но мне интересно, есть ли возможность автоматизировать процесс расчета каждого маршрута.
original_route = [0, 4, 2, 1, 3, 0]
route_2 = [0, 3, 5, 2, 4, 6, 0]
route_3 = [0, 7, 6, 4, 1, 5, 0]
distance_matrix = [[0, 6, 12, 11, 6, 13, 8, 20, 7],
[6, 0, 7, 9, 7, 9, 12, 15, 13],
[12, 7, 0, 13, 10, 11, 16, 13, 19],
[11, 9, 13, 0, 15, 4, 19, 12, 14],
[6, 7, 10, 15, 0, 16, 6, 21, 12],
[13, 9, 11, 4, 16, 0, 21, 8, 18],
[8, 12, 16, 19, 6, 21, 0, 27, 10],
[20, 15, 13, 12, 21, 8, 27, 0, 26],
[7, 13, 19, 14, 12, 18, 10, 26, 0]]
cost_route = distance_matrix[0][4] + distance_matrix[4][2] + distance_matrix[2][1] + distance_matrix[1][3] + distance_matrix[3][0]
print("The cost of the original route: " + str(cost_route))
cost_route2 = distance_matrix[0][3] + distance_matrix[3][5] + distance_matrix[5][2] + distance_matrix[2][4] + distance_matrix[4][6] + distance_matrix[6][0]
print("The cost of route 2: " + str(cost_route2))
cost_route3 = distance_matrix[0][7] + distance_matrix[7][6] + distance_matrix[6][4] + distance_matrix[4][1] + distance_matrix[1][5] + distance_matrix[5][0]
print("The cost of route 3: " + str(cost_route3))
value = ['1, ' + str(cost_route), '2, ' + str(cost_route2), '3, ' + str(cost_route3)]
print('Best value has route ' + str(min(value)) + ' is the value.')
print('Worst value has route ' + str(max(value)) + ' is the value.')