Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import random
import sys
import json
import time
from solution import *
def read_instance_json(file_path):
with open(file_path) as f:
return json.load(f)
def write_instance_json(solution, file_path):
with open(file_path, 'w') as f:
json.dump(solution, f)
def print_our_solution(best_route, best_cost):
print("My route:", best_route)
print("My cost:", round(best_cost))
def print_best_solution(instance):
print("Best route:", instance['GlobalBest'])
print("Best cost:", instance['GlobalBestVal'])
instance_path = sys.argv[1]
output_path = sys.argv[2]
instance = read_instance_json(instance_path)
best_route, best_cost = lns(instance['Coordinates'], instance['Timeout']-1)
# todo: comment out the next part
print_our_solution(best_route, best_cost)
print_best_solution(instance)
write_instance_json(best_route, output_path)
# naive_solution = [i for i in range(len(instance['Matrix']))]
# write_instance_json(naive_solution, output_path)
#######################################################################
# Example of the required timeout mechanism within the LNS structure: #
#######################################################################
# ...
# time_limit = instance['Timeout']
# start_time = time.time()
# for iteration in range(9999999999):
# ...logic of one search iteration...
# if time.time() - start_time >= time_limit:
# break
# ...
#######################################################################
#######################################################################