/*** * Name: NewModel4 * Author: huixu,tong * Description: * Tags: Tag1, Tag2, TagN ***/ model NewModel4 /* Insert your model definition here */ global { // number of S int nb_people <- 5000; //number o f I int nb_infected_init <- 0; // number of E int nb_shadow_init<- 10; // number of R int nb_recovered_init<-0; // Defining the times component of the simulation date starting_date <- date([2020,2,26,0,0,0]); float step <- 1#hour; date current_date update: #now; // Time of latent period int days_latent <- 14 #d; // Time of hospital to treat int days_treat<- 10 #d; //Rate for the infection success : this is proportional to the number of infected people around the agent at 4#m distance float beta <- 0.05 ; // Number of Hospital beds int number_B <- 500; //Rate for resistance float delta <- step/14#day; //Size of the neighbours float neighbours_size <- 5 #m; // Defining the geographical envirnoment file road_shapefile <- file("../includes/road.shp"); file buildings_shapefile <- file("../includes/buildings5.shp"); file boundary_shapefile <- file("../includes/boundary.shp"); geometry shape<-envelope(road_shapefile); graph road_network; int nb_people_shadowed <- nb_shadow_init update: people count (each.is_shadow); int nb_people_infected <- nb_infected_init update: people count (each.is_infected); int nb_recovered <- nb_recovered_init update:people count (each.is_immune); int nb_susceptible <- nb_people update:people count (each.is_susceptible); int nb_hospital<-0 update:nb_hospital; int nb_people_not_infected <- nb_people - nb_infected_init-nb_shadow_init update: nb_people - nb_people_infected-nb_people_shadowed; int nb_people_not_infectedfind <- nb_people - nb_infected_init+ nb_recovered_init update: nb_people - nb_people_infected +nb_recovered; float infected_rate update: nb_people_infected/nb_people; float death_rate update:(nb_people-(nb_people_shadowed+nb_people_infected+nb_recovered+ nb_susceptible))/nb_people; //Public info list residential_buildings; list park; list commercial; list hospital; list supermarket; list office_school; list other_places; int max_stay_duration <- 2; //maximum staying duration is 2 hours float min_stay_duration <- 1/4; // minimum stay duration is 15 minutes int work_study_time_duration <- one_of(0,3,5); // 480 minutes for work float sport_time_duration <- rnd(2.0); // 480 minutes for sport //Policies bool active_testing <- false; int g_start_day <- 6; // global variable for start of day in minutes int g_end_day <- 10; // global variable for end of day in minutes int slacking <- 4; // slacking time in minutes. list work_study_times <- [9,13]; // work times in minutes list sport_times <- [7,19]; // sport times in minutes float testing_effort <- 0.1; float prop_delegation <- 1.0; init{ // Creating buildings create building from: buildings_shapefile with: [building_type::string(read("amenity"))] { switch (building_type) { match "office_school" { color <- #pink;} //blue violet match "hospital" { color <- #orange;} // midnight blue match "green" { color <-#lightgreen;} // olive match "commercial" { color <- #darkblue;} // orange red match "supermarket" { color <- #purple ;} // magenta - fuchsia match "residential" {color <- #grey;} // light yellow match "other place" { color <- #lightyellow;} // lime } } // Creating roads create roads from: road_shapefile; road_network <- as_edge_graph(roads); residential_buildings <- building where (each.building_type="residential"); park <- building where (each.building_type="green"); commercial <- building where (each.building_type ="commercial"); hospital <- building where (each.building_type="hospital"); supermarket <- building where (each.building_type="supermarket"); other_places <- building where (each.building_type ="other place"); office_school <- building where (each.building_type ="office_school"); // Creating the people agents and initiating few values create people number: nb_people_not_infected { is_susceptible <- true; is_infected <- false; is_immune <- false; is_shadow<- false; color <- #green; // Permenant home location. my_home <- one_of(residential_buildings); // Selecting random home location <- any_location_in(my_home);// // Setting up favorites places my_park <- park closest_to(self); my_office_school <- office_school closest_to(self); my_commercial <- commercial closest_to(self); my_supermarket <- supermarket closest_to(self); hospital_near_me <- hospital closest_to(self); my_other_places<- other_places closest_to(self); //Initializing individual schedules start_day <- g_start_day + rnd(-slacking,slacking); end_day <- g_end_day + rnd(-slacking,slacking); is_family_delegate <- flip(prop_delegation); } create people number: nb_infected_init { is_susceptible <- false; is_infected <- true; is_immune <- false; is_shadow<- false; color <- #red; // Permenant home location. my_home <- one_of(residential_buildings); // Selecting random home location <- any_location_in(my_home);// // Setting up favorites places my_park <- park closest_to(self); my_office_school <- office_school closest_to(self); my_commercial <- commercial closest_to(self); my_supermarket <- supermarket closest_to(self); hospital_near_me <- hospital closest_to(self); my_other_places<- other_places closest_to(self); //Initializing individual schedules start_day <- g_start_day + rnd(-slacking,slacking); end_day <- g_end_day + rnd(-slacking,slacking); is_family_delegate <- flip(prop_delegation); } create people number: nb_shadow_init { is_susceptible <- false; is_infected <- false; is_immune <- false; is_shadow<- true; color <- #yellow; // Permenant home location. my_home <- one_of(residential_buildings); // Selecting random home location <- any_location_in(my_home);// // Setting up favorites places my_park <- park closest_to(self); my_office_school <- office_school closest_to(self); my_commercial <- commercial closest_to(self); my_supermarket <- supermarket closest_to(self); hospital_near_me <- hospital closest_to(self); my_other_places<- other_places closest_to(self); //Initializing individual schedules start_day <- g_start_day + rnd(-slacking,slacking); end_day <- g_end_day + rnd(-slacking,slacking); is_family_delegate <- flip(prop_delegation); } create people number: nb_recovered_init { is_susceptible <- false; is_infected <- false; is_immune <- true; is_shadow<- false; color <- #blue; // Permenant home location. my_home <- one_of(residential_buildings); // Selecting random home location <- any_location_in(my_home);// // Setting up favorites places my_park <- park closest_to(self); my_office_school <- office_school closest_to(self); my_commercial <- commercial closest_to(self); my_supermarket <- supermarket closest_to(self); hospital_near_me <- hospital closest_to(self); my_other_places<- other_places closest_to(self); //Initializing individual schedules start_day <- g_start_day + rnd(-slacking,slacking); end_day <- g_end_day + rnd(-slacking,slacking); is_family_delegate <- flip(prop_delegation); } } // Ending simulation when everyone is infected or when the pandemic is over reflex end_simulation when: infected_rate = 1.0 { do pause; } } // Defining the building agents specifications species building { string building_type; rgb color; aspect base { draw shape color: color ; } } // Defining the roads agents specifications species roads { aspect base { draw shape color: #black; } } species people skills:[moving]{ float speed <- (0 + rnd(2)) #km/#h; bool is_time_to_move; //Different booleans to know in which state is the host bool is_susceptible ; bool is_infected ; bool is_immune ; bool is_shadow ; rgb color <-#green; float my_watch <- start_day; date my_date <- starting_date; //individual stat point target; // person's next destination ie. the person will be moving as long as he has an objective string objective; // The objective is one of ["hospitalized","active","relax","work","sport"] // Attributes of people building my_home; building hospital_near_me; building my_park; building my_commercial; building my_office_school; building my_supermarket; building my_other_places; list errands; bool agenda_is_expired; int start_day; int end_day; bool is_family_delegate; // Infection Risk int ngb_infected_numberq function: self neighbors_at (neighbours_size) count(each.is_infected ); int ngb_infected_numberp function: self neighbors_at (neighbours_size) count(each.is_shadow ); // Actions behaviors // action to work for the duration of work time action work_study { my_watch <- current_date.hour + work_study_time_duration; } // action to sport for the duration of sport time action sport { my_watch <- current_date.hour + sport_time_duration; } // action to complete a task and stay in location for a time range between maximum and minimum stay time action complete_task { my_watch <- current_date.hour + rnd (max_stay_duration - min_stay_duration); } // action to action update_my_watch { if (objective ="work_study" ){ do work_study; target <- nil; }else if (objective ="sport"){ do sport; target <- nil; }else { do complete_task; target <- nil; } } list get_today_agenda { int n_tasks <- 1 +rnd(2); return sample([my_commercial,my_supermarket, my_other_places],n_tasks,false); } reflex set_objective { if(objective!="hospitalized" and is_family_delegate){ if ((current_date.hour <= start_day) or (current_date.hour >= end_day)){ objective <- "relax"; }else if (current_date.hour in work_study_times){ objective <- "work_study"; }else if (current_date.hour in sport_times){ objective <- "sport"; }else { objective <- "active"; }} } reflex is_it_time_to_move when: objective="active" { if (current_date.hour >= my_watch){ is_time_to_move <- true; }else { is_time_to_move <- false; } } reflex go_home when: objective="relax"{ point my_home_location <- centroid(my_home); do goto target: my_home_location on: road_network; if (location = my_home_location) { my_watch <- 0.0; } } reflex get_my_agenda when: agenda_is_expired and objective="active" { errands <- get_today_agenda(); agenda_is_expired <- false; } reflex go_to_next when: (objective ="active" ) and (target = nil) and (is_time_to_move){ if(length(errands)>0) { building target_building <- errands[0]; remove index: 0 from: errands; target <- any_location_in(target_building); } else { agenda_is_expired <- true; objective <- "relax"; target <- nil; } } reflex go_office_school when: objective="work_study" { point my_office_school_location <- any_location_in(my_office_school); do goto target: my_office_school_location on: road_network; if (location = my_office_school_location ) { target <- nil; do work_study; } } reflex sport when: objective="sport" { point my_park_location <- any_location_in(my_park); do goto target: my_park_location on: road_network; if (location = my_park_location ) { target <- nil; do sport; } } reflex move when: !(target = nil) and objective = any("active","sport","work_study") and is_time_to_move { do goto target: target on: road_network; if (location = target) { do update_my_watch; } } //Reflex to pass the agent to the state shadowed reflex shadow when: is_susceptible { if (flip(1 - (1 - beta) ^ (ngb_infected_numberp+ ngb_infected_numberq))) { is_shadow <- true; is_susceptible <- false; is_infected <- false; is_immune <- false; color <- #yellow; my_date<- current_date; } } //Reflex to pass the agent to the state infected reflex infect when: is_shadow { if ((current_date - my_date)/3600)>=336 { is_susceptible <- false; is_infected <- true; is_immune <- false; is_shadow<- false; color <- #red; } } //Reflex to pass the agent to the state susceptible reflex immune when: is_infected { if flip(delta) { is_immune <- true; is_susceptible <- false; is_infected <- false; is_shadow<- false; color <- #blue; } } // Reflex to recover in hospital reflex recover_in_hospital when: is_infected and (current_date-my_date)/3600>=576{ if nb_people_infected<= 100 { is_immune <- true; is_susceptible <- false; is_infected <- false; is_shadow<- false; color <- #blue; } else if (nb_hospital<=100 ) { nb_hospital<-nb_hospital+1; is_immune <- true; is_susceptible <- false; is_infected <- false; is_shadow<- false; color <- #blue; } } reflex go_to_hospital when: active_testing and (is_infected and flip(testing_effort)){ point hospital_bed <- any_location_in(hospital_near_me); do goto target: hospital_bed on: road_network; objective <- "hospitalized"; } //Reflex to kill the agent according to the death rate reflex shallDie when: is_infected and flip(0.001){ create species(self) { target <- any_location_in (one_of(building)); } do die; } aspect basic { draw circle(5) color:color; } } experiment NoPolicy type: gui { parameter "nb_people_infected" var: nb_infected_init min: 0 max: 2000; parameter "nb_people_exposed" var: nb_shadow_init min: 0 max: 2000; parameter "nb_people_recoveredinhospital" var: number_B min: 0 max: 2000; output { monitor "Infected people rate" value: infected_rate; layout #split; display map type:opengl{ species roads aspect: base; species building aspect: base; species people aspect: basic; } display chart_display refresh: every(1 #hour) { chart "Disease spreading" type: series { data "susceptible" value: people count (each.is_susceptible) color: #green; data "infected" value: people count (each.is_infected) color: #red; data "immune" value: people count (each.is_immune) color: #blue; data "shadow" value: people count (each.is_shadow) color: #yellow; } } } } experiment Policy type: gui { parameter "nb_people_infected" var: nb_infected_init min: 0 max: 2000; parameter "nb_people_exposed" var: nb_shadow_init min: 0 max: 2000; parameter "nb_people_recoveredinhospital" var: number_B min: 0 max: 2000; parameter 'slack time' type: int var: slacking <- 0 category: "Curfew"; parameter 'active testing' type: bool var: active_testing <- true category: "MOH efforts"; parameter 'Probability of detection' type: float var: testing_effort <- 0.0 category: "MOH efforts"; parameter 'work study times' type: list var: work_study_times <- [0] category: "Praying at home"; parameter 'sport times' type: list var: sport_times <- [0] category: "Praying at home"; parameter 'go out only if necessary' type: float var: prop_delegation <- 0.5 category: "Staying at home"; output { monitor "Infected people rate" value: infected_rate; layout #split; display map type:opengl { species roads aspect: base; species building aspect: base; species people aspect: basic; } display chart_display refresh: every(1 #hour) { chart "Disease spreading" type: series { data "susceptible" value: people count (each.is_susceptible) color: #green; data "infected" value: people count (each.is_infected) color: #red; data "immune" value: people count (each.is_immune) color: #blue; data "shadow" value: people count (each.is_shadow) color: #yellow; } } } }