Animal and swarm-inspired algorithmsVerified

Ant Colony Optimization

Ant Colony Optimization (ACO)

Year introduced
1996
Original authors
M. Dorigo; V. Maniezzo; A. Colorni
Source of inspiration
Ant pheromone trails
Search space
Combinatorial
Optimization types
Feature Selection, Neural Architecture Search, Hyperparameter Optimization
Applied research in the repository
8

Overview

A constructive algorithm: each ant builds a solution step by step by probabilistic choice based on the pheromone τ and the heuristic information η, then the pheromone is updated by evaporation and deposit. It was designed for combinatorial problems such as TSP, and has a continuous version, ACO_R.

Source of inspiration and mechanism

Image illustrating the source of inspiration of the ACO algorithm: Ant pheromone trails
Ant pheromone trailsImage: Samantha Henneke from Seagrove, North Carolina, USA · CC BY 2.0 · Wikimedia Commons

Ants lay pheromone as they walk, so the pheromone concentrates on the shorter paths because they are travelled faster; with evaporation the bad paths are forgotten. This indirect collective memory (Stigmergy) is the basis of the algorithm.

Initialization

Equal initial pheromone on all edges (or a random archive in ACO_R).

Update mechanism

The pheromone is updated after all ants (or only the best ones in MMAS) finish building.

Exploration

Evaporation prevents the pheromone from piling up on a single path; randomness comes from the probabilistic choice.

Exploitation

Good paths are reinforced by the deposit; in ACO_R a small q favours the best solutions.

Mathematical description

In Ant System the probability of moving from i to j is computed from the strength of the pheromone and the heuristic information, then the pheromone evaporates at rate ρ and a deposit inversely proportional to the path length is added. In ACO_R (Socha & Dorigo 2008) the pheromone is replaced by an archive of solutions sampled with a Gaussian kernel.

Transition probability

p_{ij}^{k} = \frac{\tau_{ij}^{\alpha}\,\eta_{ij}^{\beta}}{\sum_{l\in N_i^k} \tau_{il}^{\alpha}\,\eta_{il}^{\beta}}

η_ij=1/d_ij in TSP.

Pheromone update

\tau_{ij} \leftarrow (1-\rho)\,\tau_{ij} + \sum_{k} \Delta\tau_{ij}^{k},\quad \Delta\tau_{ij}^{k} = \frac{Q}{L_k}

ρ is the evaporation rate, L_k the tour length of ant k.

ACO_R: weight of solution l in the archive

\omega_l = \frac{1}{qk\sqrt{2\pi}} e^{-\frac{(l-1)^2}{2q^2k^2}}

q controls the preference for better solutions.

ACO_R: standard deviation

\sigma_l^{i} = \xi \sum_{e=1}^{k} \frac{\left|s_e^{i} - s_l^{i}\right|}{k-1}

ξ is similar to the evaporation rate.

Computational complexity: O(T\cdot m\cdot n^{2})\ \text{(TSP)};\quad O(T\cdot m\cdot k\cdot D)\ \text{(ACO}_R)

Pseudocode

Initialize pheromone tau
for t = 1..T:
    for each ant k:
        build a solution step by step using p_ij
    evaluate solutions
    evaporate: tau = (1 - rho) * tau
    deposit pheromone on edges of good solutions
return best solution
# ACO_R (continuous): keep an archive of k solutions sorted by fitness;
# each ant picks a guide l with prob ~ w_l and samples N(s_l, sigma_l)

Python implementation

This code was actually run while building the lab (NumPy) on the sphere function to make sure it works; this is a run test, not a performance claim.

import numpy as np

def aco_r(f, lb, ub, dim, archive=30, ants=20, iters=200, q=0.1, xi=0.85, seed=0):
    """ACO for continuous domains (ACO_R, Socha & Dorigo 2008): Gaussian kernel over a solution archive."""
    rng = np.random.default_rng(seed)
    k = archive
    S = rng.uniform(lb, ub, (k, dim))
    fs = np.apply_along_axis(f, 1, S)
    order = np.argsort(fs); S, fs = S[order], fs[order]
    rank = np.arange(1, k + 1)
    w = np.exp(-((rank - 1) ** 2) / (2 * (q * k) ** 2)) / (q * k * np.sqrt(2 * np.pi))
    p = w / w.sum()
    curve = []
    for _ in range(iters):
        new = np.empty((ants, dim))
        for a in range(ants):
            l = rng.choice(k, p=p)                       # choose a guiding solution
            sigma = xi * np.abs(S - S[l]).sum(axis=0) / (k - 1)
            new[a] = rng.normal(S[l], sigma + 1e-12)
        new = np.clip(new, lb, ub)
        fn = np.apply_along_axis(f, 1, new)
        S = np.vstack([S, new]); fs = np.concatenate([fs, fn])
        order = np.argsort(fs)[:k]; S, fs = S[order], fs[order]
        curve.append(fs[0])
    return S[0], fs[0], curve

if __name__ == "__main__":
    sphere = lambda z: float(np.sum(z ** 2))
    best, val, curve = aco_r(sphere, -100, 100, dim=10)
    print("best fitness:", val)

Coefficients

ParameterSymbolTypical valueRangeDescription
Pheromone weight
α
10.5 – 2Influence of the pheromone
Heuristic weight
β
2–51 – 5Influence of the heuristic information
Evaporation rate
ρ
0.1–0.50.01 – 0.5Evaporation rate
ACO_R locality
q
0.10.01 – 0.5Preference for better solutions
ACO_R deviation
ξ
0.850.5 – 1Sampling range

Advantages

  • Excellent for combinatorial and routing problems
  • Builds solutions constructively, so it handles constraints easily
  • Incorporates problem-specific heuristic knowledge.

Limitations

  • Needs adaptation for continuous problems
  • Memory cost O(n²) for the pheromone matrix
  • Sensitive to ρ, α and β.

Use in artificial intelligence

Domains documented in the card: Machine learning, deep learning, Feature Selection, hyperparameter tuning, Architecture search

TSP, task scheduling and routing, feature selection with features represented as nodes, continuous problems through ACO_R.

Related models in the relationship table

Hybridization potential

These are partnerships suggested theoretically in the card; any resulting design is presented as a "proposed hybrid method" until its results are compared with the literature.

Applied research from the repository

Related lessons

Original reference

M. Dorigo; V. Maniezzo; A. Colorni (1996). Ant system: optimization by a colony of cooperating agents. IEEE Transactions on Systems, Man, and Cybernetics, Part B (Cybernetics), IEEE.

Verified DOI: 10.1109/3477.484436