diff --git a/.assets/images/stats_aco_alpha1-2_beta2-5.png b/.assets/images/stats_aco_alpha1-2_beta2-5.png new file mode 100644 index 0000000..8085d97 Binary files /dev/null and b/.assets/images/stats_aco_alpha1-2_beta2-5.png differ diff --git a/tests/101_analyse_aco.py b/tests/101_analyse_aco.py index c8d2694..e3aadae 100644 --- a/tests/101_analyse_aco.py +++ b/tests/101_analyse_aco.py @@ -1,9 +1,11 @@ from matplotlib import pyplot as plt from libs.aco import AntColony, total_distance -name = "att48" -cities = [[6734, 1453], [2233, 10], [5530, 1424], [401, 841], [3082, 1644], [7608, 4458], [7573, 3716], [7265, 1268], [6898, 1885], [1112, 2049], [5468, 2606], [5989, 2873], [4706, 2674], [4612, 2035], [6347, 2683], [6107, 669], [7611, 5184], [7462, 3590], [7732, 4723], [5900, 3561], [4483, 3369], [6101, 1110], [5199, 2182], [1633, 2809], [4307, 2322], [675, 1006], [7555, 4819], [7541, 3981], [3177, 756], [7352, 4506], [7545, 2801], [3245, 3305], [6426, 3173], [4608, 1198], [23, 2216], [7248, 3779], [7762, 4595], [7392, 2244], [3484, 2829], [6271, 2135], [4985, 140], [1916, 1569], [7280, 4899], [7509, 3239], [10, 2676], [6807, 2993], [5185, 3258], [3023, 1942]] -optimal = 33523 +name = "berlin52" +cities = [[565, 575], [25, 185], [345, 750], [945, 685], [845, 655], [880, 660], [25, 230], [525, 1000], [580, 1175], [650, 1130], [1605, 620], [1220, 580], [1465, 200], [1530, 5], [845, 680], [725, 370], [145, 665], [415, 635], [510, 875], [560, 365], [300, 465], [520, 585], [480, 415], +[835, 625], [975, 580], [1215, 245], [1320, 315], [1250, 400], [660, 180], [410, 250], [420, 555], [575, 665], [1150, 1160], [700, 580], [685, 595], [685, 610], [770, 610], [795, 645], [720, 635], [760, 650], [475, 960], [95, 260], [875, 920], [700, 500], [555, 815], [830, 485], +[1170, 65], [830, 610], [605, 625], [595, 360], [1340, 725], [1740, 245]] +optimal = 7542 n_ants = 10 alpha = 1 diff --git a/tests/103_analyse_aco_alpha_beta.py b/tests/103_analyse_aco_alpha_beta.py index 7779b6a..a359cad 100644 --- a/tests/103_analyse_aco_alpha_beta.py +++ b/tests/103_analyse_aco_alpha_beta.py @@ -2,16 +2,18 @@ import numpy as np from matplotlib import pyplot as plt from libs.aco import AntColony, total_distance -name = "att48" -cities = [[6734, 1453], [2233, 10], [5530, 1424], [401, 841], [3082, 1644], [7608, 4458], [7573, 3716], [7265, 1268], [6898, 1885], [1112, 2049], [5468, 2606], [5989, 2873], [4706, 2674], [4612, 2035], [6347, 2683], [6107, 669], [7611, 5184], [7462, 3590], [7732, 4723], [5900, 3561], [4483, 3369], [6101, 1110], [5199, 2182], [1633, 2809], [4307, 2322], [675, 1006], [7555, 4819], [7541, 3981], [3177, 756], [7352, 4506], [7545, 2801], [3245, 3305], [6426, 3173], [4608, 1198], [23, 2216], [7248, 3779], [7762, 4595], [7392, 2244], [3484, 2829], [6271, 2135], [4985, 140], [1916, 1569], [7280, 4899], [7509, 3239], [10, 2676], [6807, 2993], [5185, 3258], [3023, 1942]] -optimal = 33523 +name = "berlin52" +cities = [[565, 575], [25, 185], [345, 750], [945, 685], [845, 655], [880, 660], [25, 230], [525, 1000], [580, 1175], [650, 1130], [1605, 620], [1220, 580], [1465, 200], [1530, 5], [845, 680], [725, 370], [145, 665], [415, 635], [510, 875], [560, 365], [300, 465], [520, 585], [480, 415], +[835, 625], [975, 580], [1215, 245], [1320, 315], [1250, 400], [660, 180], [410, 250], [420, 555], [575, 665], [1150, 1160], [700, 580], [685, 595], [685, 610], [770, 610], [795, 645], [720, 635], [760, 650], [475, 960], [95, 260], [875, 920], [700, 500], [555, 815], [830, 485], +[1170, 65], [830, 610], [605, 625], [595, 360], [1340, 725], [1740, 245]] +optimal = 7542 n_ants = 10 alpha = [1, 2] -beta = [1, 2] +beta = [2, 3, 4, 5] evaporation = 0.5 intensification = 2 -max_times = [0.5, 1, 1, 1, 1, 2] +max_times = [1] iterations = 1 bar_width = 0.15 @@ -21,6 +23,31 @@ x = np.arange(len(max_times)) fig, ax = plt.subplots() +# Preparing the colormap +colors = [ + '#1f77b4', # Bleu moyen + '#ff7f0e', # Orange + '#2ca02c', # Vert + '#d62728', # Rouge + '#9467bd', # Violet + '#8c564b', # Marron + '#e377c2', # Rose + '#7f7f7f', # Gris + '#bcbd22', # Vert olive + '#17becf', # Turquoise + '#1b9e77', # Vert Teal + '#d95f02', # Orange foncé + '#7570b3', # Violet moyen + '#e7298a', # Fuchsia + '#66a61e', # Vert pomme + '#e6ab02', # Jaune or + '#a6761d', # Bronze + '#666666', # Gris foncé + '#f781bf', # Rose clair + '#999999', # Gris moyen +] +color_dict = {} + for i in range(len(alpha)): for j in range(len(beta)): best_distances = [] @@ -30,12 +57,18 @@ for i in range(len(alpha)): print("Running iteration number {}/{} ({} sec)".format(iteration + 1, iterations, max_time)) best_route = ant_colony.run() best_distances.append(total_distance(best_route)) - ax.bar(x + (i * len(beta) + j) * bar_width, best_distances, bar_width, alpha=opacity, label='alpha={} beta={}'.format(alpha[i], beta[j])) + + # Defining a unique key for each alpha-beta pair + key = f"alpha={alpha[i]}_beta={beta[j]}" + if key not in color_dict: + color_dict[key] = colors[i * len(beta) + j] + + ax.bar(x + (i * len(beta) + j) * bar_width, best_distances, bar_width, alpha=opacity, color=color_dict[key], label='alpha={} beta={}'.format(alpha[i], beta[j])) ax.set_xlabel('Max Time') ax.set_ylabel('Best Distance') ax.set_title('Best distances per max time for each alpha and beta') -ax.set_xticks(x + bar_width / 2) +ax.set_xticks(x + bar_width / 3) ax.set_xticklabels(max_times) ax.legend()