adding ant number setting
This commit is contained in:
parent
72b9af908c
commit
b21ecce51e
@ -59,10 +59,11 @@ class AntColony:
|
|||||||
self.pheromones = [[(1 - self.evaporation) * p for p in row] for row in self.pheromones]
|
self.pheromones = [[(1 - self.evaporation) * p for p in row] for row in self.pheromones]
|
||||||
return [self.cities[i] for i in best_ant]
|
return [self.cities[i] for i in best_ant]
|
||||||
|
|
||||||
nb_ville = 200
|
nb_ville = 50
|
||||||
max_coords = 1000
|
max_coords = 10
|
||||||
nb_truck = 4
|
nb_truck = 1
|
||||||
max_time = 5
|
max_time = 1
|
||||||
|
nb_ants = 10
|
||||||
|
|
||||||
max_time_per_cluster = max_time / nb_truck
|
max_time_per_cluster = max_time / nb_truck
|
||||||
|
|
||||||
@ -116,12 +117,11 @@ for i, cluster_indices in enumerate(clusters.values()):
|
|||||||
cluster_cities = [cities[index] for index in cluster_indices]
|
cluster_cities = [cities[index] for index in cluster_indices]
|
||||||
|
|
||||||
# Appel de la fonction AntColony.run
|
# Appel de la fonction AntColony.run
|
||||||
ant_colony = AntColony(cluster_cities, n_ants=10, max_time=max_time_per_cluster)
|
ant_colony = AntColony(cluster_cities, n_ants=nb_ants, max_time=max_time_per_cluster)
|
||||||
best_route = ant_colony.run()
|
best_route = ant_colony.run()
|
||||||
best_routes.append((best_route, color))
|
best_routes.append((best_route, color))
|
||||||
|
|
||||||
print("Final solution for cluster ", i, ":", best_route)
|
print("Total distance for cluster", i, ": ", total_distance(best_route))
|
||||||
print("Total distance: ", total_distance(best_route))
|
|
||||||
|
|
||||||
for i, (route, color) in enumerate(best_routes):
|
for i, (route, color) in enumerate(best_routes):
|
||||||
x = [city[0] for city in route]
|
x = [city[0] for city in route]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user