def run_aco(filename, map_param, num_ants, maxiter, alpha, beta, evaporation_coeficient): if map_param is 1: small_world = le_coordenadas_tsp("test_cases/berlin52.tsp") small_world_solution = read_solution() dicio = dicio_cidades(small_world) elif map_param is 2: medium_world = le_coordenadas_tsp("test_cases/kroA100.tsp") medium_world_solution = read_solution() dicio = dicio_cidades(medium_world) elif map_param is 3: large_world = le_coordenadas_tsp("test_cases/ch150.tsp") large_world_solution = read_solution() dicio = dicio_cidades(large_world) sol = [ 0, 21, 48, 31, 17, 30, 20, 16, 2, 44, 18, 40, 7, 8, 9, 42, 32, 50, 10, 51, 13, 12, 46, 25, 26, 27, 11, 24, 3, 47, 23, 5, 4, 14, 37, 39, 36, 38, 35, 34, 33, 43, 45, 15, 28, 49, 19, 22, 29, 41, 6, 1 ] f = eval_solution(distance, dicio) print(f(sol, dicio)) colony = AntColony( dicio, distance, ant_count=num_ants, alpha=alpha, beta=beta, pheromone_evaporation_coefficient=evaporation_coeficient, time_budget=maxiter) colony.mainloop() data = { "best_individuals": colony.best_individuals, "fitness_averages": colony.fitness_averages, "generation_calculation_times": colony.generation_calculation_times, "population_initialization_time": colony.population_initialization_time, "population_size": num_ants, "iterations": maxiter, "alpha": alpha, "beta": beta, "evaporation_coeficient": evaporation_coeficient } print(" ------------------ Converting ---------------------") converter = CsvConverter(filename, data) converter.aco_to_csv() print(" ------------------ Ending ACO ---------------------")
from ant_colony import AntColony test_nodes = { 0: (0, 7), 1: (3, 9), 2: (12, 4), 3: (14, 11), 4: (8, 11), 5: (15, 6), 6: (6, 15), 7: (15, 9), 8: (12, 10), 9: (10, 7) } def distance(start, end): x_distance = abs(start[0] - end[0]) y_distance = abs(start[1] - end[1]) import math return math.sqrt(pow(x_distance, 2) + pow(y_distance, 2)) colony = AntColony(test_nodes, distance) answer = colony.mainloop() print(answer)