The decentralized nature of bees is fascinating, especially in the event of swarming. Swarming is the process of a swarm splitting into two, one group follows the old queen out of the nest to find a new location, and the other group stays at the old hive to raise a new queen. It seems like a fun exercise to try and recreate a similar sequence of events in simulation. So the following won’t be exactly what bees do in reality (there will be links for that).
Let’s say the bees need to split into groups A and B once triggered by some environmental event (or triggered by some other swarm event, like a signal from the queen that everyone immediately spreads upon hearing). This trigger will cause the bees to begin the splitting process.
One approach is to rely on statistics. The bee will randomly choose between groups A and B with equal probability. For large groups of bees, we can safely guess they will be roughly cut in half. For just 100 bees, if each has an equal chance of choosing between each group, then we get a 94.31% chance of the split being somewhere between 40% and 60% of the swarm. As we increase the size of the swarm, the chance of the split being in the 40%-60% range dramatically increases.
Another approach is to have the bees pair off. When a bee is triggered to split, they will search out another bee that has been triggered (they would need some way of communicating this), and they then decide between them which will be group A and which is group B. This is another voting problem, but it’s far more simple since it’s between just two individuals. The easiest way for them to vote is to have each pick a random time interval and announce one of the two groups at the end of that interval. One of the bees will announce first and assign themselves to that group, while the other will take the alternative. This will perfectly split the hive in half, even leaving the potential odd last bee to wander forever, ensuring not even a single bee could tip the scale for either group.
Each method could be applied to splits greater than 2. The statistical method is very simple to adapt, just have each bee randomly pick from the available groups uniformly. The pairing-up method is a bit more difficult. Bees would search out swarms until they have enough bees (small swarms may need to break so you don’t get lots of small swarms that never vote), then you need a new voting mechanism for a small swarm that results in each individual being labeled with a different group. You could again use a random time interval, where at the end of the interval the bee randomly announces and assigns themselves to a group that hasn’t been assigned yet, repeating for the other un-assigned bees until the last bee must pick the one group that hasn’t already been picked.
The newly split group must determine when the rest of the bees have finished splitting so that they can wait to act as a whole group. One approach is to have a timer begin after the bee splits, and upon the timer reaching zero, the bee assumes the swarm has finished splitting, and begins its next task (like moving to the new home). If a bee runs into someone else with a longer timer, they will reset their timer to be equal to the longer one. This means if a group is a few seconds from takeoff, but a new bee suddenly joins, that new bee will have a longer timer which spreads through the group.
The length of this timer will depend on the environment and swarm size, which is undesirable. One requirement for success is that the timer is longer than the longest possible period of time between two successive pairs finding and splitting with each other. If the timer is too short, then the swarm could pre-maturely decide they are finished and leave without the remaining undecided bees. We also need the knowledge of a new timer to spread as fast as possible. A slowly spreading new timer could mean a new bee enters the swarm, but the timer travels so slowly across the swarm that the other side of the swarm decides to take off before getting the update. This would cause an undesirable split in the swarm, where some think they are done, while others know they are not.
Here we see a swarm, and upon receiving a trigger to split uses the pairing method to assign groups (color outline and different swarm position), then starts a timer (width of outline), and when the timer reaches zero, the swarms move to a new location.
We see the expected behavior, although two bees got left behind. This is difficult, but in this case, I think this is desirable. You can imagine we want the swarm to be robust against gaining or losing bees, as well as abnormal bees. If those two bees had died or simply decided not to pair off, we wouldn’t want the groups to wait for them, as they might wait forever. But, what to classify as ‘abnormal behavior’ is quite difficult, and sometimes not clear. This depends highly on the specifics of a situation, it may be we actually want a group to wait until absolutely all the bees are accounted for before moving on.
Once the swarm has split, the new swarm needs to determine where to move to. The process of finding a new home is actually fairly understood, there are even computer simulations of bees voting, as well as mathematical formulations that show this process is almost always successful.
Our model will be a bit simpler than the examples linked above but still achieve roughly the same results.
Every once in a while a scout bee will find a potential home, this home will be scored on its desirableness (size, humidity, wind protection, etc.). The bee will return to the current hive and advocate for this new potential site (real bees use a waggle dance to communicate the location, our simulated bees will communicate by coming into contact with each other). The bee will advocate for a time proportional to the desirableness of the new site: the more desirable, the longer they will advocate for, and the less desirable, the less time they will advocate for. There is a small chance that when another bee comes close, they will listen to the advocating bee and decide to check out this potential site for themselves. The process is now repeating, but we will have the bees forget the site they had just visited after they finish advocating, so the process is capable of dying out.
Below we see a hive that has several potential sites pop up (a thicker outline means it is more desirable), and when a bee starts advocating for a site, the bee will be colored the same color as the site. Let’s also graph how many bees are voting for each site over time.
We see for this simulation that the most desirable site is the one colored the lightest green, which the bees eventually all agree on. It almost died out near the beginning, which can happen with these random processes. We see that mediocre sites are quickly forgotten, which is good in this case, but may concern us at other times. There may come a time when mediocre sites are the only ones available, in which case we would still want the swarm to select a new site, not forget about all of them. Luckily, if we run the simulation again with a single mediocre site, they still vote on that site. We introduce a better site halfway through the simulation and see that they adapt and switch their votes, which is exactly what we would want.
What is fairly neat about this solution is that the bees never announce how good the potential site is, they simply announce that it exists, and the swarm still successfully votes for the best solution.
But we have one final step, which is to decide when the vote should end. There were two theories proposed for how real bees decide when a vote is over. The first is consensuses, where all dancing bees are dancing for the same potential hive, and this signals that the vote is over. The other is quorum, where once a set threshold of bees are voting for a particular site, the vote is done. By some neat experiments (see linked sources) we have determined that bees use a quorum.
When enough bees are checking out a new site at the same time, it will trigger the scouts to start alerting the swarm to prepare to move. How the bees determine when the number of advocates has passed the quorum threshold is still unknown. Note that this strategy can result in a swarm taking off even while many scouts are voting for different potential sites. These takeoffs often fail, which is assumed to be due to the need for more agreement in the steering process of a large swarm. If a swarm fails to be steered, they will settle down and continue voting.
We will use the consensus strategy to finish the vote. When a bee sees an advocate, they will start a timer, and upon the timer reaching zero, they will decide the vote is over and take off. When a bee sees an advocate for a different location than the one they are currently counting down for, the bee will reset its timer. What this means is that while there exist advocates for more than one location in a swarm, the bee’s timers will constantly be reset. Only when a single site is being voted for does the timer have time to count down fully, whereupon the swarm finishes its vote.
Here we see the bees voting between two sites. They successfully stop voting for the worst site, which means all their timers are able to count down to zero, and then they all move to the new site. In order to have the swarm move as one, we also had the bees look for any timers that were larger than their own around themselves, that way all the timers were synced up. This is not necessary for the voting to succeed but is necessary for synchronized movement.
With that, we have all the components of simulating the event of bee swarming! The bees can split themselves into two equal groups, find and vote on the best potential new sites, then agree on one and move to it. Below is the entire swarming process all put together
While this is pretty neat, it’s not as robust as you might hope. For different swarm sizes, you would need to manually set the timings for waiting to split and finishing voting. You would also need different techniques or more timers if your swarm isn’t able to spread information as quickly as the one in this example. But it’s a good toy example for recreating some swarm intelligence.