Skip to content
Snippets Groups Projects
Commit f4c5e032 authored by Ondřej Chlubna's avatar Ondřej Chlubna
Browse files

matrix_calculation

parent 00e52dc0
No related branches found
No related tags found
No related merge requests found
import random
import sys import sys
import json import json
import time
from solution import * from solution import *
...@@ -16,16 +14,18 @@ def write_instance_json(solution, file_path): ...@@ -16,16 +14,18 @@ def write_instance_json(solution, file_path):
def print_our_solution(best_route, best_cost): def print_our_solution(best_route, best_cost):
print("My route:", best_route) print("Our route:", best_route)
print("My cost:", round(best_cost)) print("Our cost:", round(best_cost))
def print_best_solution(instance): def print_best_solution(instance):
print("Best route:", instance['GlobalBest']) print("Best route:", instance['GlobalBest'])
print("Best cost:", instance['GlobalBestVal']) print("Best cost:", instance['GlobalBestVal'])
# TODO: insted of calculate_distance create incremental evaluation
# TODO: look for better hypermarameters # TODO: instead of calculate_distance create incremental evaluation
# TODO: look into distance calculation. It seems the matrices are inaccurate because they use only int
# TODO: look for better hyperparameters
# TODO: are these methods the best possible ones? # TODO: are these methods the best possible ones?
instance_path = sys.argv[1] instance_path = sys.argv[1]
...@@ -33,9 +33,9 @@ output_path = sys.argv[2] ...@@ -33,9 +33,9 @@ output_path = sys.argv[2]
instance = read_instance_json(instance_path) instance = read_instance_json(instance_path)
best_route, best_cost = lns(instance['Coordinates'], instance['Timeout']-1) best_route, best_cost = lns(instance['Matrix'], instance['Coordinates'], instance['Timeout']-1)
# TODO: before submition comment out the next part # TODO: before submission comment out the next part
print_our_solution(best_route, best_cost) print_our_solution(best_route, best_cost)
print_best_solution(instance) print_best_solution(instance)
...@@ -57,4 +57,3 @@ write_instance_json(best_route, output_path) ...@@ -57,4 +57,3 @@ write_instance_json(best_route, output_path)
# ... # ...
####################################################################### #######################################################################
####################################################################### #######################################################################
...@@ -45,8 +45,18 @@ def zero_start(route): ...@@ -45,8 +45,18 @@ def zero_start(route):
return [0] + route[zero_index + 1:] + route[:zero_index] return [0] + route[zero_index + 1:] + route[:zero_index]
def lns(coords, time_limit=120, destroy_fraction=0.2): def print_travels(route, matrix):
# it seems the matrix provided is inaccurate route = zero_start(route)
distance = 0
for i in range(len(route)-1):
distance += matrix[route[i]][route[i+1]]
print(route[i], distance, matrix[route[i]][route[i+1]])
distance += matrix[route[-1]][route[0]]
print(route[-1], distance, matrix[route[-1]][route[0]])
def lns(matrix, coords, time_limit=120, destroy_fraction=0.2):
# it seems the matrices provided are inaccurate, cause they don't use floats
# TODO: look into this # TODO: look into this
matrix = distance_matrix(coords) matrix = distance_matrix(coords)
curr_route = greedy(matrix) curr_route = greedy(matrix)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment