Segregation (Schelling) Segregation (GIS)

Julien Mazars edited this page May 24, 2016 · 4 revisions


_Author : _

A model showing the segregation of the people just by putting a similarity wanted parameter using agents to represent the individuals and GIS file for the places

Imported model :

model segregation_base

global {
	//Different colors for the group
	rgb color_1 <- rgb ("yellow") parameter: "Color of group 1:" category: "User interface";
	rgb color_2 <- rgb ("red") parameter: "Color of group 2:" category: "User interface";
	rgb color_3 <- rgb ("blue") parameter: "Color of group 3:" category: "User interface";
	rgb color_4 <- rgb ("orange") parameter: "Color of group 4:" category: "User interface";
	rgb color_5 <- rgb ("green") parameter: "Color of group 5:" category: "User interface";
	rgb color_6 <- rgb ("pink") parameter: "Color of group 6:" category: "User interface";   
	rgb color_7 <- rgb ("magenta") parameter: "Color of group 7:" category: "User interface";
	rgb color_8 <- rgb ("cyan") parameter: "Color of group 8:" category: "User interface";
    list colors <- [color_1, color_2, color_3, color_4, color_5, color_6, color_7, color_8] of: rgb;

	//Number of groups
	int number_of_groups <- 2 max: 8 parameter: "Number of groups:" category: "Population";
	//Density of the people
	float density_of_people <- 0.7 parameter: "Density of people:" category: "Population" min: 0.01 max: 0.99;
	//Percentage of similar wanted for segregation
	float percent_similar_wanted <- 0.5 min: float (0) max: float (1) parameter: "Desired percentage of similarity:" category: "Population";
	//Dimension of the grid
	int dimensions <- 40 max: 400 min: 10 parameter: "Width and height of the environment:" category: "Environment";
	//Neighbours distance for the perception of the agents
	int neighbours_distance <- 2 max: 10 min: 1 parameter: "Distance of perception:" category: "Population";
	//Number of people agents
	int number_of_people <- 0;
	//Number of happy people
	int sum_happy_people <- 0 update: all_people count (each.is_happy);
	//Number of similar neighbours
	int sum_similar_neighbours <- 0 update: sum (all_people collect each.similar_nearby);
	//Number of neighbours
	int sum_total_neighbours <- 1 update: sum (all_people collect each.total_nearby) min: 1;
	//List of all the places
	list<agent> all_places;
	//List of all the people
	list<base> all_people;  
	//Action to write the description of the model in the console
	action description {
		"\\n\\u25B6 Description. \\n\\u25B6 Thomas Schelling model of residential segregation is a classic study of the effects of local decisions on global dynamics. Agents with mild preferences for same-type neighbors, but without preferences for segregated neighborhoods, can wind up producing complete segregation.\\n\\u25B6 In this model, agents populate a grid with a given *density*. They are in two different states : happy when the percentage of same-color neighbours is above their *desired percentage of similarity*; unhappy otherwise. In the latter case, they change their location randomly until they find a neighbourhood that fits their desire. \\n\\u25B6 In addition to the previous parameter, one can adjust the *distance of perception* (i.e.  the distance at which they consider other agents as neighbours) of the agents to see how it affects the global process. ";
	//Initialization of the model
	init {
		//Write the description of the model 
		do description;
		//Initialization of the places
		do initialize_places;
		//Computation of the number of people according to the density of people
		number_of_people <- int( length (all_places) * density_of_people);
		//Initialization of the people
		do initialize_people;
	//Action to initialize places defined in the subclasses
	action initialize_places virtual: true;
	//Action to initialize people in the subclasses
	action initialize_people virtual: true;

//Species base representing the people agents
species base {
	rgb color;
	//List of all the neighbours agents
	list<base> my_neighbours;
	//computation of the similar neighbours
	int similar_nearby -> {
		(my_neighbours count (each.color = color))
	//Computation of the total neighbours nearby
	int total_nearby -> {
		length (my_neighbours)
	//Boolean to know if the agent is happy or not
	bool is_happy -> {similar_nearby >= (percent_similar_wanted * total_nearby )} ;

Code of the model :

model segregation

//Import the model Common Schelling Segregation
import "../include/Common Schelling Segregation.gaml" 
global {
	//List of all the free places
	list<space> free_places  ;  
	//List of all the places
	list<space> all_places ;
	//Neighbours distance for the perception of an agent
	int neighbours_distance <- 50 min: 1 parameter: "Distance of perception:" category: "Population" max: 1000;
	//Shapefile to load
	file shape_file_name <- file("../gis/nha2.shp") parameter: "Shapefile to load:" category: "GIS specific";
	//Shape of the environment
	geometry shape <- envelope(shape_file_name);
	//Square meters per people in m2
	int square_meters_per_people <- 200 parameter: "Occupancy of people (in m2):" category: "GIS specific";
	//Action to initialize people agents
	action initialize_people { 
		//Create all the places with a surface given within the shapefile
		create space from: shape_file_name with: [surface :: float(read("AREA"))];
		all_places  <- shuffle(space);
		//Compute the number of people to create considering the density of people
		number_of_people <- int( density_of_people * sum (all_places collect (each.capacity))); 
		create people number: number_of_people;  
	    all_people <- people as list ; 
	    //Move all the people to a new place
		ask people  {  
			do move_to_new_place;       
	//Action to initialize the places
	action initialize_places {}   

//Species people representing the people
species people parent: base { 
	//Size of the people agent
	float size const: true <- 2.0;
	//Color of the people agent  
	rgb color const: true <- colors at (rnd (number_of_groups - 1)); 
	int red const: true <- (color as list) at 0; 
	int green const: true <- (color as list) at 1;  
	int blue const: true <- (color as list) at 2;  
	//Building in which the agent lives
	space current_building <- nil;
	//List of all the neighbour people agents
	list<people> my_neighbours -> {people at_distance neighbours_distance}; 
	//Action to move to a new place
	action move_to_new_place {  
		current_building <- (shuffle(all_places) first_with (((each).capacity) > 0));
		ask current_building {
			do accept one_people: myself;   
	//Reflex to migrate to another place if the agent isn't happy
	reflex migrate when: !is_happy {
		if current_building != nil {
			ask current_building { 
				do remove_one one_people: myself;
		do move_to_new_place;

	aspect simple {
		draw circle(5) color: color;

//Species space representing a space for a people agent to live in
species space {	
	//List of all the people agents living within
	list<people> insiders;
	rgb color <- rgb(255, 255, 255); 
	//Surface of the place
	float surface;
	//Capacity of the place
	int capacity  <- 1 + int(surface / square_meters_per_people);
	//Action to accept a people agent  
	action accept (people one_people) {
		add one_people to: insiders;
		location of one_people <- any_location_in(shape);
		capacity <- capacity - 1;
	//Action to remove a people agent
	action remove_one (people one_people){
		remove one_people from: insiders;
		capacity <- capacity + 1;
	aspect simple {
		color <- empty(insiders) ? #white : rgb ([mean (insiders collect, mean (insiders collect, mean (insiders collect]);
		draw  square(40) color: color;
	aspect gis {
		color <- empty(insiders) ? #white : rgb( [mean (insiders collect, mean (insiders collect, mean (insiders collect]);
		draw shape color: color border: #black;
	aspect highlighted {
		color <- #blue;
		draw shape+10 color: color;

experiment schelling type: gui {	
	output {
		display Town_display  {
			species space aspect: gis;
			species people  aspect: simple;
		display Charts {
			chart "Proportion of happiness" type: histogram background: #lightgray gap:0.05 position: {0,0} size: {1.0,0.5}{
				data "Unhappy" value: number_of_people - sum_happy_people color: #green;
				data "Happy" value: sum_happy_people color: #yellow ;
			chart "Global happiness and similarity" type: series background: #lightgray axes: #white position: {0,0.5} size: {1.0,0.5} {
				data "happy" color: #blue value:  ((sum_happy_people * 100) / number_of_people)  style: spline ;
				data "similarity" color: #red value:  (sum_similar_neighbours / sum_total_neighbours) * 100 style: step ;



Changes from 1.6.1 to 1.8


  1. Installation and Launching
  2. Installation
  3. Launching GAMA
  4. Headless Mode
  5. Updating GAMA
  6. Installing Plugins
  7. Troubleshooting
  8. Workspace, Projects and Models
  9. Navigating in the Workspace
  10. Changing Workspace
  11. Importing Models
  12. Editing Models
  13. GAML Editor (Generalities)
  14. GAML Editor Toolbar
  15. Validation of Models
  16. Running Experiments
  17. Launching Experiments
  18. Experiments User interface
  19. Menus and commands
  20. Parameters view
  21. Inspectors and monitors
  22. Displays
  23. Batch Specific UI
  24. Errors View
  25. Preferences

Learn GAML step by step

  1. Introduction
  2. Start with GAML
  3. Organization of a Model
  4. Basic programming concepts in GAML
  5. Manipulate basic Species
  6. Global Species
  7. Regular Species
  8. Defining Actions and Behaviors
  9. Interaction between Agents
  10. Attaching Skills
  11. Inheritance
  12. Defining Advanced Species
  13. Grid Species
  14. Graph Species
  15. Mirror Species
  16. Multi-Level Architecture
  17. Defining GUI Experiment
  18. Defining Parameters
  19. Defining Displays Generalities
  20. Defining Charts
  21. Defining 3D Displays
  22. Defining Monitors and Inspectors
  23. Defining Export files
  24. Defining User Interaction
  25. Exploring Models
  26. Run Several Simulations
  27. Batch Experiments
  28. Exploration Methods
  29. Optimizing Model Section
  30. Runtime Concepts
  31. Optimizing Models
  32. Multi-Paradigm Modeling
  33. Control Architecture
  34. Defining Equations


  1. Manipulate OSM Datas
  2. Diffusion
  3. Using Database
  4. Calling R
  5. Using FIPA ACL
  6. Using GamAnalyzer
  7. Using BDI
  8. Using Driving Skill
  9. Manipulate dates
  10. Manipulate lights
  11. Using comodel
  12. Save and restore Simulations
  13. Using network
  14. Headless mode
  15. FAQ
  16. Known Issues

GAML References

  1. Built-in Species
  2. Agent Built-in
  3. Model Built-in
  4. Experiment Built-in
  5. Built-in Skills
  6. Built-in Architecture
  7. Statements
  8. Data Type
  9. File Type
  10. Expressions
  11. Literals
  12. Units and Constants
  13. Pseudo Variables
  14. Variables And Attributes
  15. Operators [A-A]
  16. Operators [B-C]
  17. Operators [D-H]
  18. Operators [I-M]
  19. Operators [N-R]
  20. Operators [S-Z]
  21. Index


  1. Predator Prey
  2. Road Traffic
  3. 3D Tutorial
  4. Incremental Model
  5. Luneray's flu
  6. Co-modeling
  7. BDI Agents

Pedagogical materials

Developing Extensions

  1. Installing the GIT version
  2. Architecture of GAMA
  3. Developing a Plugin
  4. Developing a Skill
  5. Developing a Statement
  6. Developing an Operator
  7. Developing a Type
  8. Developing a Species
  9. Developing a Control Architecture
  10. Index of annotations
  11. IScope
  12. Creating a release of GAMA
  13. Documentation generation
  14. Website generation

Scientific References

Projects using GAMA

Training Session


Older versions

Coding Camp

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.