Ant colony optimization¶
AntSystem, AntColonySystem and MaxMinAntSystem build each solution step by step. A step picks one choice with probability proportional to tau^alpha eta^beta, where tau is the pheromone of the choice and eta its heuristic value. Good solutions add pheromone to their choices, and evaporation removes some of it everywhere.
They build discrete values directly, so they solve problems with these variable types:
| Type | Pheromone | One step |
|---|---|---|
| Permutation, Selection | item j right after item i (pheromone="successor", the default) or item at position ("position") |
add an unused item |
| Integer, Binary | value of each component | pick a value for every component |
| BinarySelection | item | add an unused item, k times |
| Partition, BinaryPartition | group of each item | pick a group for every item |
Real and FixedSum variables raise an error. Use ACOR for continuous problems.
Shared settings¶
Base class of the classic ant colony algorithms.
Each iteration pop_size ants build solutions step by step (ypea.construction). A
step picks a choice with probability proportional to tau^alpha eta^beta, where tau is the
pheromone and eta the heuristic. Deposits are 1 / f when every value so far is positive
and minimized without constraints, otherwise 1 / (1 + rank) among the colony and the best
so far (the best is worth 1). A run that meets a nonpositive or non-finite value or a
constraint switches to ranks for good, and the trails are rescaled to match.
Parameters
pop_size: number of ants m. None (default) uses the number of choices one ant makes (cities for a tour, components for Integer, items for Partition, summed over the variables). ACS uses 10.alpha,beta: weights of pheromone and heuristicrho: evaporation rateheuristic: None (eta = 1) or a dict of variable name to an array of the variable's pheromone shape, for example{"tour": 1 / distances}: (n, n) for the successor table of Permutation and Selection, (k, n) for the position table, (*shape, values) for Integer and Binary, (n,) for BinarySelection, (n, k) for Partition. Larger is better. A leading axis ofcountgives one array per row. It can also be a function of the problem that returns such a dict (or None), for one algorithm that runs on several problems, as in an experiment.pheromone: "successor" (default, item j right after item i, for tours and sequences) or "position" (item at position, for assignment and scheduling), for Permutation and Selection variablestour: False (default, a learned first item and open sequences) or True (closed tours: a random first item, the closing pair, and symmetric trails)order: "random" (default) or "fixed", the order in which an ant fills positions withpheromone="position"tau0: None (default, the start trail of each method from the greedy solution) or a positive number. MMAS also takes inf: every choice starts equal, then the trails are clamped to tau_max.
The greedy solution (each step takes the largest heuristic) is evaluated once at the
start. x0 solutions are also evaluated, help set the start trail, and deposit once.
Real and FixedSum variables are not supported (use ACOR).
Choosing the pheromone¶
- Tours and routes:
pheromone="successor". Withtour=Truethe ants close the tour and trails are symmetric, as in the book. The defaulttour=Falsealso suits open sequences, where the first item matters. - Assignment and scheduling (QAP, item to slot):
pheromone="position". Each ant fills the positions in a random order (order="random"). - The heuristic has the shape of the pheromone table, for example
1 / distancefor a tour, or for a knapsack (Binary) an (n, 2) array: the mean value to weight ratio for leaving an item out, and the item's own ratio for taking it. Without it, eta is 1 everywhere and the ants are much slower to find good solutions. To run one algorithm on several problems, as in an experiment, pass a function that takes the problem and returns the dict.