This simulation models a version of Schelling's segregation model in a 1D circular space.
Agents and Preferences
There are two types of agents: Red and Blue.
Each agent has a tolerance level between 0.0 and 1.0.
An agent is considered "happy" if the proportion of similar neighbors within its neighborhood (defined by the radius w) is greater than or equal to its tolerance.
The neighborhood extends w agents to the left and $w$ agents to the right (considering the circular boundary). The agent itself is not counted as a neighbor.
Dynamics
If there are any "unhappy" Red and Blue agents, the simulation randomly selects one unhappy Red agent and one unhappy Blue agent.
These two unhappy agents swap their positions in the 1D space.
After the swap, the happiness of the neighbors around the swapped positions is re-evaluated.
The simulation continues with random swaps between unhappy Red and Blue agents until no unhappy agents of either color remain, or a state of total segregation (all agents of the same color are clustered together) is reached.
Parameters
Size: The total number of agents in the 1D space.
Radius: The number of neighbors to the left and right that each agent considers.
Tolerance: The threshold for happiness (proportion of similar neighbors).
Minority: The initial proportion of Red agents in the space.