Collective behaviour as computation
A flock of birds turns as one body although no bird leads it. Reynolds reproduced this with three local rules for each simulated bird: avoid crowding neighbours, align with their heading, and move towards their centre [1]. Ant colonies find short paths between nest and food without a map, because ants deposit pheromone and prefer trails with more of it; shorter trails are completed faster and accumulate pheromone sooner. Honeybee colonies allocate foragers to flower patches in proportion to their quality through the waggle dance. These systems share decentralised control, simple agents, local interaction and emergent global behaviour, which Bonabeau, Dorigo and Theraulaz summarised as swarm intelligence [2].
Animation: Three rules make a flock
Each arrow follows only its neighbours. Set separation, alignment and cohesion and watch order emerge or dissolve. With alignment at zero, the flock never forms a common heading.
Particle swarm optimisation
Kennedy and Eberhart introduced particle swarm optimisation in 1995, inspired by bird flocking and social behaviour [3]. Each particle i has a position x, which is a candidate solution, and a velocity v. It remembers the best position p it has visited, and the swarm shares the best position g found by any particle. In every iteration, the velocity is updated as v = w v + c1 r1 (p - x) + c2 r2 (g - x), and the position as x = x + v, where r1 and r2 are random numbers between 0 and 1 drawn for each dimension.
The three terms have clear meanings. The inertia weight w keeps part of the previous motion; Shi and Eberhart introduced it to balance global and local search, with values around 0.4 to 0.9 [4]. The cognitive term, weighted by c1, pulls a particle back towards its own best experience. The social term, weighted by c2, pulls it towards the best experience of the swarm. Clerc and Kennedy analysed the dynamics and derived a constriction factor that guarantees convergence; the widely used setting w = 0.7298 with c1 = c2 = 1.49618 follows from it [5]. Particle swarms are easy to implement, need no gradients, and work well on continuous problems of moderate dimension, but like every metaheuristic they can stagnate in a local optimum.
Check your understanding. In the velocity update, what does the social term c2 r2 (g - x) do?
Tuning a PID controller with a swarm
The proportional-integral-derivative controller is the workhorse of industrial control. Its three gains shape the response: The proportional gain speeds up the reaction, the integral gain removes steady-state error, and the derivative gain damps oscillation [6]. Tuning them by hand is tedious, and classical rules assume simple process models. Controller tuning can instead be formulated as optimisation: Choose the gains that minimise a cost computed from a simulated step response, such as the integral of the time-weighted absolute error (ITAE), with penalties for overshoot and limits on the actuator. Particle swarms have been used in this way for automatic voltage regulators and many other loops [7].
The notebook applies the method to the speed control of a DC motor, using the standard model and parameters of the Control Tutorials for MATLAB and Simulink [8]. The armature voltage is limited to 24 volts, which makes the problem nonlinear, and the swarm evaluates all particles in one vectorised simulation. The cost function is part of the design: A cost that rewards speed alone drives the gains to their bounds, and adding a penalty on overshoot or control effort changes the optimum. The optimiser serves the engineer's definition of good behaviour; it cannot supply that definition.
Check your understanding. A swarm tunes a PID controller by minimising only the settling time, and the result shows violent oscillation of the actuator. What is the most likely cause?
Ant colony optimisation
Dorigo, Maniezzo and Colorni turned the pheromone mechanism into the Ant System for the travelling salesman problem [9]. Each artificial ant builds a complete tour city by city. From city i, it chooses the next unvisited city j with a probability proportional to the pheromone on edge (i, j) raised to a power alpha, times a heuristic desirability, usually the inverse distance, raised to a power beta. After all ants have finished, pheromone evaporates on every edge by a factor rho, and each ant deposits pheromone on the edges of its tour in inverse proportion to the tour length. Short tours therefore reinforce their edges, while evaporation forgets poor early choices.
The Ant Colony System added a stronger exploitation rule and local pheromone updates and was competitive on benchmark instances [10]; the monograph by Dorigo and Stützle presents the family and its applications to routing, scheduling and assignment [11]. Drilling holes in a printed circuit board is a classical travelling salesman application: The drill head must visit every hole once, and the travel time between holes is wasted production time. Benchmark libraries such as TSPLIB include instances that come from drilling problems [12].
Check your understanding. What is the purpose of pheromone evaporation in ant colony optimisation?
Artificial bee colony and the metaphor question
Karaboga and Basturk's artificial bee colony algorithm assigns roles to solutions [13]. Employed bees search around their food sources, onlooker bees choose sources in proportion to their quality and search around them, and scout bees replace sources that have not improved for a number of trials with random new ones. The scout phase gives the algorithm a built-in restart mechanism. Many further algorithms followed, inspired by fireflies, bats, wolves, whales and others, including the ant lion optimiser used to train neural networks for chaotic signal prediction in earlier work [14].
Sörensen argued that the flood of metaphor-based algorithms often hides old ideas behind new vocabulary and weak experiments [15]. The no free lunch theorems add that no algorithm can be best on all problems [16]. Engineers should therefore judge a metaheuristic by its search mechanism rather than its metaphor, compare it with established methods on the problem at hand, report results over many independent runs with statistics, and count function evaluations, not iterations, because a single evaluation of an engineering simulation may take minutes.
Check your understanding. A paper claims that a new animal-inspired algorithm beats PSO, based on one run per method with different numbers of function evaluations. What is the main weakness?
Python step 6: Classes, objects and probabilistic choice
The Python step of this week is part of the Colab notebook, where every explanation stands next to a cell that runs it and the step closes with a quick check and exercises with immediate feedback. The printable lecture notes contain the same step together with the outputs of its code.
Review cards
Select a card to turn it over.
Continue the week
The week continues with the simulation and the self-assessment of the interactive lab and with the Python step and the hands-on work of the Colab notebook. The week overview lists the discipline challenges, the weekly task and the research assignment.
Interactive lab Colab notebook Self-assessment Week overview and tasks
References
[1] Reynolds, C. W. (1987). Flocks, herds and schools: A distributed behavioral model. ACM SIGGRAPH Computer Graphics, 21(4), 25-34. https://doi.org/10.1145/37402.37406
[2] Bonabeau, E., Dorigo, M., & Theraulaz, G. (1999). Swarm Intelligence: From Natural to Artificial Systems. Oxford University Press.
[3] Kennedy, J., & Eberhart, R. (1995). Particle swarm optimization. In Proceedings of ICNN'95, International Conference on Neural Networks, Vol. 4 (pp. 1942-1948). IEEE. https://doi.org/10.1109/ICNN.1995.488968
[4] Shi, Y., & Eberhart, R. (1998). A modified particle swarm optimizer. In 1998 IEEE International Conference on Evolutionary Computation Proceedings (pp. 69-73). IEEE. https://doi.org/10.1109/ICEC.1998.699146
[5] Clerc, M., & Kennedy, J. (2002). The particle swarm: Explosion, stability, and convergence in a multidimensional complex space. IEEE Transactions on Evolutionary Computation, 6(1), 58-73. https://doi.org/10.1109/4235.985692
[6] Åström, K. J., & Hägglund, T. (1995). PID Controllers: Theory, Design, and Tuning (2nd ed.). Instrument Society of America.
[7] Gaing, Z.-L. (2004). A particle swarm optimization approach for optimum design of PID controller in AVR system. IEEE Transactions on Energy Conversion, 19(2), 384-391. https://doi.org/10.1109/TEC.2003.821821
[8] University of Michigan, Carnegie Mellon University, & University of Detroit Mercy (2026). Control Tutorials for MATLAB and Simulink: DC motor speed, system modeling. https://ctms.engin.umich.edu
[9] Dorigo, M., Maniezzo, V., & Colorni, A. (1996). Ant system: Optimization by a colony of cooperating agents. IEEE Transactions on Systems, Man, and Cybernetics, Part B, 26(1), 29-41. https://doi.org/10.1109/3477.484436
[10] Dorigo, M., & Gambardella, L. M. (1997). Ant colony system: A cooperative learning approach to the traveling salesman problem. IEEE Transactions on Evolutionary Computation, 1(1), 53-66. https://doi.org/10.1109/4235.585892
[11] Dorigo, M., & Stützle, T. (2004). Ant Colony Optimization. MIT Press.
[12] Reinelt, G. (1991). TSPLIB: A traveling salesman problem library. ORSA Journal on Computing, 3(4), 376-384. https://doi.org/10.1287/ijoc.3.4.376
[13] Karaboga, D., & Basturk, B. (2007). A powerful and efficient algorithm for numerical function optimization: Artificial bee colony (ABC) algorithm. Journal of Global Optimization, 39(3), 459-471. https://doi.org/10.1007/s10898-007-9149-x
[14] Kose, U. (2018). An ant-lion optimizer-trained artificial neural network system for chaotic electroencephalogram (EEG) prediction. Applied Sciences, 8(9), 1613. https://doi.org/10.3390/app8091613
[15] Sörensen, K. (2015). Metaheuristics: The metaphor exposed. International Transactions in Operational Research, 22(1), 3-18. https://doi.org/10.1111/itor.12001
[16] Wolpert, D. H., & Macready, W. G. (1997). No free lunch theorems for optimization. IEEE Transactions on Evolutionary Computation, 1(1), 67-82. https://doi.org/10.1109/4235.585893