Overview
This example models opinion dynamics — a classic ABM scenario where each agent holds a real-valued opinion and gradually shifts toward the average opinion of its neighbors. Over time, agents converge toward consensus. It demonstrates:- Setting up parameters and a custom graph
- Writing initial data and timestep functions
- Running to convergence
- Reading final state
The simulation
What to expect
On a cycle graph, information only travels between immediate neighbors, so convergence is slower than on a complete graph. With 30 nodes and a convergence threshold of0.005, you should see the simulation settle in a few hundred timesteps with all agents very close to a shared mean opinion.
Variations to try
Switch to a complete graph
Switch to a complete graph
Change
graph_type to "complete" to see how convergence speed changes when every agent can directly influence every other agent.Use a scale-free network
Use a scale-free network
Replace the built-in graph with a Barabási–Albert graph to model opinion dynamics on a social network with hubs.
Add noise to each update
Add noise to each update
Introduce a small random perturbation at each step to prevent perfect convergence and model real-world uncertainty.