## Segration demo by computational agent simulation

For the fun of it, (and to learn more about Numpy’s multidimensional arrays) I decided to repeat Thomas Shelling’s famous experiment which demonstrates that segregation based on any real or imagined divider, such as gender, income, language,age, ethnicity, race, social status, religion, sexual preference etc, can occur by very innocent, non-prejudist,non-discriminating reasons: it suffices that each ‘agent’ has a slight preference for any specific characteristic, such as gender, language etc for segregation, that is, clustering of people with similar characteristics or preferences, to occur.  That clustering could occur in many different domains, such as selection of friends, where individuals decide to live,  or choice of restaurants to visit.

Thomas Schelling conducted his experiment by flipping coins, but that seems very time consuming, so I wrote a Python program to do the simulation.

My simulation takes place on a 20 x 20 grid, where each  green and black cell of the grid represents an individual ‘agent’. An agent is either ‘green’ or ‘black’, the color representing the agent’s preference on the selected dividing characteristic. Basically, ‘greens’ prefer other ‘greens’, ‘blacks’ prefer other ‘blacks’.

The below image shows the initial state of the board, where I’ve placed the agents according to a specific pattern ( you might want to think about this initial pattern as some lefty politician’s wet dream… 🙂

The black and green squares represent agents located at a specific location on the grid, each agent with having differing preference on any of the dividing categories mentioned above.

The grey squares are free, i.e. currently unpopulated slots.

In my model, the ‘satisfaction’ of the current situation of each client is expressed by a very simple parameter: any agent that is surrounded by more than 2 non-peer agents of its 8 possible ‘neighbors’, feels dissatisfied with its current neighborhood, and will move to one of the free slots. The dissatisfied agent looks for any free slot which would result in a lower number of ‘non-peer’ neighbors, and if such a slot is found, the agent will move to that slot.

The simulation proceeds in a number of iterations, where each agent, at each iteration, determines whether it is satisfied with its current neighborhood (number of non-peers <3) or whether it wants to move.

In the initial state of the simulation, the average number of non-peer neighbors for all the agents is 2.8, that is, on average, any agent is dissatisfied with its current neighborhood.

After one iteration, the ‘board’ looks like below:

Many of the agents have moved, but the average number of ‘non-peer’ neighbors is 2.62, that is still above the satisfaction limit of 2.

After 10 iterations, the average number of non-peer neighbors has decresed to 1.44, that is, below the limit of 2, and and we are starting to see some clustering, that is, segregation along the dividing characteristic emerging.

After 100 iterations, the clustering is very clear:  most of the green and black agents have settled in their own, fully segregated neighborhoods, and the few that have not have settled in the segregated areas have mostly found space in the ‘wilderness’, where they have few if any neighbors. And if they have any neighbors of non-peer kind, their number is below the limit.

The average number of non-peer neighbors has now decreased to 0.47.

The only still dissatisfied agents are now those sitting on the border of the two segregated areas, and it seems like the model has now reached close to it’s optimum – even if I increase the number of iterations to 10000, the remaining dissatisfied agents are unable to improve their situation.