Metaheuristics

ACO for Continuous Domains in MATLAB

Get the code
Comments

Implement ACOR in MATLAB with a ranked solution archive, Gaussian sampling, configurable parameters, and a bounded Sphere test problem.

Illustration for ACO for Continuous Domains in MATLAB
On this page

Ant algorithms were originally designed for discrete and combinatorial optimization problems. Several extensions of Ant Colony Optimization (ACO) handle problems defined in continuous domains. One of the most useful is ACOR, Ant Colony Optimization for Continuous Domains, proposed by Socha and Dorigo in 2008 (paper (opens in a new tab)).

ACOR is an Estimation of Distribution Algorithm (EDA). It looks for a probabilistic model that generates promising solutions with higher likelihood. At every iteration, the model is updated so that it generates even more promising solutions.

How ACOR works

In discrete ACO, the ants choose among a finite set of options, guided by a pheromone matrix. In a continuous space there is no finite set of options, so ACOR replaces the pheromone matrix with a solution archive: a sorted list of the kk best solutions found so far. The archive defines a mixture of Gaussian functions, one centered at each stored solution, and new solutions are sampled from this mixture.

Weights of the archive members

The solutions in the archive are sorted from best (l=1l = 1) to worst (l=kl = k). Solution ll gets the weight

wl=1qk2πexp⁡(−(l−1)22q2k2)w_l = \frac{1}{q k \sqrt{2\pi}} \exp\left(-\frac{(l - 1)^2}{2 q^2 k^2}\right)

and it is chosen with probability pl=wl/∑r=1kwrp_l = w_l / \sum_{r=1}^{k} w_r. The parameter qq sets the selection pressure. A small qq gives most of the weight to the best solutions, and a large qq spreads the weight more evenly.

Sampling a new solution

For each variable ii, a Gaussian kernel ll is chosen with the probabilities plp_l. Its mean is the value of that variable in archive solution ll, slis_l^i, and its standard deviation is the average distance from sls_l to the other archive members, scaled by ζ\zeta:

σli=ζ∑r=1k∣sri−sli∣k−1\sigma_l^i = \zeta \sum_{r=1}^{k} \frac{\left|s_r^i - s_l^i\right|}{k - 1}

The new value is then drawn from N(sli,(σli)2)\mathcal{N}(s_l^i, (\sigma_l^i)^2). When the archive members are spread out, the samples are spread out too. As the archive converges to a region, σ\sigma shrinks and the search becomes more local.

Updating the archive

After the new samples are evaluated, they are added to the archive. The archive is sorted by cost again, and only the best kk solutions are kept. This step plays the role of the pheromone update in discrete ACO.

What is in the download

This post shares an open-source MATLAB implementation of ACOR. The code is structured, so if you know MATLAB, you will find it easy to use in your research projects.

The ACOR folder holds four files:

  • acor.m: the algorithm, with the problem definition, the parameters, the main loop and the results.
  • Sphere.m: the sample cost function, f(x)=∑i=1nxi2f(x) = \sum_{i=1}^{n} x_i^2.
  • RouletteWheelSelection.m: chooses a Gaussian kernel by its probability.
  • main.m: a one line entry point that runs acor.m.

To run the code, open the ACOR folder in MATLAB and run main.m. The program prints the best cost in every iteration and plots the best cost against the iteration on a logarithmic scale. New samples outside the bounds are clipped to VarMin and VarMax. The script creates the first archive with unifrnd, a function of the Statistics and Machine Learning Toolbox, so it probably needs that toolbox.

Parameters in the code

Parameter Meaning Value
nVar Number of decision variables 10
VarMin, VarMax Bounds of the variables −10-10, 1010
MaxIt Maximum number of iterations 1000
nPop Archive size kk 10
nSample Number of new samples per iteration 40
q Intensification factor (selection pressure) 0.5
zeta Deviation to distance ratio ζ\zeta 1

To solve your own problem, write a cost function that takes a row vector and returns a number, and set CostFunction, nVar, VarMin and VarMax at the top of acor.m.

Check the result

The supplied Sphere problem has a known minimum of 0 at the origin. Check the returned coordinates and cost, then repeat runs to assess variability. Keep the archive size above 1 because the deviation formula divides by k−1k-1. Very similar archive members produce small sampling deviations, so early concentration can reduce exploration even while the best cost appears stable.

Downloads

How to cite

If you use this code or tutorial in your work, articles or publications, please cite it.

Plain text
Mostapha Kalami Heris, ACO for Continuous Domains in MATLAB (YPEA104), Yarpiz, 2015. https://yarpiz.com/acor-ypea104
BibTeX
@misc{yarpiz-ypea104,
  author = {{Mostapha Kalami Heris}},
  title = {{ACO for Continuous Domains in MATLAB}},
  howpublished = {Yarpiz},
  year = {2015},
  note = {Code YPEA104},
  url = {https://yarpiz.com/acor-ypea104}
}

Comments

Sign in or create a free account to join the discussion. No password needed.