[new] Implement container
This commit is contained in:
parent
e120708d8d
commit
89d429f69b
|
|
@ -0,0 +1 @@
|
|||
.vscode/
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
.vscode/
|
||||
*.json
|
||||
*.txt
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
.vscode/
|
||||
__pycache__/
|
||||
output/
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
FROM python:3.8
|
||||
|
||||
ADD ./ /tsp
|
||||
|
||||
WORKDIR /tsp
|
||||
|
||||
CMD ["/bin/bash", "-c", "pip install -r requirements.txt && python main.py; cp -r output/* /output"]
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
## Windows
|
||||
|
||||
docker container run -v $PWD/requirements.txt:/tsp/requirements.txt -v $PWD/output/:/output/ com2014-tsp
|
||||
docker container run --rm -v /f/COM2014/template:/tsp python:3.8 /bin/bash -c "cd /tsp; ./run_all.sh"
|
||||
|
||||
## Linux
|
||||
|
||||
docker container run --rm -v $pwd:/tsp python:3.8 /bin/bash -c "cd /tsp; ./run_all.sh"
|
||||
docker container run -v $PWD/requirements.txt:/tsp/requirements.txt -v $PWD/output/:/output/ com2014-tsp
|
||||
|
|
|
|||
163
main.py
163
main.py
|
|
@ -1,31 +1,12 @@
|
|||
import os
|
||||
import argparse
|
||||
|
||||
import signal
|
||||
import json
|
||||
|
||||
import matplotlib
|
||||
# matplotlib.use('TkAgg')
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from utils import visualize_tsp
|
||||
|
||||
from model.anneal_model import SimAnneal
|
||||
from model.my_model import MyModel
|
||||
|
||||
def write_to_file(solution, fitness):
|
||||
with open('output/' + os.path.splitext(os.path.basename(args.tsp_file))[0] + '.txt', "w") as outfile:
|
||||
outfile.write(", ".join(str(item) for item in solution))
|
||||
outfile.write("\n")
|
||||
outfile.write(str(fitness))
|
||||
|
||||
def plot_learning(fitness_list):
|
||||
"""
|
||||
Plot the fitness through iterations.
|
||||
"""
|
||||
plt.plot([i for i in range(len(fitness_list))], fitness_list)
|
||||
plt.ylabel("Fitness")
|
||||
plt.xlabel("Iteration")
|
||||
plt.show()
|
||||
def log(msg):
|
||||
print('[*] {msg}'.format(msg=msg))
|
||||
|
||||
def load_data(file):
|
||||
coords = []
|
||||
|
|
@ -42,57 +23,99 @@ def load_data(file):
|
|||
coords.append(line)
|
||||
return coords
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description='TSP Solver')
|
||||
parser.add_argument(
|
||||
'tsp_file',
|
||||
type=str,
|
||||
help='Path to tsp file.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--plot',
|
||||
action="store_true",
|
||||
help='Plot results'
|
||||
)
|
||||
args = parser.parse_args()
|
||||
def timeout_handler(signum, frame):
|
||||
print("Timeout")
|
||||
raise Exception("Timeout")
|
||||
|
||||
def TSP(tsp_file, model):
|
||||
|
||||
coords = load_data(args.tsp_file)
|
||||
best_solution = []
|
||||
fitness_list = []
|
||||
|
||||
# model = MyModel(coords)
|
||||
# best_solution, fitness_list = model.fit(max_it=100000)
|
||||
coords = load_data(tsp_file)
|
||||
|
||||
sa = SimAnneal(coords)
|
||||
best_solution, fitness_list = sa.fit(max_it=100000)
|
||||
# Set timeout
|
||||
signal.signal(signal.SIGALRM, timeout_handler)
|
||||
signal.alarm(60)
|
||||
|
||||
if best_solution:
|
||||
if args.plot:
|
||||
visualize_tsp.plotTSP([best_solution], coords)
|
||||
if fitness_list:
|
||||
plot_learning(fitness_list)
|
||||
print("Writing the best solution to file" )
|
||||
write_to_file(best_solution, sa.fitness(best_solution))
|
||||
|
||||
data = {}
|
||||
data['nodes'] = []
|
||||
for i in range(len(coords)):
|
||||
data['nodes'].append({
|
||||
'title': str(i),
|
||||
'id': i,
|
||||
'x': int(coords[i][0]),
|
||||
'y': int(coords[i][1])
|
||||
})
|
||||
data['edges'] = []
|
||||
for i in range(len(best_solution)):
|
||||
if i == len(best_solution)-1:
|
||||
data['edges'].append({
|
||||
'source': best_solution[i],
|
||||
'target': best_solution[0]
|
||||
})
|
||||
# Try your algorithm
|
||||
try:
|
||||
model.init(coords)
|
||||
best_solution, fitness_list = model.fit(max_it=100000)
|
||||
except Exception as exc:
|
||||
if(str(exc) == "Timeout"):
|
||||
log("Timeout -3")
|
||||
with open('output/' + os.path.splitext(os.path.basename(tsp_file))[0] + '.txt', "w") as outfile:
|
||||
outfile.write("-3")
|
||||
else:
|
||||
data['edges'].append({
|
||||
'source': best_solution[i],
|
||||
'target': best_solution[i+1]
|
||||
print(exc)
|
||||
log("Unkown -4")
|
||||
with open('output/' + os.path.splitext(os.path.basename(tsp_file))[0] + '.txt', "w") as outfile:
|
||||
outfile.write("-4")
|
||||
|
||||
# Collect results
|
||||
if(len(fitness_list) > 0):
|
||||
log("Best: " + str(fitness_list[-1]))
|
||||
|
||||
if (len(best_solution) == 0):
|
||||
log("No Answer -1")
|
||||
with open('output/' + os.path.splitext(os.path.basename(tsp_file))[0] + '.txt', "w") as outfile:
|
||||
outfile.write("-1")
|
||||
elif (len(best_solution) != len(coords)):
|
||||
log("Invalid -2")
|
||||
with open('output/' + os.path.splitext(os.path.basename(tsp_file))[0] + '.txt', "w") as outfile:
|
||||
outfile.write("-2")
|
||||
else:
|
||||
log("Writing the best solution to file" )
|
||||
with open('output/' + os.path.splitext(os.path.basename(tsp_file))[0] + '.txt', "w") as outfile:
|
||||
outfile.write(str(model.fitness(best_solution)))
|
||||
outfile.write("\n")
|
||||
outfile.write(", ".join(str(item) for item in best_solution))
|
||||
|
||||
# Write to JSON
|
||||
data = {}
|
||||
|
||||
data['nodes'] = []
|
||||
for i in range(len(coords)):
|
||||
data['nodes'].append({
|
||||
'title': str(i),
|
||||
'id': i,
|
||||
'x': int(coords[i][0]),
|
||||
'y': int(coords[i][1])
|
||||
})
|
||||
|
||||
with open('output/' + os.path.splitext(os.path.basename(args.tsp_file))[0] + '.json', 'w') as outfile:
|
||||
json.dump(data, outfile)
|
||||
|
||||
data['edges'] = []
|
||||
for i in range(len(best_solution)):
|
||||
if i == len(best_solution)-1:
|
||||
data['edges'].append({
|
||||
'source': best_solution[i],
|
||||
'target': best_solution[0]
|
||||
})
|
||||
else:
|
||||
data['edges'].append({
|
||||
'source': best_solution[i],
|
||||
'target': best_solution[i+1]
|
||||
})
|
||||
|
||||
with open('output/' + os.path.splitext(os.path.basename(tsp_file))[0] + '.json', 'w') as outfile:
|
||||
json.dump(data, outfile)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
for root, _, files in os.walk('./data'):
|
||||
if(files):
|
||||
for f in files:
|
||||
# Get input file name
|
||||
tsp_file = str(root) + '/' + str(f)
|
||||
log(tsp_file)
|
||||
|
||||
# Your Model
|
||||
# model = MyModel()
|
||||
|
||||
# Simulated Annealing
|
||||
model = SimAnneal()
|
||||
|
||||
TSP(tsp_file, model)
|
||||
|
||||
print()
|
||||
|
|
|
|||
|
|
@ -1,19 +1,24 @@
|
|||
import math
|
||||
import random
|
||||
import matplotlib.pyplot as plt
|
||||
from model.base_model import Model
|
||||
|
||||
class SimAnneal(Model):
|
||||
def __init__(self, coords, T=-1, alpha=-1, stopping_T=-1):
|
||||
super().__init__(coords)
|
||||
def __init__(self, T=-1, alpha=-1, stopping_T=-1):
|
||||
super().__init__()
|
||||
|
||||
self.iteration = 0
|
||||
|
||||
self.T = math.sqrt(self.N) if T == -1 else T
|
||||
self.T_save = self.T # save inital T to reset if batch annealing is used
|
||||
self.T = T
|
||||
self.alpha = 0.995 if alpha == -1 else alpha
|
||||
self.stopping_temperature = 1e-8 if stopping_T == -1 else stopping_T
|
||||
|
||||
def init(self, coords):
|
||||
super().init(coords)
|
||||
|
||||
if (self.T == -1):
|
||||
self.T = math.sqrt(self.N)
|
||||
self.T_save = self.T # save inital T to reset if batch annealing is used
|
||||
|
||||
def initial_solution(self):
|
||||
"""
|
||||
Greedy algorithm to get an initial solution (closest-neighbour).
|
||||
|
|
|
|||
|
|
@ -2,15 +2,16 @@ import math
|
|||
|
||||
class Model:
|
||||
|
||||
def __init__(self, coords):
|
||||
def __init__(self):
|
||||
self.best_solution = []
|
||||
self.best_fitness = float("Inf")
|
||||
self.fitness_list = []
|
||||
|
||||
def init(self, coords):
|
||||
self.coords = coords
|
||||
self.N = len(coords)
|
||||
self.nodes = [i for i in range(self.N)]
|
||||
|
||||
self.best_solution = None
|
||||
self.best_fitness = float("Inf")
|
||||
self.fitness_list = []
|
||||
|
||||
def dist(self, node_0, node_1):
|
||||
"""
|
||||
Euclidean distance between two nodes.
|
||||
|
|
|
|||
|
|
@ -3,11 +3,14 @@ import random
|
|||
from model.base_model import Model
|
||||
|
||||
class MyModel(Model):
|
||||
def __init__(self, coords):
|
||||
super().__init__(coords)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def init(self, coords):
|
||||
"""
|
||||
Put your initialization here.
|
||||
"""
|
||||
super().init(coords)
|
||||
self.log("Nothing to initialize in your model now")
|
||||
|
||||
def fit(self, max_it=1000, visualize=False):
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1 +0,0 @@
|
|||
198, 199, 201, 202, 142, 143, 144, 145, 146, 148, 149, 177, 150, 151, 155, 152, 154, 153, 128, 129, 130, 131, 132, 14, 269, 133, 134, 135, 136, 137, 265, 264, 263, 262, 261, 260, 259, 258, 257, 256, 253, 252, 251, 254, 255, 248, 247, 0, 4, 5, 8, 6, 7, 9, 10, 11, 12, 13, 23, 22, 24, 21, 25, 26, 27, 28, 31, 30, 29, 124, 125, 126, 127, 20, 19, 18, 17, 16, 15, 270, 271, 272, 273, 274, 275, 276, 3, 277, 278, 2, 279, 1, 241, 242, 244, 245, 236, 235, 234, 233, 232, 231, 230, 237, 238, 239, 240, 243, 246, 249, 250, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 215, 214, 213, 212, 211, 206, 210, 209, 208, 207, 203, 204, 205, 268, 267, 266, 139, 138, 147, 140, 141, 119, 120, 121, 122, 123, 33, 32, 35, 34, 37, 36, 38, 39, 40, 41, 42, 59, 60, 117, 116, 114, 113, 110, 109, 107, 103, 82, 87, 111, 108, 88, 89, 90, 91, 96, 95, 94, 93, 92, 97, 98, 99, 100, 101, 102, 81, 80, 79, 78, 75, 74, 73, 72, 71, 70, 69, 66, 65, 64, 63, 62, 61, 115, 85, 84, 83, 86, 112, 106, 172, 104, 105, 77, 76, 68, 67, 57, 56, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 58, 118, 156, 157, 158, 159, 173, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 174, 184, 183, 182, 181, 180, 175, 176, 179, 178, 185, 186, 187, 188, 189, 190, 191, 192, 200, 195, 194, 193, 196, 197
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"nodes": [{"title": "0", "id": 0, "x": 6734, "y": 1453}, {"title": "1", "id": 1, "x": 2233, "y": 10}, {"title": "2", "id": 2, "x": 5530, "y": 1424}, {"title": "3", "id": 3, "x": 401, "y": 841}, {"title": "4", "id": 4, "x": 3082, "y": 1644}, {"title": "5", "id": 5, "x": 7608, "y": 4458}, {"title": "6", "id": 6, "x": 7573, "y": 3716}, {"title": "7", "id": 7, "x": 7265, "y": 1268}, {"title": "8", "id": 8, "x": 6898, "y": 1885}, {"title": "9", "id": 9, "x": 1112, "y": 2049}, {"title": "10", "id": 10, "x": 5468, "y": 2606}, {"title": "11", "id": 11, "x": 5989, "y": 2873}, {"title": "12", "id": 12, "x": 4706, "y": 2674}, {"title": "13", "id": 13, "x": 4612, "y": 2035}, {"title": "14", "id": 14, "x": 6347, "y": 2683}, {"title": "15", "id": 15, "x": 6107, "y": 669}, {"title": "16", "id": 16, "x": 7611, "y": 5184}, {"title": "17", "id": 17, "x": 7462, "y": 3590}, {"title": "18", "id": 18, "x": 7732, "y": 4723}, {"title": "19", "id": 19, "x": 5900, "y": 3561}, {"title": "20", "id": 20, "x": 4483, "y": 3369}, {"title": "21", "id": 21, "x": 6101, "y": 1110}, {"title": "22", "id": 22, "x": 5199, "y": 2182}, {"title": "23", "id": 23, "x": 1633, "y": 2809}, {"title": "24", "id": 24, "x": 4307, "y": 2322}, {"title": "25", "id": 25, "x": 675, "y": 1006}, {"title": "26", "id": 26, "x": 7555, "y": 4819}, {"title": "27", "id": 27, "x": 7541, "y": 3981}, {"title": "28", "id": 28, "x": 3177, "y": 756}, {"title": "29", "id": 29, "x": 7352, "y": 4506}, {"title": "30", "id": 30, "x": 7545, "y": 2801}, {"title": "31", "id": 31, "x": 3245, "y": 3305}, {"title": "32", "id": 32, "x": 6426, "y": 3173}, {"title": "33", "id": 33, "x": 4608, "y": 1198}, {"title": "34", "id": 34, "x": 23, "y": 2216}, {"title": "35", "id": 35, "x": 7248, "y": 3779}, {"title": "36", "id": 36, "x": 7762, "y": 4595}, {"title": "37", "id": 37, "x": 7392, "y": 2244}, {"title": "38", "id": 38, "x": 3484, "y": 2829}, {"title": "39", "id": 39, "x": 6271, "y": 2135}, {"title": "40", "id": 40, "x": 4985, "y": 140}, {"title": "41", "id": 41, "x": 1916, "y": 1569}, {"title": "42", "id": 42, "x": 7280, "y": 4899}, {"title": "43", "id": 43, "x": 7509, "y": 3239}, {"title": "44", "id": 44, "x": 10, "y": 2676}, {"title": "45", "id": 45, "x": 6807, "y": 2993}, {"title": "46", "id": 46, "x": 5185, "y": 3258}, {"title": "47", "id": 47, "x": 3023, "y": 1942}], "edges": [{"source": 36, "target": 5}, {"source": 5, "target": 27}, {"source": 27, "target": 6}, {"source": 6, "target": 17}, {"source": 17, "target": 43}, {"source": 43, "target": 30}, {"source": 30, "target": 37}, {"source": 37, "target": 8}, {"source": 8, "target": 7}, {"source": 7, "target": 0}, {"source": 0, "target": 15}, {"source": 15, "target": 21}, {"source": 21, "target": 2}, {"source": 2, "target": 39}, {"source": 39, "target": 14}, {"source": 14, "target": 11}, {"source": 11, "target": 10}, {"source": 10, "target": 22}, {"source": 22, "target": 33}, {"source": 33, "target": 40}, {"source": 40, "target": 1}, {"source": 1, "target": 28}, {"source": 28, "target": 4}, {"source": 4, "target": 47}, {"source": 47, "target": 41}, {"source": 41, "target": 9}, {"source": 9, "target": 25}, {"source": 25, "target": 3}, {"source": 3, "target": 34}, {"source": 34, "target": 44}, {"source": 44, "target": 23}, {"source": 23, "target": 31}, {"source": 31, "target": 38}, {"source": 38, "target": 24}, {"source": 24, "target": 13}, {"source": 13, "target": 12}, {"source": 12, "target": 20}, {"source": 20, "target": 46}, {"source": 46, "target": 19}, {"source": 19, "target": 32}, {"source": 32, "target": 45}, {"source": 45, "target": 35}, {"source": 35, "target": 29}, {"source": 29, "target": 42}, {"source": 42, "target": 16}, {"source": 16, "target": 26}, {"source": 26, "target": 18}, {"source": 18, "target": 36}]}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
36, 5, 27, 6, 17, 43, 30, 37, 8, 7, 0, 15, 21, 2, 39, 14, 11, 10, 22, 33, 40, 1, 28, 4, 47, 41, 9, 25, 3, 34, 44, 23, 31, 38, 24, 13, 12, 20, 46, 19, 32, 45, 35, 29, 42, 16, 26, 18
|
||||
34767.13377984314
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1 +0,0 @@
|
|||
694, 113, 939, 256, 50, 268, 148, 225, 578, 555, 618, 839, 110, 565, 336, 169, 719, 645, 22, 988, 71, 426, 203, 924, 157, 216, 905, 904, 981, 61, 920, 27, 280, 348, 477, 604, 586, 133, 86, 942, 33, 761, 695, 840, 548, 361, 838, 226, 89, 774, 321, 460, 272, 932, 400, 165, 470, 862, 444, 830, 688, 293, 125, 69, 552, 340, 66, 317, 949, 790, 376, 474, 175, 923, 166, 598, 91, 692, 625, 57, 664, 935, 999, 525, 241, 164, 350, 457, 691, 879, 387, 735, 849, 243, 158, 700, 53, 287, 757, 616, 270, 220, 109, 54, 418, 965, 998, 60, 919, 928, 887, 946, 911, 955, 933, 982, 636, 617, 914, 143, 150, 120, 325, 356, 172, 452, 505, 315, 333, 486, 288, 327, 817, 85, 889, 64, 730, 469, 876, 722, 909, 822, 337, 745, 250, 18, 813, 439, 716, 238, 490, 2, 902, 568, 1, 630, 690, 708, 627, 668, 468, 709, 373, 612, 424, 798, 814, 132, 812, 11, 802, 882, 379, 984, 750, 967, 642, 845, 402, 715, 180, 652, 35, 874, 826, 357, 521, 459, 210, 52, 499, 608, 219, 45, 329, 921, 257, 571, 605, 67, 77, 507, 346, 105, 184, 233, 723, 8, 558, 808, 714, 343, 682, 332, 886, 888, 675, 729, 401, 3, 393, 147, 508, 601, 269, 846, 858, 378, 58, 129, 950, 893, 117, 947, 580, 285, 101, 683, 587, 196, 326, 182, 78, 576, 183, 677, 420, 246, 141, 208, 957, 433, 769, 394, 827, 660, 413, 301, 562, 788, 569, 989, 185, 530, 389, 539, 335, 375, 903, 742, 82, 943, 994, 676, 739, 98, 964, 349, 137, 410, 396, 743, 324, 986, 762, 556, 776, 538, 991, 810, 799, 144, 746, 952, 405, 437, 531, 42, 929, 298, 179, 828, 661, 895, 996, 665, 372, 63, 689, 121, 75, 311, 465, 509, 199, 48, 853, 993, 599, 510, 30, 574, 831, 451, 685, 478, 344, 93, 733, 657, 663, 978, 138, 969, 713, 41, 785, 559, 693, 209, 65, 979, 95, 207, 438, 171, 448, 328, 248, 330, 670, 367, 430, 309, 239, 440, 192, 359, 339, 43, 875, 278, 899, 191, 228, 631, 39, 892, 768, 633, 863, 254, 56, 613, 201, 533, 523, 384, 756, 970, 76, 299, 323, 0, 913, 816, 727, 870, 658, 421, 247, 883, 600, 259, 619, 291, 951, 796, 560, 609, 511, 726, 149, 543, 513, 654, 255, 561, 265, 881, 678, 841, 181, 963, 386, 371, 966, 614, 84, 135, 347, 520, 632, 195, 607, 623, 249, 20, 857, 189, 385, 740, 687, 140, 279, 650, 151, 824, 891, 537, 829, 206, 284, 504, 320, 634, 446, 703, 566, 805, 635, 17, 363, 641, 498, 198, 747, 593, 236, 864, 620, 44, 15, 355, 139, 681, 163, 916, 527, 835, 749, 671, 70, 651, 995, 649, 976, 304, 930, 290, 119, 759, 990, 23, 388, 901, 512, 698, 240, 878, 126, 251, 253, 837, 792, 118, 961, 653, 155, 34, 488, 721, 364, 844, 815, 271, 992, 443, 771, 5, 557, 72, 366, 953, 900, 10, 544, 496, 4, 382, 99, 370, 515, 134, 850, 734, 940, 186, 753, 781, 314, 804, 87, 322, 473, 342, 260, 302, 704, 88, 463, 501, 19, 374, 583, 673, 896, 123, 997, 503, 975, 725, 136, 977, 922, 859, 567, 528, 414, 49, 292, 106, 731, 194, 908, 403, 594, 592, 492, 485, 534, 843, 114, 907, 399, 471, 787, 591, 884, 46, 755, 679, 934, 854, 390, 820, 973, 818, 795, 710, 427, 154, 640, 680, 867, 526, 581, 550, 834, 24, 28, 639, 717, 624, 51, 79, 274, 936, 408, 319, 590, 177, 821, 754, 295, 267, 419, 29, 103, 737, 242, 546, 111, 877, 395, 116, 656, 575, 286, 885, 603, 313, 825, 397, 235, 237, 338, 861, 648, 540, 218, 383, 434, 748, 779, 915, 549, 416, 773, 73, 415, 354, 142, 458, 487, 570, 391, 707, 483, 728, 643, 153, 766, 647, 204, 628, 958, 494, 466, 851, 168, 252, 602, 244, 780, 906, 124, 289, 97, 823, 152, 985, 584, 532, 775, 941, 261, 701, 702, 622, 377, 786, 873, 227, 454, 432, 447, 987, 331, 772, 758, 365, 744, 96, 316, 442, 541, 406, 156, 491, 535, 334, 564, 514, 223, 597, 644, 345, 712, 763, 341, 234, 423, 765, 422, 791, 711, 193, 944, 684, 74, 476, 300, 160, 263, 767, 596, 778, 782, 666, 793, 706, 972, 221, 971, 962, 264, 37, 637, 231, 522, 90, 453, 577, 100, 130, 435, 59, 582, 294, 68, 450, 662, 282, 230, 13, 484, 202, 610, 16, 638, 848, 407, 224, 480, 718, 353, 9, 159, 938, 832, 736, 983, 128, 428, 871, 215, 489, 112, 801, 855, 167, 777, 529, 732, 307, 398, 869, 102, 847, 968, 62, 866, 751, 273, 524, 436, 455, 174, 358, 32, 927, 277, 38, 974, 836, 217, 669, 931, 412, 720, 800, 200, 360, 784, 312, 297, 21, 629, 6, 760, 872, 12, 211, 789, 266, 880, 910, 926, 588, 481, 409, 572, 621, 368, 925, 411, 495, 868, 752, 589, 456, 699, 197, 615, 536, 553, 188, 472, 842, 819, 794, 585, 865, 579, 646, 104, 674, 245, 464, 92, 55, 352, 351, 229, 595, 310, 429, 214, 449, 275, 431, 222, 506, 960, 705, 131, 146, 738, 811, 190, 860, 890, 94, 551, 741, 945, 563, 362, 917, 912, 764, 127, 667, 894, 606, 425, 14, 806, 545, 672, 956, 852, 213, 81, 145, 303, 36, 176, 547, 25, 783, 809, 697, 696, 519, 122, 626, 276, 107, 80, 318, 833, 7, 26, 500, 283, 445, 897, 47, 205, 381, 980, 380, 770, 392, 948, 187, 517, 305, 959, 542, 807, 803, 573, 369, 475, 462, 482, 467, 170, 232, 417, 115, 40, 306, 262, 659, 308, 161, 954, 83, 108, 497, 281, 516, 898, 296, 518, 441, 404, 173, 162, 178, 937, 479, 461, 918, 724, 502, 212, 655, 686, 493, 856, 797, 31, 554, 258, 611
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1 +0,0 @@
|
|||
18, 17, 16, 15, 14, 13, 70, 71, 72, 73, 74, 75, 99, 78, 79, 80, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 0, 1, 2, 3, 4, 441, 69, 68, 67, 66, 65, 101, 102, 113, 125, 135, 148, 160, 171, 184, 399, 404, 226, 233, 237, 238, 265, 268, 272, 275, 278, 280, 281, 427, 341, 340, 345, 346, 347, 432, 348, 349, 350, 351, 342, 352, 353, 354, 433, 355, 356, 357, 434, 358, 359, 360, 343, 361, 362, 363, 364, 365, 366, 344, 367, 368, 369, 370, 371, 372, 373, 374, 337, 336, 426, 335, 334, 333, 306, 332, 331, 330, 305, 304, 303, 302, 301, 300, 299, 298, 297, 296, 295, 294, 293, 292, 291, 290, 289, 288, 287, 286, 285, 284, 283, 282, 279, 425, 439, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 428, 324, 325, 326, 327, 328, 329, 430, 429, 277, 416, 417, 252, 431, 421, 418, 411, 412, 206, 205, 194, 195, 110, 122, 132, 145, 157, 168, 181, 196, 207, 217, 225, 219, 209, 198, 183, 170, 159, 147, 134, 124, 112, 383, 382, 97, 96, 379, 95, 378, 94, 62, 63, 64, 32, 376, 375, 31, 30, 29, 28, 61, 93, 92, 100, 435, 111, 123, 133, 146, 158, 169, 182, 197, 208, 218, 410, 409, 413, 236, 264, 436, 274, 437, 422, 271, 419, 267, 415, 263, 235, 262, 261, 260, 259, 258, 257, 256, 255, 254, 253, 231, 223, 214, 202, 178, 394, 393, 389, 387, 143, 390, 384, 120, 109, 121, 131, 144, 156, 167, 180, 193, 204, 216, 403, 408, 407, 232, 224, 215, 203, 192, 191, 179, 166, 155, 142, 130, 119, 108, 381, 380, 438, 107, 118, 129, 141, 154, 165, 177, 397, 190, 189, 201, 401, 200, 188, 176, 163, 164, 153, 140, 128, 117, 106, 105, 104, 116, 115, 137, 391, 151, 150, 388, 386, 440, 103, 114, 385, 126, 136, 149, 161, 172, 185, 400, 405, 227, 234, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 414, 249, 250, 251, 230, 222, 213, 396, 175, 162, 152, 138, 127, 139, 392, 174, 186, 398, 395, 173, 406, 402, 210, 220, 228, 211, 212, 199, 187, 221, 229, 420, 424, 423, 339, 338, 276, 273, 270, 266, 269, 98, 77, 76, 5, 6, 7, 8, 9, 10, 11, 12, 48, 49, 50, 51, 52, 53, 54, 55, 56, 19, 20, 21, 22, 23, 24, 25, 26, 27, 60, 57, 58, 59, 91, 90, 89, 88, 87, 377, 86, 85, 84, 83, 82, 81
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1 +0,0 @@
|
|||
63, 10, 66, 47, 53, 32, 59, 51, 9, 4, 52, 20, 16, 42, 40, 3, 17, 41, 5, 11, 33, 61, 60, 39, 38, 24, 44, 45, 26, 8, 67, 43, 29, 19, 13, 27, 7, 25, 48, 54, 18, 6, 31, 2, 1, 23, 14, 56, 62, 65, 21, 58, 37, 22, 12, 68, 30, 34, 69, 28, 35, 0, 15, 46, 36, 57, 49, 50, 55, 64
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"nodes": [{"title": "0", "id": 0, "x": 38, "y": 20}, {"title": "1", "id": 1, "x": 39, "y": 26}, {"title": "2", "id": 2, "x": 40, "y": 25}, {"title": "3", "id": 3, "x": 36, "y": 23}, {"title": "4", "id": 4, "x": 33, "y": 10}, {"title": "5", "id": 5, "x": 37, "y": 12}, {"title": "6", "id": 6, "x": 38, "y": 13}, {"title": "7", "id": 7, "x": 37, "y": 20}, {"title": "8", "id": 8, "x": 41, "y": 9}, {"title": "9", "id": 9, "x": 41, "y": 13}, {"title": "10", "id": 10, "x": 36, "y": -5}, {"title": "11", "id": 11, "x": 38, "y": 15}, {"title": "12", "id": 12, "x": 38, "y": 15}, {"title": "13", "id": 13, "x": 37, "y": 15}, {"title": "14", "id": 14, "x": 35, "y": 14}, {"title": "15", "id": 15, "x": 39, "y": 19}], "edges": [{"source": 7, "target": 3}, {"source": 3, "target": 1}, {"source": 1, "target": 2}, {"source": 2, "target": 0}, {"source": 0, "target": 15}, {"source": 15, "target": 12}, {"source": 12, "target": 11}, {"source": 11, "target": 6}, {"source": 6, "target": 5}, {"source": 5, "target": 9}, {"source": 9, "target": 8}, {"source": 8, "target": 10}, {"source": 10, "target": 4}, {"source": 4, "target": 14}, {"source": 14, "target": 13}, {"source": 13, "target": 7}]}
|
||||
|
|
@ -1 +0,0 @@
|
|||
7, 3, 1, 2, 0, 15, 12, 11, 6, 5, 9, 8, 10, 4, 14, 13
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
matplotlib
|
||||
scikit-learn
|
||||
scipy
|
||||
numpy
|
||||
12
run_all.sh
12
run_all.sh
|
|
@ -1,12 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
pip install -r requirements.txt
|
||||
|
||||
python main.py data/simple/ulysses16.tsp
|
||||
python main.py data/simple/att48.tsp
|
||||
python main.py data/simple/st70.tsp
|
||||
|
||||
python main.py data/medium/a280.tsp
|
||||
python main.py data/medium/pcb442.tsp
|
||||
|
||||
python main.py data/hard/dsj1000.tsp
|
||||
|
|
@ -1,5 +1,15 @@
|
|||
import matplotlib.pyplot as plt
|
||||
|
||||
def plot_learning(fitness_list):
|
||||
"""
|
||||
Plot the fitness through iterations.
|
||||
"""
|
||||
plt.plot([i for i in range(len(fitness_list))], fitness_list)
|
||||
plt.ylabel("Fitness")
|
||||
plt.xlabel("Iteration")
|
||||
plt.show()
|
||||
|
||||
|
||||
def plotTSP(paths, points, num_iters=1):
|
||||
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in New Issue