Loading the engineShared by all simulations, so the next one opens instantly.
The physics

Thomas Schelling asked in 1969 and 1971 how much individual preference it takes to split a town into separate neighborhoods. He worked it out by hand, moving pennies and dimes on a checkerboard, and found that it takes very little: even when everyone is content to live as a minority, as long as not too small a one, the town sorts itself into large single-colored districts that nobody asked for. The model became a standard example of how a collective outcome can differ sharply from what any individual intends. Schelling later shared the 2005 Nobel Memorial Prize in Economic Sciences for his game-theory work on conflict and cooperation.

What you see

A 100 by 100 grid whose edges wrap around, so the grid is a torus. Blue and orange cells are agents of two groups of equal size, dark cells are empty. Every run starts from the same random mix for a given occupancy. Unhappy agents move away, and the mix sorts itself into patches of one color. In every preset this goes on until every agent is content and the picture freezes. The Segregation index readout in the panel shows the index S defined below.

Rule

An agent looks at the up to eight occupied cells around it (its Moore neighborhood) and is content when at least a fraction τ of them belong to its own group:

nsamensame+nother≥τ.

An agent without any neighbors is content. In each step, 2500 cells (a quarter of the grid) are picked at random. If a picked agent is not content, it picks a random cell anywhere on the grid and moves there if that cell is empty; otherwise it stays put for now. A mover does not check whether it will be content at its new address. Schelling moved his agents to the nearest place where they would be content; moving to a random empty cell is a common simplification.

The segregation index is the mean share of same-group agents among the occupied neighbors of each agent,

S=⟨nsamensame+nother⟩.

A random mix of two equal groups gives S=0.5, complete separation gives S=1.

With at most eight neighbors, only a few values of τ matter: an agent counts nsame out of at most eight, so τ=0.30 and τ=0.33, for example, make exactly the same agents unhappy. At 80% occupancy the final index grows with τ in steps: 0.52 at τ=0.1, 0.59 at 0.2, 0.61 at 0.25, then a jump to 0.74 at 0.3, where agents with one like neighbor out of four or two out of seven start to move. It reaches 0.82 at 0.4, 0.87 at 0.5, 0.96 at 0.6 and 0.998 at 0.8, where the groups are almost completely separated.

Presets

Mild preference (τ = 1/3): 80% of the cells occupied, and every agent is content as long as a third of its neighbors are like it. At the start 18% of the agents are unhappy. The index rises from 0.50 to 0.70 within 100 steps and freezes at 0.74 after about 300 steps, 5 seconds at 60 steps per second. Everyone would accept being in a two-to-one minority, yet the average agent ends up with three quarters of its neighbors from its own group.

Weak preference (τ = 0.2): the same town with agents that need only one like neighbor in five. Only 7% start unhappy, and the index stops at 0.59 after about 180 steps: little sorting beyond the random mix.

Half alike (τ = 0.5): 70% occupancy and agents that want at least half of their neighbors like them. 42% start unhappy, and the groups separate much further, to an index of 0.88 after about 280 steps.

Sparse town (τ = 1/3, half empty): half of the cells empty. With many vacancies a move succeeds more often, so the town settles faster, after about 150 steps, and sorts slightly more, to an index of 0.76.

Parameters

Threshold τ: the smallest share of like neighbors an agent accepts, 0.1 to 0.8. It applies immediately: raising it makes more agents unhappy, and a frozen town starts moving again.

Occupancy: the fraction of cells holding an agent, 0.5 to 0.95, split evenly between the two groups. It applies when the simulation is reset.