/*** * Name: Sprawl2 * Author: allan * Description: * Tags: Tag1, Tag2, TagN ***/ model Sprawl2 /* Insert your model definition here */ global{ //Size of the environment int environment_width <- 200 min: 10 max: 1000; int environment_height <- 200 min: 10 max: 1000; int Number_High_Income <-1 min:1 max:10; int Number_Medium_Income <-1 min:1 max:10; int Number_Low_Income <-1 min:1 max:10; //how many neighbors will each income group tolerate int High_Income_threshold <-15 min:0 max:100; int Medium_Income_threshold <-20 min:0 max:100; int Low_Income_threshold <-30 min:0 max:100; //number of times the cycle repeats int Iterations <-125 min:1 max:400; //size of the city center int CBD_size <-10 min:5 max:50; //Mobility level or The strength of the urban center as an attractor for each income group int High_Income_mobility <-1000 min:0 max:1000; int Medium_Income_mobility <-100 min:0 max:1000; int Low_Income_mobility <-50 min:0 max:1000; init { loop times:Iterations { create High_Income number: Number_High_Income; create Medium_Income number: Number_Medium_Income; create Low_Income number: Number_Low_Income; } create city_center number: 1; } //create a city center species that does not move and always goes to the center of the environment species city_center { aspect default {draw square(CBD_size) color:#black; location <- {(environment_width/4),(environment_height/4)}; } } //define High Income household as moving finite state machine species High_Income skills:[moving] control:fsm { aspect default {draw circle(0) color: rgb(226,88,60);} //determine how many other households are in neighboring cells (roughly) list hood_list <- agents_at_distance(5); int total_nearby <- length (hood_list); //randomly populate a cell, cell will turn gray to indicate it is being considered by the agent state developing initial: true { do goto target: any_location_in(circle(High_Income_mobility,{(environment_width/4),(environment_height/4)})); ask High_Income { ask Game_Grid at_distance(1) { if(self overlaps myself) { self.color_value <- 4; } } } // if the agent finds their cell suitable they transition to develop mode transition to: develop when:(total_nearby <= High_Income_threshold); // if the agent finds their cell unsuitable they transition to flight mode transition to: flight when:(total_nearby > High_Income_threshold); } // develop mode causes the agent to continuosly move toward itself in effect staying still. The cell it is in will be turned orange to indicate it is developed state develop { do goto target: any_location_in(circle(High_Income_mobility,{(environment_width/4),(environment_height/4)})); ask High_Income { ask Game_Grid at_distance(1) { if(self overlaps myself) { self.color_value <- 1; } } } } // flight mode causes the agent to reject the cell and exit the simulation. Before it does so it should convert the cell to gray. state flight { ask High_Income { ask Game_Grid at_distance(1) { if(self overlaps myself) { self.color_value <- 4; } } } } } //define Medium Income household as moving finite state machine species Medium_Income skills:[moving] control:fsm { aspect default {draw circle(0) color: rgb(238,127,46);} //determine how many other households are in neighboring cells (roughly) list hood_list <- agents_at_distance(5); int total_nearby <- length (hood_list); //randomly populate a cell, cell will turn gray to indicate it is being considered by the agent state developing initial: true { do goto target: any_location_in(circle(Medium_Income_mobility,{(environment_width/4),(environment_height/4)})); ask Medium_Income { ask Game_Grid at_distance(1) { if(self overlaps myself) { self.color_value <- 4; } } } // if the agent finds their cell suitable they transition to develop mode transition to: develop when:(total_nearby <= Medium_Income_threshold); // if the agent finds their cell unsuitable they transition to flight mode transition to: flight when:(total_nearby > Medium_Income_threshold); } // develop mode causes the agent to continuosly move toward itself in effect staying still. The cell it is in will be turned orange to indicate it is developed state develop { do goto target: any_location_in(circle(Medium_Income_mobility,{(environment_width/4),(environment_height/4)})); ask Medium_Income { ask Game_Grid at_distance(1) { if(self overlaps myself) { self.color_value <- 2; } } } } // flight mode causes the agent to reject the cell and exit the simulation. Before it does so it should convert the cell from gray back to green. state flight { ask Medium_Income { ask Game_Grid at_distance(1) { if(self overlaps myself) { self.color_value <- 4; } } } } } //define Low Income household as moving finite state machine species Low_Income skills:[moving] control:fsm { aspect default {draw circle(0) color: rgb(235,193,93);} //determine how many other households are in neighboring cells (roughly) list hood_list <- agents_at_distance(5); int total_nearby <- length (hood_list); //randomly populate a cell, cell will turn gray to indicate it is being considered by the agent state developing initial: true { do goto target: any_location_in(circle(Low_Income_mobility,{(environment_width/4),(environment_height/4)})); ask Low_Income { ask Game_Grid at_distance(1) { if(self overlaps myself) { self.color_value <- 4; } } } // if the agent finds their cell suitable they transition to develop mode transition to: develop when:(total_nearby <= Low_Income_threshold); // if the agent finds their cell unsuitable they transition to flight mode transition to: flight when:(total_nearby > Low_Income_threshold); } // develop mode causes the agent to continuosly move toward itself in effect staying still. The cell it is in will be turned orange to indicate it is developed state develop { do goto target: any_location_in(circle(Low_Income_mobility,{(environment_width/4),(environment_height/4)})); ask Low_Income { ask Game_Grid at_distance(1) { if(self overlaps myself) { self.color_value <- 3; } } } } // flight mode causes the agent to reject the cell and exit the simulation. Before it does so it should convert the cell from gray back to green. state flight { ask Low_Income { ask Game_Grid at_distance(1) { if(self overlaps myself) { self.color_value <- 4; } } } } } grid Game_Grid cell_width:5 cell_height:5 { int color_value <- 0; action update_color { if (color_value = 0) { //green space color value color <- rgb(62,151,95); //high income color value } else if (color_value = 1) { color <- rgb(226,88,60); //medium income color value } else if (color_value = 2) { color <- rgb(238,127,46); //low income color value } else if (color_value = 3) { color <- rgb(235,193,93); //developing color value } else if (color_value = 4) { color <- rgb(176,177,181); } color_value <- 0; } } //based on the color values decided by the agent fsm in the loop the grid will update each cell to the appropriate color at the end of the turn reflex update { ask Game_Grid { do update_color;} } } experiment Sprawl type: gui { parameter "Environment Width " var: environment_width category: 'Environment'; parameter "Environment Height " var: environment_height category: 'Environment'; parameter "City Center Size " var: CBD_size category: 'Environment'; parameter "General Density" var: Iterations category:'Population'; parameter "Relative Density of High Income" var: Number_High_Income category:'Population'; parameter "Relative Density of Medium Income" var: Number_Medium_Income category:'Population'; parameter "Relative Density of Low Income" var: Number_Low_Income category:'Population'; parameter "Crowding level acceptable to High Income" var: High_Income_threshold category:'Preferences'; parameter "Crowding level acceptable to Medium Income" var: Medium_Income_threshold category:'Preferences'; parameter "Crowding level acceptable to Low Income" var: Low_Income_threshold category:'Preferences'; parameter "High Income Mobility Level" var: High_Income_mobility category: 'Mobility'; parameter "Medium Income Mobility Level" var: Medium_Income_mobility category: 'Mobility'; parameter "Low Income Mobility Level" var: Low_Income_mobility category: 'Mobility'; output { display Sprawl type: java2D { grid Game_Grid lines: #black; species High_Income aspect: default; species Medium_Income aspect: default; species Low_Income aspect: default; species city_center aspect: default; } } }