IMAGINE that you are French. You are walking along a busy pavement in Paris and another pedestrian is approaching from the opposite direction. A collision will occur unless you each move out of the other's way. Which way do you step?

The answer is almost certainly to the right. Replay the same scene in many parts of Asia, however, and you would probably move to the left. It is not obvious why. There is no instruction to head in a specific direction (South Korea, where there is a campaign to get people to walk on the right, is an exception). There is no simple correlation with the side of the road on which people drive: Londoners funnel to the right on pavements, for example.

Instead, says Mehdi Moussaid of the Max Planck Institute in Berlin, this is a behaviour brought about by probabilities. If two opposing people guess each other's intentions correctly, each moving to one side and allowing the other past, then they are likely to choose to move the same way the next time they need to avoid a collision. The probability of a successful manoeuvre increases as more and more people adopt a bias in one direction, until the tendency sticks. Whether it's right or left does not matter; what does is that it is the unspoken will of the majority.

That is at odds with most people's idea of being a pedestrian. More than any other way of getting around—such as being crushed into a train or stuck in a traffic jam—walking appears to offer freedom of choice. Reality is more complicated. Whether stepping aside to avoid a collision, following the person in front through a crowd or navigating busy streets, pedestrians are autonomous yet constrained by others. They are both highly mobile and very predictable. “These are particles with a will,” says Dirk Helbing of ETH Zurich, a technology-focused university.

Messrs Helbing and Moussaid are at the cutting edge of a youngish field: understanding and modelling how pedestrians behave. Its purpose is not mere curiosity. Understanding pedestrian flows makes crowd events safer: knowing about the propensity of different nationalities to step in different directions could, for instance, matter to organisers of an event such as a football World Cup, where fans from various countries mingle. The odds of collisions go up if they do not share a reflex to move to one side. In a packed crowd, that could slow down lots of people.

In 1995 Mr Helbing and Peter Molnar, both physicists, came up with a “social force” computer model that used insights from the way that particles in fluids and gases behave to describe pedestrian movement. The model assumed that people are attracted by some things, such as the destination they are heading for, and repelled by others, such as another pedestrian in their path. It proved its worth by predicting several self-organising effects among crowds that are visible in real life.

One is the propensity of dense crowds spontaneously to break into lanes that allow people to move more efficiently in opposing directions. Individuals do not have to negotiate their way through a series of encounters with oncoming people; they can just follow the person in front. That works better than trying to overtake. Research by Mr Moussaid suggests that the effect of one person trying to walk faster than the people around them in a dense crowd is to force an opposing lane of pedestrians to split in two, which has the effect of breaking up the lane next door, and so on. Everyone moves slower as a result.

Up close and personal

Another self-organising behaviour comes when opposing flows of people meet at a single intersection: think of parents trying to shepherd their children into school as other parents, their sprogs already dropped off, try to leave. As people stream through in one direction, the pressure on their side of the intersection drops. That gives those waiting on the other side more opportunity to go through, until pressure on their side is relieved. The result is a series of alternating bursts of traffic through the gates.

This oscillation in flows is clever enough to have got Mr Helbing wondering about its application to cars. Traffic-light systems currently operate on fixed cycles, with lights staying green on the basis of past traffic patterns. If those patterns are not repeated, drivers are left to idle their engines for too long at red signals, raising emissions and tempers. Mr Helbing thinks it is better to have decentralised, local systems, which—like parents at the school gates—can respond to a build-up of traffic and keep the lights on green for longer if need be. City authorities agree: Mr Helbing's ideas will soon be implemented in Dresden and Zurich.

Trying to capture every element of pedestrian movement in an equation is horribly complex, however. One problem is allowing for cultural biases, such as whether people step to the left or the right, or their willingness to get close to fellow pedestrians. An experiment in 2009 tested the walking speeds of Germans and Indians by getting volunteers in each country to walk in single file around an elliptical, makeshift corridor of ropes and chairs. At low densities the speeds of each nationality are similar; but once the numbers increase, Indians walk faster than Germans. This won't be news to anyone familiar with Munich and Mumbai, but Indians are just less bothered about bumping into other people.

