From f4c5e032d4ef721205f965dcf797749aa7c51e98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Chlubna?= <xchlubn1@fi.muni.cz>
Date: Fri, 18 Oct 2024 14:56:44 +0200
Subject: [PATCH] matrix_calculation

---
 main.py     | 17 ++++++++---------
 solution.py | 14 ++++++++++++--
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/main.py b/main.py
index 695912c..0a05662 100644
--- a/main.py
+++ b/main.py
@@ -1,7 +1,5 @@
-import random
 import sys
 import json
-import time
 from solution import *
 
 
@@ -16,16 +14,18 @@ def write_instance_json(solution, file_path):
 
 
 def print_our_solution(best_route, best_cost):
-    print("My route:", best_route)
-    print("My cost:", round(best_cost))
+    print("Our route:", best_route)
+    print("Our cost:", round(best_cost))
 
 
 def print_best_solution(instance):
     print("Best route:", instance['GlobalBest'])
     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?
 
 instance_path = sys.argv[1]
@@ -33,9 +33,9 @@ output_path = sys.argv[2]
 
 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_best_solution(instance)
 
@@ -57,4 +57,3 @@ write_instance_json(best_route, output_path)
 # ...
 #######################################################################
 #######################################################################
-
diff --git a/solution.py b/solution.py
index a62f782..26fa601 100644
--- a/solution.py
+++ b/solution.py
@@ -45,8 +45,18 @@ def zero_start(route):
     return [0] + route[zero_index + 1:] + route[:zero_index]
 
 
-def lns(coords, time_limit=120, destroy_fraction=0.2):
-    # it seems the matrix provided is inaccurate
+def print_travels(route, matrix):
+    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
     matrix = distance_matrix(coords)
     curr_route = greedy(matrix)
-- 
GitLab