DEV Community

Cover image for Agent-based social segregation model
Linnart Felkl
Linnart Felkl

Posted on

Agent-based social segregation model

In this post I will briefly present an agent-based simulation model that can be used for modeling e.g. social segregation.

Framework for agent-based models in Python

The framework for modeling agent-based models in Python the abm_framework. I made this framework available on Github. The repository is here: abm_framework

The repository contains a directory with demo models. The directory is located here. At the time of this post the directory contains a segregation example and a disease spread SIR model example.

Model logic and implementation

The code for the model is available here. The model essentially implements the following workflow:

1) For each iteration one random agent is selected
2) The agent's neighbourhood is collected
3) For every agent of same type the agent's utility increases
4) For every agent that is not of same type utility decreases
5) Up to 10 random empty cells in the grid are collected
6) If the agent's utility would be higher in one of the cells, the first cell with higher utility is assigned as the agent's location (relocation)

Simulation results

Below is an animation of the simulation run, showing the segregation process.

Image description

Another animation, shown below, shows agent utility density distribution.

Image description

References to related agent-based simulation content

If you are interested in agent-based modeling and simulation you can also look at some other simple examples that I have published:

Top comments (0)