Artificial Bee Colony (ABC)¶
A swarm method for continuous problems, with few settings to tune.
ABC ¶
ABC(*, onlooker_count=None, max_acceleration=1.0, trial_limit=None, fitness='auto', **kwargs)
Artificial Bee Colony (Karaboga, 2005, and Karaboga and Basturk, 2007).
Each food source (one of pop_size solutions) has an employed bee. The bee changes
one random component j of its source, v_j = x_j + phi (x_j - x_kj), where k is
another random source and phi is uniform in [-max_acceleration, max_acceleration].
The source moves only if the new position is strictly better, as in Karaboga's
reference code. Onlooker bees then pick sources in proportion to their fitness and
search around them the same way. A source that fails to improve trial_limit times
in a row is abandoned, and a scout bee replaces it with a random solution.
Parameters
pop_size: number of food sources (the paper's SN)onlooker_count: number of onlooker bees per iteration. None (the default) means pop_size.max_acceleration: the limit a of the uniform factor phi in [-a, a]trial_limit: abandonment limit. None (the default) means onlooker_count * d, where d is the code size (Karaboga 2005, Table 2).fitness: "auto" (default), "paper" or "rank". "paper" uses 1 / (1 + f) for f >= 0 and 1 + |f| for f < 0, with f turned into "smaller is better" (the rule of Karaboga's reference code). "auto" uses that formula but switches to ranks when the problem has constraints, since an infeasible solution has no meaningful objective value. "rank" always uses ranks.
Unlike the paper, each bee phase is evaluated as one batch, from the sources as they were at its start.
References: Karaboga, D. (2005). An idea based on honey bee swarm for numerical optimization. Technical report TR06, Erciyes University. Karaboga, D. and Basturk, B. (2007). A powerful and efficient algorithm for numerical function optimization: artificial bee colony (ABC) algorithm. Journal of Global Optimization, 39, 459 to 471.
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.ABC(max_nfe=20_000)
result = alg.solve(problem, seed=1)
print(result.summary())
ABC on sphere
best objective value: 0.00190007
feasible: True (violation 0)
evaluations: 20000, iterations: 100, time: 0.0246 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.ABC(max_nfe=20000);
result = alg.solve(problem, seed=1);
disp(result.summary())
ABC on sphere
best objective value: 0.00148295
feasible: true (violation 0)
evaluations: 20000, iterations: 100, time: 0.33 s, stopped by: max_nfe
Search on Rastrigin¶