Another problem with assuming people act like particles is that up to 70% of people in a crowd are actually in groups. That matters, as anyone trying to get past shuffling tourists knows. It also leads to some lovely fine-scale choreography when small groups are squeezed. Observations of pavement crowds in Toulouse in France show that clusters of three and four people naturally organise themselves into concave “V” and “U” shapes, with middle members falling back slightly. If a group of three people cared about moving quickly, they would behave like geese and form a convex “V”, with the middle member slightly in front to forge a path. Instead, they adopt a formation that enables them to keep communicating with each other; talking trumps walking.

Mr Moussaid's solution to such complexity has been to build a model based less on the analogy between humans and particles and more on cognitive science. Agents in this new model are allowed to “see” what's in front of them; they then try to carve a free path through the masses to get to their destination. This approach produces the same effects of lane-formation in crowds as the physics-based models, but with some added advantages.

In particular, boffins think it could help make emergency evacuations safer. Simulating evacuations is a big part of what pedestrian modellers do—the King's Cross underground fire in London in 1987 gave the field one of its starting shoves. One big danger in an emergency is that people will follow the crowd and all herd towards a single exit. That in turn means that the crowd may jam as too many people try to force their way through a single doorway.

The physics-based models do have an answer to this problem of “arching” (so called for the shape of the crowd that builds up around the exit). Their simulations suggest the flow of pedestrians through a narrow doorway can be smoothed by plonking an obstacle such as a pillar just in front of the exit. In theory, that should have the effect of splitting people into more efficient lanes. In practice, however, the idea of putting a barrier in front of an emergency exit is too counter-intuitive for planners to have tried.

The cognitive-science model offers a more palatable option, that of experimenting with the effects of changes in people's visual fields. Mr Moussaid speculates that adaptable lighting systems, which use darkness to repel people and light to attract them, could be used to direct them in emergencies, for example. Where the cognitive approach falls down is in the most packed environments. “At low densities, behaviour is cognitive and strategic,” says Mr Moussaid. “At high density, it's about mass movement and physical pressures.” At a certain point crowds can shift from a controlled flow to a stop-and-go pattern, as people are forced to shorten their stride length and occasionally halt to avoid collisions. This kind of movement can develop into something much more frightening, known as crowd turbulence, when people can no longer keep a space between themselves and others. The physical forces that are imparted from one body to another when that happens are both chaotic and powerful: if someone falls over, others will be unable to avoid them. Science meets religion Working out precisely how and when these transitions happen is tough. Bringing a real-life situation under control once a stop-and-go pattern has started is equally hard. So the trick is to ensure that serious crowding is avoided in the first place. From big events such as the London Olympics to the design of new railway stations, engineering firms now routinely simulate the movement of people to try to spot areas where crowding is likely to occur.

A typical project involves using off-the-shelf software programs to identify potential bottlenecks in a particular environment, such as a stadium or a Tube station. These models specify the entry and exit points at a location and then use “routing algorithms” that send people to their destinations. Even a one-off event like the Olympics has plenty of data on pedestrian movement to draw on, from past games to other set-piece gatherings such as, say, city-centre carnivals, which enable some basic assumptions about how people will flow.

Once potential points of congestion are identified, more sophisticated models can then be used to go down to a finer level of detail. This second stage allows planners to change architectural designs for new locations and identify when to intervene in existing ones. “There should be many fewer crowd disasters given what we now know and can simulate,” says Mr Helbing.

The biggest test possible of these tools and techniques is the haj, the annual pilgrimage to Mecca in Saudi Arabia that Muslims are expected to carry out at least once in their lives if they can. With as many as 3m pilgrims making the journey each year, the haj has a long history of crowd stampedes and deaths. Indeed, video footage of a haj stampede is used by lots of modellers to validate their simulations of crowd turbulence.

The Saudi authorities have brought in consultants in recent years, focusing in particular on the layout of the Jamarat Bridge, where pilgrims perform a ritual in which they throw stones at three pillars. By making the crossing one-way, and changing the shape of the pillars so that people can stone them from a number of locations, they have improved the bridge's safety.

But according to Paul Townsend of Crowd Dynamics, a consultancy that has worked on the pilgrimage, the risks remain significant. He thinks that the use of gates that could be opened and shut would help to manage the flow. Yet the haj presents some very specific difficulties beyond its sheer scale. Part of the problem is not having a clear idea of how many pilgrims will turn up, which makes planning difficult. Another issue is the nature of the crowd.

“Pilgrims on the haj have the attitude that, if I die there it is God's will,” says Mr Townsend. “There is a willingness to get more and more dense in the space.” Scientists can model many aspects of pedestrian behaviour, but religious fervour is a step too far.