MAX-MIN Ant System (MMAS)¶
An ant colony algorithm for discrete problems such as tours, and a strong choice among them when you have a heuristic. Pheromone stays between bounds and is reset when the search stalls, which keeps the ants exploring.
MaxMinAntSystem ¶
MaxMinAntSystem(*, beta=2.0, rho=0.02, p_best=0.05, schedule='iteration', restart_after=250, **kwargs)
MAX-MIN Ant System (MMAS).
Only one solution deposits after each colony: the iteration best, or the best so far as
schedule says. Trails stay within [tau_min, tau_max], where tau_max = 1 / (rho f_best)
and tau_min = tau_max (1 - p^(1/n)) / ((avg - 1) p^(1/n)), with p = p_best, n the
number of choices per ant and avg the mean number of options per choice. Trails start at
1 / (rho f_nn) and are reset to tau_max after restart_after iterations without a
better solution.
Parameters
beta: heuristic weight (default 2)rho: evaporation rate (default 0.02)p_best: probability that a converged colony builds the best solution (default 0.05)schedule: "iteration" (default), "best", or "mixed" (iteration best for the first 25 iterations, then the best so far every 5, 3 and 2 iterations up to 75, 125 and 250, and every iteration after that, Eq. 3.20 of the book)restart_after: iterations without improvement before the trails are reset (default 250), or None
References: T. Stützle and H. H. Hoos, "MAX-MIN Ant System", Future Generation Computer Systems 16(8), 2000, 889 to 914. M. Dorigo and T. Stützle, "Ant Colony Optimization", MIT Press, 2004, Chapter 3.
ypea.MMAS 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.MaxMinAntSystem(heuristic=heuristic, max_nfe=50_000)
result = alg.solve(problem, seed=1)
print(result.summary())
MMAS on random_tsp50
best objective value: 578.951
feasible: True (violation 0)
evaluations: 50000, iterations: 1000, time: 5.65 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.MaxMinAntSystem(heuristic=heuristic, max_nfe=50000);
result = alg.solve(problem, seed=1);
disp(result.summary())
MMAS on random_tsp50
best objective value: 558.059
feasible: true (violation 0)
evaluations: 50000, iterations: 1000, time: 2.42 s, stopped by: max_nfe