10 Spatial Coverage & Exploration · #46 of 46

Swarm Sandbox

Three good ideas, fighting for the wheel

A dense swarm of tiny three-legged Kilobot robots clustered on a flat surface, each a small disc on vibrating legs.
A real Kilobot swarm: hundreds of coin-sized robots, each seeing only its nearest neighbours. The same local rules a starling runs are the rules you are about to wire into the sandbox below. · asuscreative, CC BY-SA 4.0

A starling watches only its seven nearest neighbours. Multiply that by ten thousand birds and you get this: a cloud that turns inside out at the speed of fear, with no one in charge.

Now you build one. And you discover that the rules want different things.

You have spent this whole phase collecting behaviours like tools: flocking for coordinated motion, goal-seeking for purpose, obstacle avoidance for survival. Individually, each is simple and well-mannered. Stack all three onto the same agent and they stop cooperating. They start negotiating, and you are the one who sets the terms.

Build a swarm, then watch it argue

The sandbox below is the capstone. Every dot runs the same four-term controller, and the sliders set how loudly each term gets to vote. Move the goal and the swarm chases it. Crank cohesion and it clumps. Somewhere in between is your swarm.

mean dist to goal

Try this:

  1. Pure goal-seek. Drop cohesion and alignment to near zero, max out goal-seek. The flock dissolves into a panicked sprint: fast to the target, but a smear, not a swarm. Watch the collision count climb.
  2. Pure cohesion. Now invert it: max cohesion, kill goal-seek. The agents huddle into a tight, beautiful, completely useless ball that never goes anywhere.
  3. Find the seam. Nudge both up together and hunt for the setting that arrives and stays in formation. Tap "Move goal" (or click the canvas) to relocate the target and stress-test your tuning against a fresh chase.

The thing you just felt in your fingertips is the entire discipline: more cohesion means fewer collisions but slower arrival. Tighten the flock and bodies stop colliding, but the group also stops committing to the goal. Loosen it and they sprint, straight into each other. There is no slider position that wins everything. That tension is swarm design.

Why the objectives fight

Each term is a vector pulling the agent somewhere, and they rarely point the same way. Separation says back off. Cohesion says come closer. Goal-seek says that way, now. Alignment says match the crowd. The controller just sums them, so the swarm's behaviour is a tug-of-war, and the slider weights decide who wins each pull.

Tune one objective up and you almost always pay somewhere else. Crank goal-seek and arrival time drops, but collisions spike. Crank cohesion and collisions vanish, but the swarm dawdles. You can't have all three maxed at once, and pretending otherwise is how real swarms fly into walls. This is the multi-objective trade-off, and there is no setting that dominates every metric. The best you can do is pick which losses you can live with.

Why there's no single 'best' swarm: the Pareto front

When you optimize for several things at once, you minimize a vector of objectives rather than a single number:

minf(x)=[f1(x),  f2(x),  ,  fk(x)]\min f(x) = \big[\, f_1(x),\; f_2(x),\; \ldots,\; f_k(x) \,\big]

Here f1f_1 might be arrival time, f2f_2 energy spent, and f3f_3 collisions, while xx is your slider setting. The trouble is that no single xx minimizes all of them together. Instead we talk about dominance: a setting xx dominates yy when it is at least as good on every objective and strictly better on one,

i:  fi(x)fi(y)j:  fj(x)<fj(y).\forall i:\; f_i(x) \le f_i(y) \quad\wedge\quad \exists j:\; f_j(x) < f_j(y).

The settings that nobody dominates form the Pareto front: the set of honest trade-offs, where improving any one objective forces another to get worse. Every point on that front is a legitimate "best" swarm; which one you want depends entirely on what you're willing to sacrifice.

To actually pick, you collapse the vector into one score with weights that encode your priorities:

S=w1time+w2energy+w3collisions.S = w_1 \cdot \text{time} + w_2 \cdot \text{energy} + w_3 \cdot \text{collisions}.

Those weights are the sliders. Choosing them is not solving the problem; it is stating which problem you wanted to solve.

The flashiest swarms are robots, but the most profitable ones move money, not light. The same local-rules trick that keeps your dots in formation also routes data through the internet, schedules deliveries, and steers the orange robots that haul shelves around an Amazon warehouse. Amazon bought the company behind those robots, Kiva Systems, in 2012 and now runs them by the hundreds of thousands.

Key takeaways

A murmuration has no captain. Neither does your swarm. There is only a handful of local rules, a few weights, and the quiet violence of objectives that refuse to fully agree.

Tune them well and ten thousand selfish dots become one intelligent cloud, not because you commanded it, but because you found the seam where their arguments cancel into grace.

full glossary →