HomeSociety & EconomicsHappiness & Similar Neighbours

😊 Happiness & Similar Neighbours

Interactive happiness-threshold cellular automaton: agents relocate when fewer than k of their 8 neighbours share their type. Watch mild local preferences produce large-scale clustering patterns.

Society & Economics3DEasy60 FPS
happiness-neighbors ↗ Open standalone

😊 Happiness & Similar Neighbours — Local Similarity Cellular Automaton

Each agent on the grid checks its 8 surrounding neighbours: if fewer than k of them share its own type, the agent is "unhappy" and relocates to a random empty cell. Watch how this simple, purely local happiness rule produces large clustered neighbourhoods even when every agent would gladly live in a mixed area.

🔬 What It Demonstrates

A cellular automaton where local micro-decisions — "am I happy with my k out of 8 neighbours?" — aggregate into global clustering patterns. It illustrates emergence: no agent aims to create large uniform regions, yet they appear anyway once every unhappy agent relocates.

🎮 How to Use

Raise the happiness threshold k to demand more same-type neighbours before an agent is content; lower it to allow more mixing. Adjust density and the Type A / Type B mix, then watch pulsing yellow outlines mark unhappy agents right before they jump to an empty cell.

💡 Did You Know?

Even a mild threshold like k = 3 out of 8 (just over a third of neighbours) is enough to drive a randomly mixed grid into strongly clustered regions within a few dozen generations — a striking demonstration of how weak local preferences scale into strong global patterns.

About Happiness & Similar Neighbours — Local Similarity Cellular Automaton

This simulation models a grid of Type A and Type B agents, each of whom evaluates happiness using a single rule: count how many of the up-to-8 surrounding neighbours share your type, and if that count falls below a threshold k, relocate to a random empty cell. Every generation, every unhappy agent moves, and the process repeats until few or no agents remain unhappy. The model is a close relative of economist Thomas Schelling's 1971 paper "Dynamic Models of Segregation" (Journal of Mathematical Sociology), which first showed that even a mild individual preference for similar neighbours — far short of active hostility toward other groups — can tip an integrated neighbourhood into sharply divided clusters. This page deliberately reframes that mechanism in abstract terms: agents are simply "Type A" and "Type B," happiness is a numeric threshold out of 8 neighbours, and the emphasis is on local similarity and clustering dynamics rather than on group identity or segregation by race or class, which is the framing used in the site's separate Schelling Segregation Model.

The underlying dynamic also connects directly to Waldo Tobler's First Law of Geography (1970): "everything is related to everything else, but near things are more related than distant things." The happiness rule literally operationalises this law at the scale of a single grid cell — an agent only cares about its immediate 8-cell neighbourhood, yet the cumulative effect of thousands of purely local relocation decisions is a globally patterned landscape of same-type clusters. Because relocation decisions cascade (an agent that moves can make its old neighbours unhappy and its new neighbours happier), the resulting clustering is highly sensitive to the threshold k: low values of k barely change a random layout, while values around or above half of 8 can produce nearly complete separation, illustrating how small changes in a purely local rule can produce dramatically different global outcomes.

Frequently Asked Questions

What does "happy" mean in this simulation?

An agent is happy if the number of its occupied Moore-neighbourhood cells (up to 8 surrounding cells) that share its own type is at least the happiness threshold k. If fewer same-type neighbours are present than k, the agent is unhappy and is marked for relocation to a randomly chosen empty cell on the next tick. Edge and corner cells naturally have fewer than 8 possible neighbours, so their happiness is judged against however many occupied neighbours actually surround them.

How do I use this simulation?

Use the "Happiness threshold (k of 8)" slider to set how many same-type neighbours an agent needs to stay put — higher k means agents demand more similarity. The Density slider controls what fraction of the grid is occupied, and the Type A share slider controls the mix ratio between the two types. Click Reshuffle to regenerate a fresh random grid, or Pause to freeze the animation while still viewing the current state.

What is the similarity index shown in the info bar?

