Algorithm
Worked example
The cycle below is taken verbatim from the "Step by Step Procedure of ABC" document on the Erciyes University ABC page. The randomly selected neighbour (k), dimension (j) and Φ values are the ones given there, so you can follow along with the same numbers.
min f(x) = x1² + x2², −5 ≤ xi ≤ 5, D = 2
Start: 3 food sources drawn uniformly from (−5, 5).
| # | Position x | f(x) | Fitness |
|---|---|---|---|
| 0 | ( 1.4112, −2.5644) | 8.5678 | 0.1045 |
| 1 | ( 0.4756, 1.4338) | 2.2820 | 0.3047 |
| 2 | (−0.1824, −1.0323) | 1.0990 | 0.4764 |
1Employed bee phase
Each employed bee produces a candidate with υi,j = xi,j + Φij(xi,j − xk,j) and applies greedy selection.
1st employed bee
k=1, j=0, Φ=0.8050 → υ0 = (2.1644, −2.5644)
f=11.2610, fitness=0.0816. 0.0816 < 0.1045 → no improvement, trial counter incremented.
2nd employed bee
k=2, j=1, Φ=0.0762 → υ1 = (0.4756, 1.6217)
f=2.8560, fitness=0.2593. 0.2593 < 0.3047 → no improvement, trial counter incremented.
3rd employed bee
k=0, j=0, Φ=−0.0671 → υ2 = (−0.0754, −1.0323)
f=1.0714, fitness=0.4828. 0.4828 > 0.4764 → IMPROVED, solution replaced, counter reset.
2Probability calculation
pi = fiti / Σfit — a richer source attracts more onlookers.
p
0.1172 · 0.3416 · 0.5412
The third source has the highest probability.
3Onlooker bee phase
Onlookers pick sources with probability pi and produce candidates with the same formula.
1st onlooker bee
i=2 → υ2 = (−0.0754, −2.2520)
f=5.0772, fitness=0.1645. 0.1645 < 0.4828 → no improvement.
2nd onlooker bee
i=1 → υ1 = (0.1722, 1.4338)
f=2.0855, fitness=0.3241. 0.3241 > 0.3047 → IMPROVED.
3rd onlooker bee
i=2 → υ2 = (0.0348, −1.0323)
f=1.0669, fitness=0.4838. 0.4838 > 0.4828 → IMPROVED.
4Scout bee phase
A source whose trial counter exceeds the limit is abandoned and replaced by a randomly generated one.
Trial counters
1 · 0 · 0
None exceeded limit = 6 → no abandoned source, no scout bee this cycle.
End of cycle — the best solution is memorized.
| # | Position x | f(x) | Fitness |
|---|---|---|---|
| 0 | ( 1.4112, −2.5644) | 8.5678 | 0.1045 |
| 1 | ( 0.1722, 1.4338) | 2.0855 | 0.3241 |
| 2 | ( 0.0348, −1.0323) | 1.0669 | 0.4838 |
Best: (0.0348, −1.0323)