Skip to content

Bees Algorithm (BA)

A population method for continuous problems that balances local search near the best solutions with global random search.

BA

BA(*, variant='standard', selected_site_ratio=0.5, selected_site_bee_ratio=0.1, elite_site_ratio=0.4, elite_site_bee_ratio=2.0, recruited_bee_ratio=0.1, dance_radius=0.1, dance_radius_damp=0.99, neighborhood='patch', **kwargs)

Bees Algorithm (Pham et al., 2005, 2006).

Each solution is a site (a flower patch) visited by a scout bee. The sites are kept sorted from best to worst.

Standard mode (Pham et al.): the best selected_site_count sites are searched by recruited bees, elite_site_bee_count bees for each of the elite_site_count elite sites and selected_site_bee_count bees for each other selected site. Every recruited bee is drawn uniformly from the patch around its site, a box of half width r in every component (cut at the bounds). A site moves to its best recruited bee only if that bee is strictly better. All other sites are replaced by new random scouts.

Probabilistic mode: every site gets a rank-based score d with mean 1, from about 1.58 for the best site to about 0.58 for the worst. A site is abandoned for a new random scout with probability 0.6 if d < 0.9, 0.2 if 0.9 <= d < 0.95, 0.05 if 0.95 <= d < 1.15 and 0 otherwise. A site that is kept gets ceil(d * recruited_bee_count) recruited bees, and each of them changes one random component of the site by r * U(-1, 1).

Parameters

  • pop_size: number of scout bees, which is also the number of sites
  • variant: "standard" (or "std") or "probabilistic" (or "prob")
  • selected_site_ratio: selected sites as a fraction of the scout bees (standard mode)
  • selected_site_bee_ratio: bees per selected site as a fraction of the scout bees (standard mode)
  • elite_site_ratio: elite sites as a fraction of the selected sites (standard mode)
  • elite_site_bee_ratio: bees per elite site as a multiple of the bees per selected site (standard mode)
  • recruited_bee_ratio: base number of recruited bees as a fraction of the scout bees (probabilistic mode)
  • dance_radius: initial neighborhood size r (code units)
  • dance_radius_damp: r is multiplied by this after every iteration
  • neighborhood: how a recruited bee leaves its site in the standard mode. "patch" (default, the paper) draws every component uniformly from the box of half width r. "component" changes one random component by r * U(-1, 1), which works much better on problems with many components.

Each site gets at least one bee, so small populations still search their sites.

The papers have no probabilistic mode and no rule for shrinking r. The probabilistic mode and its rejection thresholds are the original toolbox author's own design. Their fewer selected sites and smaller patch are an alternative, and the defaults were chosen on benchmark tests.

References: Pham, Ghanbarzadeh, Koc, Otri, Rahim and Zaidi (2005), Bee Algorithm: a novel approach to function optimisation, Technical Note MEC 0501, Manufacturing Engineering Centre, Cardiff University. Pham, Ghanbarzadeh, Koc, Otri, Rahim and Zaidi (2006), The Bees Algorithm: a novel tool for complex optimisation problems, IPROMS 2006.

Differences explains the origin of the probabilistic mode.

Example

import ypea

problem = ypea.Problem(
    ypea.Real("x", shape=20, lb=-10, ub=10),
    lambda sol: ypea.benchmarks.sphere(sol.x),
    vectorized=True,
    name="sphere",
)

alg = ypea.BA(max_nfe=20_000)
result = alg.solve(problem, seed=1)
print(result.summary())
BA on sphere
  best objective value: 11.2863
  feasible: True (violation 0)
  evaluations: 20000, iterations: 27, time: 0.00873 s, stopped by: max_nfe

Differs from Python: MATLAB draws its own random numbers, so the best value differs from Python's.

problem = ypea.Problem( ...
    vars=ypea.Real("x", shape=20, lb=-10, ub=10), ...
    objective=@(sol) ypea.benchmarks.sphere(sol.x), ...
    vectorized=true, ...
    name="sphere");

alg = ypea.BA(max_nfe=20000);
result = alg.solve(problem, seed=1);
disp(result.summary())
BA on sphere
  best objective value: 8.9801
  feasible: true (violation 0)
  evaluations: 20000, iterations: 27, time: 0.112 s, stopped by: max_nfe

Search on Rastrigin

BA solutions on Rastrigin at four iterations, and its convergence
BA with default settings, 50 iterations on Rastrigin in two dimensions (seed 1). The red points are the current sites, including the random scouts that keep the search broad. The open diamond is the best solution so far, and the plus sign the global minimum.