Skip to content

Ant Colony System (ACS)

An ant colony algorithm for discrete problems such as tours. Ants often take the best choice, and only the best solution adds pheromone, so it converges quickly.

AntColonySystem

AntColonySystem(*, beta=2.0, rho=0.1, xi=0.1, q0=0.9, pop_size=10, **kwargs)

Ant Colony System (ACS).

Each step takes the best choice (largest tau eta^beta) with probability q0, otherwise it draws one as AS does. After each step the ants, moving in parallel, pull the trail of the choice they made toward tau0 (local rate xi). After each colony only the choices of the best so far solution are updated: tau = (1 - rho) tau + rho / f_best. tau0 = 1 / (n f_nn), with n the number of choices per ant.

Parameters

  • pop_size: ants (default 10)
  • beta: heuristic weight (default 2)
  • rho: global evaporation rate (default 0.1)
  • xi: local evaporation rate (default 0.1)
  • q0: probability of the best choice (default 0.9)

References: M. Dorigo and L. M. Gambardella, "Ant colony system: a cooperative learning approach to the traveling salesman problem", IEEE Transactions on Evolutionary Computation 1(1), 1997, 53 to 66. M. Dorigo and T. Stützle, "Ant Colony Optimization", MIT Press, 2004, Chapter 3.

ypea.ACS is the same class. The settings shared by the three ant colony classes, and how each variable type is built, are on Ant colony optimization.

Example

The heuristic makes a large difference on tours: without it the ants learn from the pheromone alone.

import numpy as np
import ypea

problem = ypea.problems.random_tsp(50, seed=2)
distances = problem.objective.distances
n = len(distances)
heuristic = {"tour": 1 / (distances + np.eye(n))}  # the diagonal is never used

alg = ypea.AntColonySystem(heuristic=heuristic, max_nfe=50_000)
result = alg.solve(problem, seed=1)
print(result.summary())
ACS on random_tsp50
  best objective value: 582.833
  feasible: True (violation 0)
  evaluations: 50000, iterations: 5000, time: 29.1 s, stopped by: max_nfe

Differs from Python: MATLAB draws its own cities and random numbers, so the tour length differs from Python's. The heuristic is a struct keyed by the variable name.

problem = ypea.problems.random_tsp(50, seed=2);
distances = problem.info.distances;
n = size(distances, 1);
heuristic = struct("tour", 1 ./ (distances + eye(n)));  % the diagonal is never used

alg = ypea.AntColonySystem(heuristic=heuristic, max_nfe=50000);
result = alg.solve(problem, seed=1);
disp(result.summary())
ACS on random_tsp50
  best objective value: 567.544
  feasible: true (violation 0)
  evaluations: 50000, iterations: 5000, time: 24.4 s, stopped by: max_nfe