Why might two school lunch queues keep swapping which one is longer?
At lunch, you spot a shorter queue. Everyone in your queue spots it too, and you all move at once. Now your new queue is the longer one. If nobody arrives or gets served, could the queues keep swapping which one is longer?
You could model a single lunch queue with just one count. An arrival adds one and a pupil being served takes one away. That tells you how many are waiting. It gives you no way to track which pupil would switch queues.
Now watch each pupil look at both queues. Each chooses the shorter one, or stays put if they’re tied. Everyone chooses from the same snapshot, then all switches happen together. Each pupil is an agent with a queue and a decision rule.
You see five pupils in queue A and three in queue B. Everyone chooses before anyone moves. Nobody arrives or gets served in this round. How many pupils are in each queue after the switches? Pick the pair of counts.
The numbers identify pupils, with queue A on the left and B on the right. Nobody arrives or gets served. First, pupils one to six all choose B and move together. Next, all eight see an empty A and switch to it. In round three, all eight switch back to B.
Try starting with four pupils in A and two in B. Keep the same rules: everybody chooses before anybody moves, and nobody arrives or gets served. What are the counts after two rounds? Pick the pair you’d expect to see.
Each list entry records one pupil’s queue. Count both queues first. At a tie, return an unchanged copy. Otherwise, find the shorter queue and record switches in a copy. With together set to false, stop after one switch. Use the returned list for the next step, which counts the queues again.
You might think the rule says to swap every round. That’s the mistake. Each pupil chooses the shorter queue and stays put at a tie. Their moves change the counts others see next. The repeated swing is an oscillation. It shows emergence: a group pattern arising from individual interactions.
An average of four hides both an even split and everyone in one queue. Agents let you link a pupil’s move to what nearby pupils see. You can give pupils different minimum gaps for switching. That adds rules to specify, and checking each pupil’s rule can take more computing time.
To analyse and interpret outcomes before and after a modification, start both runs at six and two, with no arrivals or service. Moving together makes the counts alternate. Moving one at a time gives five and three, then four and four. Fresh counts reveal the tie before anyone else moves.