In 1996 Joshua Epstein and Robert Axtell's Sugarscape grew trade, migration, inequality and epidemics from simple agents foraging on a grid. Agent-based models (ABMs) build societies and ecosystems from the bottom up: many autonomous agents follow local rules, and aggregate patterns emerge from their interactions rather than being assumed.
We will gather the ingredients, write the simulation loop, and finish with when to use one.
Step 1: Ingredients
Every ABM has four ingredients: agents with states and rules for updating them; an interaction structure, such as a grid, a network or a market, saying who affects whom; a schedule saying when agents update, since the order can change results; and randomness in choices or encounters. Nothing about the aggregate is assumed. In Sugarscape, agents differing in vision and metabolism forage on a landscape with uneven sugar, and a skewed wealth distribution emerges.
Such emergence is the point: a traffic jam can move backward while every car in it moves forward. Unlike a representative-agent model, where one agent stands for everyone, an ABM has many differing agents interacting, and running it many times shows which aggregate patterns the rules produce.
Step 2: The simulation loop
In code, an ABM is a loop. Create the agents and their environment; then at each time step go through the agents in the order the schedule sets, let each observe its neighbors and apply its rule, and record the aggregate statistics of interest. Repeat the steps for the length of the run, and repeat whole runs with different random seeds. Whether agents update one at a time, each seeing the others' latest states, or all at once from the previous step's states is part of the schedule.
Step 3: When to use one
ABMs complement equation-based models when heterogeneity, local interaction, bounded rationality or out-of-equilibrium dynamics matter. How jams form on a ring road, or how an infection moves through a contact network, depends on who meets whom, and suits an ABM; the price response of a single competitive market has a clean equation-based answer. Epstein's generative social science asks of any pattern: can you grow it from plausible rules?
The cost is that results can be hard to generalize and can hinge on choices, such as the update order or the network, that are hard to verify. And since one random run may be unrepresentative, results are reported over many runs.