Heuristic — nature-inspired metaheuristic

▶ Open interactive explainer →

Cuckoo Search

Aliascs, cuckoo_search
TypeHeuristic — nature-inspired metaheuristic
Auto-seeds fromshuffle (random nests)

Description

Nature-inspired metaheuristic that models brood parasitism in cuckoos. Maintains a population of nests (candidate tours). Each epoch:

  1. A new cuckoo tour is generated from a randomly selected nest via a Lévy flight step — a sequence of random 2-opt reversals whose count is drawn from a power-law Lévy distribution.
  2. The cuckoo tour replaces a random nest if it is better.
  3. Each nest is independently abandoned with probability pa and re-seeded randomly (Bernoulli nest abandonment) to maintain population diversity.

TSP-specific adaptations (deviations from Yang & Deb 2009):

AdaptationReason
Lévy flight → k random 2-opt reversalsMaps continuous step magnitude to a discrete tour perturbation; preserves permutation validity
k capped at n/2Prevents full-tour scrambles from very large Lévy draws
β=1.5 fixed; σ_u≈0.6966 precomputedStandard Lévy exponent (Mantegna 1994); constant avoids repeated gamma evaluation
Per-nest Bernoulli abandonmentCloser to the original paper than deterministic worst-k; avoids discarding more information per epoch than Lévy moves can recover

Auto-expands to pipeline(shuffle, cs).

procedure CuckooSearch(cities, n_nests, pa, epochs):
    nests ← initialize_nests(n_nests, cities)
    best ← best_tour(nests)
    for epoch in 1..epochs:
        for each nest i:
            step ← levy_flight()
            candidate ← apply_2opt_reversals(nests[i], step)
            j ← random_nest_index()
            if length(candidate) < length(nests[j]):
                nests[j] ← candidate
        abandon_worst_fraction(nests, pa)
        best ← min(best, best_tour(nests))
    return best

Options

FlagDescriptionDefault
--epochsMaximum iterations10 000
--n_nearestNumber of nests (floored at 25)25
--mutation_probabilityPer-nest abandonment probability pa0.001

Usage

teeline solve cs -i ./data/tsplib/berlin52.tsp
teeline solve cuckoo_search -i ./data/tsplib/berlin52.tsp --epochs=500
teeline solve cs -i ./data/tsplib/berlin52.tsp --n_nearest=40 --mutation_probability=0.25

References