The similarity index is the average, across all occupied agents, of the fraction of their occupied neighbours that share their own type. It ranges from 0 (every agent is surrounded entirely by the opposite type) to 1 (every agent is surrounded entirely by its own type). Watching this number climb and plateau over generations shows the grid converging toward a stable, clustered configuration.

Why does even a small happiness threshold produce strong clustering?

The effect is driven by feedback: when an unhappy agent relocates, it typically increases the same-type density around its new location while decreasing it around its old one. This makes the new neighbourhood more attractive to other same-type agents and the old neighbourhood less attractive, so subsequent moves reinforce the emerging boundary. Because thousands of small relocation events compound over generations, even a modest per-agent tolerance for diversity (say, needing only 3 of 8 neighbours to match) produces regions that are far more segregated than any individual agent's stated preference would suggest.

How does this differ from the Schelling Segregation Model on this site?

Both simulations share the same underlying mechanism — agents check their neighbourhood and relocate if unsatisfied — but they differ in framing and parameterisation. The Schelling model on this site is typically presented with a "tolerance percentage" and language emphasizing racial or group segregation dynamics, echoing the historical urban-sociology context in which Schelling's original model was discussed. This simulation instead uses an abstract "Type A / Type B" vocabulary and an explicit integer threshold (k out of 8 neighbours), deliberately avoiding group-identity framing so the focus stays on the mathematics of local similarity preference and its geographic implications, in the spirit of Tobler's First Law rather than segregation studies specifically.

What is Tobler's First Law of Geography, and how does it relate here?

Geographer Waldo Tobler proposed in 1970 that "everything is related to everything else, but near things are more related than distant things." This simulation is a direct, mechanistic illustration of that principle: an agent's happiness depends only on its immediate spatial neighbourhood, not on the whole grid. Because relocation decisions are made purely from local information, the resulting global pattern — large same-type regions separated by sharp boundaries — emerges without any agent, or any central planner, ever considering the grid as a whole.

Does raising the happiness threshold always increase clustering?

Generally yes, but the relationship is not perfectly linear. At very low k (0 or 1), almost every layout is already happy and the grid stays close to its random initial state. As k rises toward 4 (half of 8 neighbours), clustering increases sharply because agents become far more selective. Beyond that, very high thresholds (7 or 8) can make convergence difficult or unstable, since agents may struggle to find any empty cell where they satisfy such a strict neighbour requirement, leading to persistent relocation cycles rather than a stable equilibrium.

What real-world phenomena does this kind of model help explain?

Beyond its historical use in urban residential-sorting studies, the same local-threshold relocation mechanism has been applied to explain clustering in online social networks (users migrating toward communities with similar views), retail location patterns (similar businesses clustering into districts), species habitat selection in ecology, and opinion polarization in social simulations. The general lesson — that mild local preferences can produce strong global separation without anyone intending it — is a recurring theme across many complex systems, which is why the model remains widely taught outside its original urban-sociology context.

Why do some agents keep moving without ever settling down?

At high density and a high happiness threshold, the supply of empty cells that satisfy an agent's requirement can become scarce, especially near cluster boundaries. An agent might move into a cell that looks satisfactory at the moment it relocates, but as other agents around it also move in the same generation, its new neighbourhood composition changes and it can become unhappy again on a later tick. This can produce long transient periods of continued churn before the grid — if it converges at all — settles into a stable pattern with zero moves per tick.

How is "convergence" determined in this simulation?

The info bar's "Converged" indicator reads "yes" whenever a completed generation results in zero relocations — meaning every occupied agent already meets its happiness threshold given the current grid state. Because the grid is finite and moves are driven purely by local rules, most parameter combinations do eventually reach this zero-move state, though the number of generations required grows with higher thresholds, higher density, and more balanced Type A / Type B mixes.

⚙ Under the hood

Interactive happiness-threshold cellular automaton: agents relocate when fewer than k of their 8 neighbours share their type. Watch mild local preferences produce large-scale clustering patterns.

cellular automatonagent-based modelemergencesegregation

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)