extensions [ gis csv matrix table profiler ] globals [ small-areas ;;gis dataset of the small age-sex ;;age sex dataset i z SA_ids ;;list of ids of the small areas households ;;dataset with household information sex1 ;;Male or Female sex2 ;;Male or Female homes ;;agentset of patches designated as homes %infected ;;the percent of infected agents in the simulation %susceptible ;;percent of susceptible agents %immune ;;percent of immune agents %recovered ;;percent of recovered agents %exposed ;;percent of exposed agents NUM_HUMANS ;;number of agents in the model hh_makeup ;;dataset with the household makeup family_child ;;dataset with the number of families with x number of children family_type_child ;;dataset with the number of families couple, lone parent with chidlren under/over 15 NUM_CHILDREN ;;the number of children in families econ_status ;;dataset with the economics status of the agents time ;;time of the day in the simulation day ;;day number in the simulation week ;;week number in the simulation SA ;;small area age/sex breakdown age_adult ;;list of number of total adults each age age_adult_F ;;list of number of female adults each age age_adult_M ;;list of number of male adults each age age_child ;;list of number of children each age x den_adult ;;total number of adults den_adult_F ;;total number of adult females den_adult_M ;; total number of adult males den_child_type_c ;;total number of children in a family with a couple den_child_type_m ;;total number of children in a family with a single mother den_child_type_d ;;total number of children in a family with a single father child_type_c ;;list of number of childlren with family with a couple child_type_m ;;list of number of childlren with family with a single mother child_type_d ;;list of number of childlren with family with a single father num_child ;;dataset with number of children den_size_u ;;number of children under 15 for each familysize in an all under 15 family child_size_u ;;list of number of children under 15 by familysize in an all under 15 family den_size_o ;;number of children over 15 for each familysize in an all over 15 family child_size_o ;;list of number of children over 15 for each familysize in an all over 15 family den_size_uo ;;number of children for each familysize in an under and over 15 family child_size_uo ;;list of number of children for each familysize in an under and over 15 family age_child_F ;;list of number of female children by age den_child_F ;;total number of female children age_child_M ;;list of number of male children by age den_child_M ;;total number of male children econ_F ;;list of number of females of each economic status den_econ_F ;;total number of females econ_M ;;list of number of males of each economic status den_econ_M ;;total number of males infected ;;the number of infected individuals susceptible ;;the number of susceptible individuals immune ;;the number of immune individuals vac_rate ;;dataset with the vaccination rates zones ;;dataset with zoning data roads ;;dataset with roads soc_class ;;dataset with social class data den_soc_F ;;total number of females soc_F ;;list of the number of females in each social class den_soc_M ;;total number of males soc_M ;;list of SA_labels ;;small area labels in csv files tot_contacts ;; list of mean number of contacts for each turtle mean_tot_contacts ;;mean of number of contacts for all turtles count_list ;; list of average contacts each time step seconds ;;number of seconds model has run for exposed ;;count of turtels exposed sick_turts ;;turtles who are infected at that timestep sick_turts_age ;;age of turtles infected at that timestep sick_turts_econ ;;econstatus of turtles infected at that timestep landuse ;;gis land use data set primary ;;primary school data set secondary ;;secondary school data set seconds_to_run ;;seconds taken for model to run students ;;agentset of students workers ;;agent set of working individuals non-workers ;; agent set of individuals not working stay-at-home ;;agent set of individuals who are stay at home parents infants ;;agent set of infants schools ;;patches that are schools work ;;patches that represent work places community ;;patches with community town_patches ;;patches in the town count_moved ;;turtles who have moved iterations ;;number of iterations gone through diss_list_p ;;list of dissmilarites of professionals diss_sum_p ;;sum of dissimilarites of professionals diss_list_m ;;list of dissmilarites of nonmanual diss_sum_m ;;sum of dissimilarites of nonmanual diss_list_s ;;list of dissmilarites of sem/skilled diss_sum_s ;;sum of dissimilarites semi/skilled diss_list_r ;;list of dissmilarites of retired diss_sum_r ;;sum of dissimilarites retired diss_list_o ;;list of dissmilarites of other diss_sum_o ;;sum of dissimilarites other diss_list_ma ;;list of dissmilarites of managerial diss_sum_ma ;;sum of dissimilarites managerial diss_sum ;;sum of all disimilarities centers ;patch in center of area center_patches ;;agentset of centetrs ;;dissimilarity index values for house prices diss_list_h1 diss_sum_h1 diss_list_h2 diss_sum_h2 diss_list_h3 diss_sum_h3 diss_list_h4 diss_sum_h4 diss_list_h5 diss_sum_h5 diss_list_h6 diss_sum_h6 ;;number of households in each social class N_p N_ma N_m N_s N_r N_o t ;;number of households T_h ;;number of households(house price datasets) ;;number of households in each house price range N_h1 N_h2 N_h3 N_h4 N_h5 N_h6 ] patches-own [ sm_area ;;the geoid for small area work-size ;;number of agents working on patch use ;;what is the "use" of the patch? Home, work, school, community etc. family ;;is there a family in the house house_type ;;what is the type of household, single, couple, couple with children, single parent child_age ;;age of children in house, under 15, over 15 or under and over 15 zone ;;the zoning of the patch land ;;land use of the patch unoccupied ;;unoccupied houses cord ;;coordinates and potential happiness of newhouses has_children ;;patch has had children added family_soc_class ;;social class of household test diss_sim_patch_p ;; dissimilarity measure of professinoals in neighbor radius diss_sim_patch_m ;; dissimilarity measure of manual in neighbor radius diss_sim_patch_s ;; dissimilarity measure of unskilled in neighbor radius diss_sim_patch_r ;; dissimilarity measure of retired in neighbor radius diss_sim_patch_o ;; dissimilarity measure of other in neighbor radius diss_sim_patch_ma ;; dissimilarity measure of other in neighbor radius unoccup ;;unoccupied households neighbor_cpatch ;; center patches that are adjacent to patch ;;count of households in each social class within a radius N_pi N_mai N_mi N_si N_ri N_oi ti ;;total households within the radius ;;count of households in each price range within the radius N_h1i N_h2i N_h3i N_h4i N_h5i N_h6i ncp ;;neigboring center patches ] turtles-own[ small_area ;;what small area does the agent live in home-patch ;;home of the agent to-work? ;;is the agent going to work to-home? ;;is the agent going home work-patch ;;where does the agent work age sex hhsize ;;how many agents in the household sick? ;;is the agent sick immune? ;;is the agent immune exposed? ;;was the agent exposed contacts ;;contacts the agent has had adult? ;;is the agent an adult hh_type ;;type of family single, couple, couple with children etc. familyid ;;number same for all agents in the same family childid_U15 ;;number for all children in the same family child_type ;;is the family made up of children all under 15, all over 15 or a mix child_size ;;number of children single_dad ;;is the agent a single father single_mom ;;is the agent a single mother couple ;;is the agent part of a couple econ_stat ;economic status of the agent: work, school, unemployed, retired etc. infant ;;does the agent have an infant child num_contacts ;;number of contacts dest-patch ;;where is an agent moving to immunity ;;level of immunity the individual has vaccinated;;if individual was vaccinated job_type ;;job type/social class of agent work-path ;path to get to school or work home_work-path ;path to go from school or work to home avg_contacts ;list with average contacts each tick days_exposed ; number of days turtle will stay exposed but not infectious days_sick ; number of days turtle will remain sick and infectious cont_table ;; table of who numbers of turtles in contact with tick_exposed ;;time the agent was exposed ticks_exposed ;;testing variable ticks_when_sick ;;testing variables ticks_sick ;;testing variables my-contacts-table ;;table of contacts per tick empty_tab ;; empty table count_similar_hh ;;count of houses with the same household type count_similar_es ;;count of houses with the same econ status count_neighbors ;;count of neighbors in the radius count_neighbors_turts ;;count of turtles in radius happiness ;;percent of turtles similar to turtle possible_home ;;agentset of possible homes to move to new_hap ;;happiness rates at possibel homes hh ;;list of happienss rates count_similar_child ;;count of houses with similar child ages count_similar_sc ;;count houses with same social class soc_cl ;;social class of turtles ] breed [people person] to setup_createworld ca if town = "Schull" [ resize-world -300 300 -300 300 ] if town = "Tramore" [ resize-world -380 380 -380 380 ] if town = "Kinsale" [ resize-world -530 530 -530 530 ] set-default-shape turtles "person" set small-areas gis:load-dataset (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/shp/" town ".shp" ) ;;load the gis dataset set zones gis:load-dataset (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/shp/Zoning_Data.shp") ;;load the gis dataset set landuse gis:load-dataset (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/shp/landuse.shp") ;;load the gis dataset set primary gis:load-dataset (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/shp/primary.shp") ;;load the gist datset set secondary gis:load-dataset (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/shp/secondary.shp") ;;load the gis dataset set SA csv:from-file (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/smareas_ids.csv") ;;gets the age-sex breakdown data set set vac_rate csv:from-file "C:/Users/D15127585/Google Drive/DIT/data/vac_rate_measles.csv" ;;vaccination rates gis:set-world-envelope gis:envelope-of small-areas set homes [] set tot_contacts [0] set count_list [0] setup-areas get-sa-list setup-zones setup-schools setup-households setup-econstatus setup-soc_class setup-work set-immunitylevel start-infection ask turtles [set to-home? FALSE set num_contacts [] set my-contacts-table table:make ] set iterations 0 set_centers find-dissimlarity ask turtles with [soc_cl = "Professional"][set color blue] ask turtles with [soc_cl = "Managerial"][set color red] ask turtles with [soc_cl = "Non-Manual"][set color pink] ask turtles with [soc_cl = "Semi/skilled"][set color green] ask turtles with [soc_cl = "Retired"][set color white] ask turtles with [soc_cl = "Other"][set color orange] reset-timer reset-ticks end to cluster find-similar ifelse count_moved = 0 and iterations > 0[ find-dissimlarity stop setup-work ] [ set count_moved 0 move-house set iterations iterations + 1 find-dissimlarity ] tick end to go if count turtles with [(sick? = TRUE or exposed? = TRUE) and immune? = FALSE] = 0 [ set seconds_to_run timer find_contacts stop ] clock move infect recover update-global-variables who-sick update-numcontacts reset-contacts clear-links tick end to setup ca if town = "Schull" [ resize-world -300 300 -300 300 ] if town = "Tramore" [ resize-world -380 380 -380 380 ] if town = "Kinsale" [ resize-world -530 530 -530 530 ] import-world (word town "_town.csv") end to setup-areas gis:set-drawing-color white gis:draw small-areas 1 ;;draw the small areas gis:apply-coverage small-areas "SMALL_AREA" sm_area ;;set the variable sm_area to the geoid ask patches [ if not is-string? sm_area[ set sm_area 0] ] set town_patches patches with [sm_area != 0] ask town_patches [ foreach gis:feature-list-of zones [[zo] -> if gis:intersects? self zo[ set zone gis:property-value zo "ZONE_GZT" ] ] foreach gis:feature-list-of landuse [[l] -> if gis:intersects? self l[ set land gis:property-value l "TYPE" ] ] foreach gis:feature-list-of small-areas [[un] -> if gis:intersects? self un [ set unoccupied gis:property-value un "UNOCC2011" ] ] ] end to get-sa-list ;;creates a list of the small area geoids set i 0 set SA_ids [] set SA_labels [] while [i < length SA] [ set SA_ids lput item 0 item i SA SA_ids ifelse is-string? item 0 item i SA [ set SA_labels lput substring (item 0 item i SA) 0 9 SA_labels ] [ set SA_labels lput item 0 (item i SA) SA_labels ifelse 100000000 - (item 0 item i SA) > 0 [ set SA_ids replace-item i SA_ids word "0" (item 0 item i SA)][ set SA_ids replace-item i SA_ids word "" (item 0 item i SA) ] ] set i i + 1 ] end to set-immunitylevel ifelse vaccinations[ ask turtles with [age > (year - item 0 (item 1 vac_rate))][ if random-float 1 < .99 [ set immunity .995 ] ] ask turtles with [age < 1][ if random-float 1 < .5 [ set immunity .8 ]] set i 1 while [i <= (year - item 0 (item 1 vac_rate))][ ask turtles with [age = (year - item 0 (item i vac_rate))][ if soc_cl = "Professional" or soc_cl = "Retired" [ ifelse random-float 1 < item 1 (item i vac_rate) [ ; if 1 < .98[ set immunity vaccine_immunity ] [set immunity 0] ];] if soc_cl = "Managerial" [ ifelse random-float 1 < ((1 - item 1 (item i vac_rate)) * 1.377) [ ;ifelse random-float 1 < .98[ set immunity 0 ] [set immunity vaccine_immunity] ] if soc_cl = "Non-Manual" [ ifelse random-float 1 < ((1 - item 1 (item i vac_rate)) * 1.237) [ ;ifelse random-float 1 < .98[ set immunity 0 ] [set immunity vaccine_immunity] ] if soc_cl = "Semi/skilled" [ ifelse random-float 1 < ((1 - item 1 (item i vac_rate)) * 1.310) [ ;ifelse random-float 1 < .98[ set immunity 0 ] [set immunity vaccine_immunity] ] if soc_cl = "Other" [ ifelse random-float 1 < ((1 - item 1 (item i vac_rate)) * 1.612) [ ;ifelse random-float 1 < .98[ set immunity 0 ] [set immunity vaccine_immunity] ] ] set i i + 1 ] ] [ ask turtles [ set immunity 0] ] end to start-infection ask n-of num_infected turtles with [immunity = 0 and age > 12 and age < 20 and econ_stat = "Student"][set sick? TRUE set color red set days_sick round((random-normal 8 .5) * 12) set tick_exposed 0 set days_exposed 0 ] end to setup-households ;;setting up the number of agents, ages, sex and children in each household, done for each small area foreach SA_labels[ [?1] -> let datasethouseld (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/python/household" ?1 ".csv") set households csv:from-file datasethouseld let j position ?1 SA_labels ask n-of item 1 (item 9 households) town_patches with [ sm_area = word "" item j SA_ids and use != "work" and use != "preschool" and use != "secondary school" and use != "primary school" and (zone = 0 or use = "residential" or use = "town center" or use = "mixed" or use = "open")] ;;sets up the number of households in each area [ ;set pcolor blue set use "home" set family FALSE ] set homes town_patches with [use = "home" and sm_area = word "" item j SA_ids] ask one-of patches with [ sm_area = word "" item j SA_ids] [ set unoccup [unoccupied] of self ifelse unoccup <= count patches with [ sm_area = word "" item j SA_ids and (zone = 0 or use = "residential" or use = "town center" or use = "mixed" or use = "open") and use != "preschool" and use != "primary school" and use != "secondary school"] [ ask n-of unoccup patches with [ sm_area = word "" item j SA_ids and (zone = 0 or use = "residential" or use = "town center" or use = "mixed" or use = "open") and use != "preschool" and use != "primary school" and use != "secondary school"] [ set use "home" set family FALSE set has_children FALSE ] ] [ ask patches with [ sm_area = word "" item j SA_ids and (zone = 0 or use = "residential" or use = "town center" or use = "mixed" or use = "open") and use != "preschool" and use != "primary school" and use != "secondary school"][ set use "home" set family FALSE set has_children FALSE ] ] ] set homes town_patches with [use = "home" and sm_area = word "" item j SA_ids] let datasethh (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/python/hh_makeup" ?1 ".csv") set hh_makeup csv:from-file datasethh let datasetage (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/python/age_sex" ?1 ".csv") set age-sex csv:from-file datasetage let datasetchildtype (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/python/fam_child_15" ?1 ".csv") set family_type_child csv:from-file datasetchildtype let datasetnumchild (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/python/num_child" ?1 ".csv") set num_child csv:from-file datasetnumchild set i 20 set den_adult 0 set age_adult [] while [i < 35][ set den_adult den_adult + ((item 1 (item i age-sex)) + (item 2 (item i age-sex))) set age_adult lput den_adult age_adult set i i + 1 ] set i 20 set den_adult_F 0 set age_adult_F [] while [i < 35][ set den_adult_F den_adult_F + ((item 1 (item i age-sex))) set age_adult_F lput den_adult_F age_adult_F set i i + 1 ] set i 20 set den_adult_M 0 set age_adult_M [] while [i < 35][ set den_adult_M den_adult_M + ((item 2 (item i age-sex))) set age_adult_M lput den_adult_M age_adult_M set i i + 1 ] set i 1 set den_child_type_c 0 set child_type_c [] while [i < 4][ set den_child_type_c den_child_type_c + ((item 1 (item i family_type_child))) set child_type_c lput den_child_type_c child_type_c set i i + 1 ] set den_child_type_m 0 set child_type_m [] set i i + 1 while [i < 7][ set den_child_type_m den_child_type_m + ((item 1 (item i family_type_child))) set child_type_m lput den_child_type_m child_type_m set i i + 1 ] set den_child_type_d 0 set child_type_d [] set i i + 1 while [i < 11][ set den_child_type_d den_child_type_d + ((item 1 (item i family_type_child))) set child_type_d lput den_child_type_d child_type_d set i i + 1 ] set den_size_u 0 set child_size_u [] set i 2 while [i < 7][ set den_size_u den_size_u + ((item 1 (item i num_child))) set child_size_u lput den_size_u child_size_u set i i + 1 ] set den_size_o 0 set child_size_o [] set i i + 1 while [i < 13][ set den_size_o den_size_o + ((item 1 (item i num_child))) set child_size_o lput den_size_o child_size_o set i i + 1 ] set den_size_uo 0 set child_size_uo [] set i i + 1 while [i < 19][ set den_size_uo den_size_uo + ((item 1 (item i num_child))) set child_size_uo lput den_size_uo child_size_uo set i i + 1 ] set i 1 set den_child_F 0 set age_child_F [] while [i < 20][ set den_child_F den_child_F + ((item 1 (item i age-sex))) set age_child_F lput den_child_F age_child_F set i i + 1 ] set i 1 set den_child_M 0 set age_child_M [] while [i < 20][ set den_child_M den_child_M + ((item 2 (item i age-sex))) set age_child_M lput den_child_M age_child_M set i i + 1 ] ask n-of item 1 (item 1 hh_makeup) homes with [family = FALSE ][ set house_type item 0 (item 1 hh_makeup) sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE let items-to-pick ["Female" "Male"] let cum-pmf list (item 1 (item 35 age-sex)) ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) set cum-pmf map [ [??1] -> ??1 / ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) ] cum-pmf ; to normalize set sex item random-from-cum-pmf cum-pmf items-to-pick if sex = "Female" [ let items-to-pick_a [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf_a age_adult_F set cum-pmf_a map [ [??1] -> ??1 / den_adult_F ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a set familyid who ] if sex = "Male" [ let items-to-pick_a [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf_a age_adult_M set cum-pmf_a map [ [??1] -> ??1 / den_adult_M ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a set familyid who ] set home-patch patch-here set hh_type item 0 (item 1 hh_makeup) ] set family TRUE ] ask n-of item 1 (item 2 hh_makeup) homes with [family = FALSE ][ set house_type item 0 (item 2 hh_makeup) sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set sex "Female" let items-to-pick [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf age_adult_F set cum-pmf map [ [??1] -> ??1 / den_adult_F ] cum-pmf ; to normalize set age item random-from-cum-pmf cum-pmf items-to-pick set familyid who set hh_type item 0 (item 2 hh_makeup) set couple TRUE set home-patch patch-here ] sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set sex "Male" let age_hh [age] of one-of turtles-here with [age != 0] set age age_hh + random 10 + random -10 if age < 18 [ set age 19 ] let id [familyid] of one-of turtles-here with [familyid != 0] set familyid id set hh_type item 0 (item 2 hh_makeup) set couple TRUE set home-patch patch-here ] set family TRUE ] ask n-of item 1 (item 3 hh_makeup) homes with [family = FALSE ][ set house_type item 0 (item 3 hh_makeup) sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set sex "Female" let items-to-pick [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf age_adult_F set cum-pmf map [ [??1] -> ??1 / den_adult_F ] cum-pmf ; to normalize set age item random-from-cum-pmf cum-pmf items-to-pick set familyid who set hh_type item 0 (item 3 hh_makeup) set couple TRUE let items-to-pick_c ["U15" "O15" "UO15"] let cum-pmf_c child_type_c set cum-pmf map [ [??1] -> ??1 / den_child_type_c ] cum-pmf_c ; to normalize set child_type item random-from-cum-pmf cum-pmf items-to-pick_c ask patch-here [set child_age [child_type] of one-of turtles-here] set home-patch patch-here ] sprout-people 1[ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set sex "Male" let age_hh [age] of one-of turtles-here with [age != 0] set age age_hh + random 10 + random -10 if age < 18 [ set age 19 ] let id [familyid] of one-of turtles-here with [familyid != 0] set familyid id set hh_type item 0 (item 3 hh_makeup) set couple TRUE let hh_child [child_type] of one-of turtles-here with [child_type != 0] set child_type hh_child set home-patch patch-here ] set family TRUE ] ask n-of item 1 (item 4 hh_makeup) homes with [family = FALSE ][ set house_type item 0 (item 4 hh_makeup) sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set sex "Male" set hh_type item 0 (item 4 hh_makeup) set single_dad TRUE let items-to-pick [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf age_adult_M set cum-pmf map [ [??1] -> ??1 / den_adult_M ] cum-pmf ; to normalize set age item random-from-cum-pmf cum-pmf items-to-pick let items-to-pick_c ["U15" "O15" "UO15"] let cum-pmf_c child_type_d set cum-pmf_c map [ [??1] -> ??1 / den_child_type_d ] cum-pmf_c ; to normalize set child_type item random-from-cum-pmf cum-pmf_c items-to-pick_c ask patch-here [set child_age [child_type] of one-of turtles-here] set home-patch patch-here set familyid who ] set family TRUE ] ask n-of item 1 (item 5 hh_makeup) homes with [family = FALSE ][ set house_type item 0 (item 5 hh_makeup) sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set sex "Female" set hh_type item 0 (item 5 hh_makeup) set single_mom TRUE let items-to-pick [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf age_adult_F set cum-pmf map [ [??1] -> ??1 / den_adult_F ] cum-pmf ; to normalize set age item random-from-cum-pmf cum-pmf items-to-pick let items-to-pick_c ["U15" "O15" "UO15"] let cum-pmf_c child_type_m set cum-pmf_c map [ [??1] -> ??1 / den_child_type_m ] cum-pmf_c ; to normalize set child_type item random-from-cum-pmf cum-pmf_c items-to-pick_c ask patch-here [set child_age [child_type] of one-of turtles-here] set home-patch patch-here set familyid who ] set family TRUE ] ask n-of item 1 (item 6 hh_makeup) homes with [family = FALSE ][ set house_type item 0 (item 6 hh_makeup) sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set sex "Female" let items-to-pick [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf age_adult_F set cum-pmf map [ [??1] -> ??1 / den_adult_F ] cum-pmf ; to normalize set age item random-from-cum-pmf cum-pmf items-to-pick set familyid who set hh_type item 0 (item 6 hh_makeup) set couple TRUE set home-patch patch-here ] sprout-people 1[ set sex "Male" set color yellow set size 5 let age_hh [age] of one-of turtles-here with [age != 0] set age age_hh + random 10 + random -10 let id [familyid] of one-of turtles-here with [familyid != 0] set familyid id set hh_type item 0 (item 6 hh_makeup) set couple TRUE set home-patch patch-here set adult? TRUE ] set family TRUE ] ask n-of item 1 (item 7 hh_makeup) homes with [family = FALSE ][ set house_type item 0 (item 7 hh_makeup) sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set sex "Female" let items-to-pick [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf age_adult_F set cum-pmf map [ [??1] -> ??1 / den_adult_F ] cum-pmf ; to normalize set age item random-from-cum-pmf cum-pmf items-to-pick set familyid who set hh_type item 0 (item 7 hh_makeup) let items-to-pick_c ["U15" "O15" "UO15"] let cum-pmf_c child_type_c set cum-pmf map [ [??1] -> ??1 / den_child_type_c ] cum-pmf_c ; to normalize set child_type item random-from-cum-pmf cum-pmf items-to-pick_c set couple TRUE ask patch-here [set child_age [child_type] of one-of turtles-here] set home-patch patch-here ] sprout-people 1 [ set sex "Male" set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE let age_hh [age] of one-of turtles-here with [age != 0] set age age_hh + random 10 + random -10 if age < 18 [ set age 19 ] let id [familyid] of one-of turtles-here with [familyid != 0] set familyid id set hh_type item 0 (item 7 hh_makeup) let child_hh [child_type] of one-of turtles-here with [child_type != 0] set child_type child_hh set home-patch patch-here set couple TRUE ] set family TRUE ] ask n-of item 1 (item 8 hh_makeup) homes with [family = FALSE ][ set house_type item 0 (item 8 hh_makeup) sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set sex "Male" set hh_type item 0 (item 8 hh_makeup) set single_dad TRUE set familyid who let items-to-pick [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf age_adult_M set cum-pmf map [ [??1] -> ??1 / den_adult_M ] cum-pmf ; to normalize set age item random-from-cum-pmf cum-pmf items-to-pick let items-to-pick_c ["U15" "O15" "UO15"] let cum-pmf_c child_type_d set cum-pmf_c map [ [??1] -> ??1 / den_child_type_d ] cum-pmf_c ; to normalize set child_type item random-from-cum-pmf cum-pmf_c items-to-pick_c ask patch-here [set child_age [child_type] of one-of turtles-here] set home-patch patch-here ] set family TRUE ] ask n-of item 1 (item 9 hh_makeup) homes with [family = FALSE ][ set house_type item 0 (item 9 hh_makeup) sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set sex "Female" set hh_type item 0 (item 9 hh_makeup) set single_mom TRUE set familyid who let items-to-pick [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf age_adult_F set cum-pmf map [ [??1] -> ??1 / den_adult_F ] cum-pmf ; to normalize set age item random-from-cum-pmf cum-pmf items-to-pick let items-to-pick_c ["U15" "O15" "UO15"] let cum-pmf_c child_type_m set cum-pmf_c map [ [??1] -> ??1 / den_child_type_m ] cum-pmf_c ; to normalize set child_type item random-from-cum-pmf cum-pmf_c items-to-pick_c ask patch-here [set child_age [child_type] of one-of turtles-here] set home-patch patch-here ] set family TRUE ] ask n-of item 1 (item 10 hh_makeup) homes with [family = FALSE ][ set house_type "other" sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set hh_type "other" let items-to-pick ["Female" "Male"] let cum-pmf list (item 1 (item 35 age-sex)) ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) set cum-pmf map [ [??1] -> ??1 / ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) ] cum-pmf ; to normalize set sex item random-from-cum-pmf cum-pmf items-to-pick if sex = "Female" [ let items-to-pick_a [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf_a age_adult_F set cum-pmf_a map [ [??1] -> ??1 / den_adult_F ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a set familyid who ] if sex = "Male" [ let items-to-pick_a [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf_a age_adult_M set cum-pmf_a map [ [??1] -> ??1 / den_adult_M ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a set familyid who ] set home-patch patch-here ] set family TRUE ] ask n-of item 1 (item 11 hh_makeup) homes with [family = FALSE ][ set house_type "other" sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set hh_type "other" let items-to-pick ["Female" "Male"] let cum-pmf list (item 1 (item 35 age-sex)) ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) set cum-pmf map [ [??1] -> ??1 / ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) ] cum-pmf ; to normalize set sex item random-from-cum-pmf cum-pmf items-to-pick if sex = "Female" [ let items-to-pick_a [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf_a age_adult_F set cum-pmf_a map [ [??1] -> ??1 / den_adult_F ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a set familyid who ] if sex = "Male" [ let items-to-pick_a [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf_a age_adult_M set cum-pmf_a map [ [??1] -> ??1 / den_adult_M ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a set familyid who ] set home-patch patch-here ] set family TRUE ] if den_size_u != 0 [ ask patches with [child_age = "U15" and sm_area = word "" item j SA_ids][ let items-to-pick [1 2 3 4 5] let cum-pmf child_size_u set cum-pmf map [ [??1] -> ??1 / den_size_u ] cum-pmf ; to normalize let kids item random-from-cum-pmf cum-pmf items-to-pick sprout-people kids[ set small_area word "" item j SA_ids set color yellow set size 5 set adult? FALSE set child_type "U15" set child_size kids let items-to-pick_s ["Female" "Male"] let cum-pmf_s list (item 1 (item 35 age-sex)) ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) set cum-pmf_s map [ [??1] -> ??1 / ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) ] cum-pmf_s ; to normalize set sex item random-from-cum-pmf cum-pmf_s items-to-pick_s if sex = "Female" [ let items-to-pick_a [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] let cum-pmf_a age_child_F set cum-pmf_a map [ [??1] -> ??1 / den_child_F ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a ] if sex = "Male" [ let items-to-pick_a [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] let cum-pmf_a age_child_M set cum-pmf_a map [ [??1] -> ??1 / den_child_M ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a ] let id [familyid] of one-of turtles-here with [familyid != 0] set familyid id set home-patch patch-here ] ] ] if den_size_o != 0 [ ask patches with [child_age = "O15" and sm_area = word "" item j SA_ids][ let items-to-pick [1 2 3 4 5] let cum-pmf child_size_o set cum-pmf map [ [??1] -> ??1 / den_size_o ] cum-pmf ; to normalize let kids item random-from-cum-pmf cum-pmf items-to-pick sprout-people kids[ set small_area word "" item j SA_ids set color yellow set size 5 set adult? FALSE set child_type "O15" set child_size kids let items-to-pick_s ["Female" "Male"] let cum-pmf_s list (item 1 (item 35 age-sex)) ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) set cum-pmf_s map [ [??1] -> ??1 / ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) ] cum-pmf_s ; to normalize set sex item random-from-cum-pmf cum-pmf_s items-to-pick_s if sex = "Female" [ let items-to-pick_a [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] let cum-pmf_a age_child_F set cum-pmf_a map [ [??1] -> ??1 / den_child_F ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a ] if sex = "Male" [ let items-to-pick_a [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] let cum-pmf_a age_child_M set cum-pmf_a map [ [??1] -> ??1 / den_child_M ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a ] let id [familyid] of one-of turtles-here with [familyid != 0] set familyid id set home-patch patch-here ] ] ] if den_size_uo != 0 [ ask patches with [child_age = "UO15" and sm_area = word "" item j SA_ids][ let items-to-pick [1 2 3 4 5] let cum-pmf child_size_uo set cum-pmf map [ [??1] -> ??1 / den_size_uo ] cum-pmf ; to normalize let kids item random-from-cum-pmf cum-pmf items-to-pick sprout-people kids[ set small_area word "" item j SA_ids set color yellow set size 5 set adult? FALSE set child_type "UO15" set child_size kids let items-to-pick_s ["Female" "Male"] let cum-pmf_s list (item 1 (item 35 age-sex)) ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) set cum-pmf_s map [ [??1] -> ??1 / ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) ] cum-pmf_s ; to normalize set sex item random-from-cum-pmf cum-pmf_s items-to-pick_s if sex = "Female" [ let items-to-pick_a [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] let cum-pmf_a age_child_F set cum-pmf_a map [ [??1] -> ??1 / den_child_F ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a ] if sex = "Male" [ let items-to-pick_a [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] let cum-pmf_a age_child_M set cum-pmf_a map [ [??1] -> ??1 / den_child_M ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a ] let id [familyid] of one-of turtles-here with [familyid != 0] set familyid id set home-patch patch-here ] ] ] if count turtles with [small_area = word "" item j SA_ids] < ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) [ let diff ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) - count turtles with [sm_area = word "" item j SA_ids] if count patches with [use = "home" and sm_area = word "" item j SA_ids and (house_type = "couple_plus" or house_type = "couple_children_plus" or house_type = "dad_children_others" or house_type = "mom_children_others" or house_type = "other") ] = 0 [ ask n-of diff patches with [sm_area = word "" item j SA_ids and (zone = 0 or use = "residential" or use = "town center" or use = "mixed" or use = "open") and use != "preschool" and use != "primary school" and use != "secondary school" and use != "work"][ set use "home" set house_type "other" ] ] set i 0 ; let diff ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) - count turtles with [sm_area = word "" item j SA_ids] while [i < diff][ ask turtles [set sick? diff] ask turtles [set exposed? i] ask one-of patches with [use = "home" and sm_area = word "" item j SA_ids and (house_type = "couple_plus" or house_type = "couple_children_plus" or house_type = "dad_children_others" or house_type = "mom_children_others" or house_type = "other") ] [ sprout-people 1 [ set small_area word "" item j SA_ids set color yellow set size 5 set adult? TRUE set hh_type [house_type] of patch-here let items-to-pick ["Female" "Male"] let cum-pmf list (item 1 (item 35 age-sex)) ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) set cum-pmf map [ [??1] -> ??1 / ((item 1 (item 35 age-sex)) + (item 2 (item 35 age-sex))) ] cum-pmf ; to normalize set sex item random-from-cum-pmf cum-pmf items-to-pick if sex = "Female" [ let items-to-pick_a [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf_a age_adult_F set cum-pmf_a map [ [??1] -> ??1 / den_adult_F ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a ] if sex = "Male" [ let items-to-pick_a [19 20 25 30 35 40 45 50 55 60 65 70 75 80 85] let cum-pmf_a age_adult_M set cum-pmf_a map [ [??1] -> ??1 / den_adult_M ] cum-pmf_a ; to normalize set age item random-from-cum-pmf cum-pmf_a items-to-pick_a ] set home-patch patch-here set hh_type [house_type] of patch-here ifelse count turtles-here > 1 [ let id [familyid] of one-of turtles-here with [familyid != 0] set familyid id ][set familyid [who] of self ] ] ] set i i + 1 ] ] ] set NUM_HUMANS count turtles ask turtles [set sick? FALSE set exposed? FALSE set immune? FALSE set contacts n-values NUM_HUMANS [0] set num_contacts [] ] end to-report random-from-cum-pmf [cum-pmf] let n random-float 1 report length filter [ [?1] -> ?1 < n ] cum-pmf end to setup-zones ask town_patches with [zone = "G1" or zone = "G3"] [ set use "open"] ask town_patches with [zone = "M2" or zone = "C1.1"] [set use "town center"] ask town_patches with [zone = "S3" or zone = "S5"] [set use "community"] ask town_patches with [zone = "R" or zone = "R1" or zone ="R2" or zone = "R3" or zone = "M5" or zone = "R4"][ set use "residential" ] ask town_patches with [zone = "C6" or zone = "C.2.1"] [set use "commercial" ] ask town_patches with [zone = "M1"] [set use "mixed" ] ask town_patches [ if not is-string? zone [ set zone 0] ] ask town_patches with [zone = 0][ if land = "construction" or land = "military" or land = "farmyard" or land = "government" or land = "prison" or land = "commercial" or land = "industrial" or land = "farm" or land = "quarry" or land = "farmland" [ set use "commercial" ] if land = "pitch" or land = "recreation_groun" or land = "village_green" or land = "religious" or land = "garden" or land = "pedestrian" or land = "leisure" or land = "churchyard" or land = "golf" or land = "sport" or land = "community" [ set use "community" ] if land = "local_authority" or land = "medical" or land = "tourism" [ set use "mixed" ] if land = "retail" [ set use "town center" ] if land = "residential" or land = "caravan_site" [ set use "residential" ] ] end to setup-schools ask patches gis:intersecting primary [ set use "primary school" ] ask patches gis:intersecting secondary [ set use "secondary school" ] if count patches with [use = "secondary school"] = 0 [ ask one-of patches with [sm_area = 0][ set use "secondary school"] ] if count patches with [use = "primary school"] = 0 [ ask one-of patches with [sm_area = 0][ set use "primary school"] ] ask n-of 10 town_patches with [ use = "commercial" or use = "town center" or use = "mixed" ] [ set pcolor grey ;set plabel "work" set use "work" set work-size 10 ] ask one-of patches with [sm_area != 0 and use != "primary school" and use != "secondary school" and use != "work" and use != "home"][ set use "preschool" ; ask neighbors4 [set use "preschool"] ] set schools patches with [use = "primary school" or use = "secondary school" or use = "preschool"] set work patches with [use = "work"] set community patches with [sm_area != 0 and (use = "residential" or use = "open" or use = "town center" or use = "mixed")] end to setup-econstatus foreach SA_labels[ [?1] -> let j position ?1 SA_labels let datasetecon (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/python/econ_status" ?1 ".csv") ;;path to economic status dataset set econ_status csv:from-file datasetecon ;;setting the economic status dataset set den_econ_F 0 set econ_F [] set den_econ_F (item 1 (item 1 econ_status)) + (item 1 (item 2 econ_status)) + (item 1 (item 3 econ_status)) + (item 1 (item 7 econ_status)) + (item 1 (item 8 econ_status)) set econ_F (list (item 1 (item 1 econ_status)) ((item 1 (item 1 econ_status)) + (item 1 (item 2 econ_status))) ((item 1 (item 1 econ_status)) + (item 1 (item 2 econ_status)) + (item 1 (item 3 econ_status))) ((item 1 (item 1 econ_status)) + (item 1 (item 2 econ_status)) + (item 1 (item 3 econ_status)) + (item 1 (item 7 econ_status)) ) ((item 1 (item 1 econ_status)) + (item 1 (item 2 econ_status)) + (item 1 (item 3 econ_status)) + (item 1 (item 7 econ_status)) + (item 1 (item 8 econ_status)) ) ) set den_econ_M 0 set econ_M [] set den_econ_M (item 2 (item 1 econ_status)) + (item 2 (item 2 econ_status)) + (item 2 (item 3 econ_status)) + (item 2 (item 7 econ_status)) + (item 2 (item 8 econ_status)) set econ_M (list (item 2 (item 1 econ_status)) ((item 2 (item 1 econ_status)) + (item 2 (item 2 econ_status))) ((item 2 (item 1 econ_status)) + (item 2 (item 2 econ_status)) + (item 2 (item 3 econ_status))) ((item 2 (item 1 econ_status)) + (item 2 (item 2 econ_status)) + (item 2 (item 3 econ_status)) + (item 2 (item 7 econ_status)) ) ((item 2 (item 1 econ_status)) + (item 2 (item 2 econ_status)) + (item 2 (item 3 econ_status)) + (item 2 (item 7 econ_status)) + (item 2 (item 8 econ_status)) ) ) ask turtles with [age < 15 and age > 4 and small_area = word "" item j SA_ids][ set econ_stat "Student" ] ask turtles with [age >= 65 and small_area = word "" item j SA_ids][ set econ_stat "Retired" ] while[count turtles with [age >= 15 and adult? = FALSE and small_area = word "" item j SA_ids and sex = (item 1 (item 0 econ_status)) and econ_stat = 0] > 0][ ask one-of turtles with [age >= 15 and adult? = FALSE and small_area = word "" item j SA_ids and sex = (item 1 (item 0 econ_status)) and econ_stat = 0] [ ifelse count turtles with [age >= 15 and adult? = FALSE and small_area = word "" item j SA_ids and sex = (item 1 (item 0 econ_status)) and econ_stat = "Student"] < (item 1 (item 4 econ_status))[ set econ_stat "Student" ] [ ifelse count turtles with [age >= 15 and adult? = FALSE and small_area = word "" item j SA_ids and sex = (item 1 (item 0 econ_status)) and econ_stat = "Looking for first job"] < (item 1 (item 2 econ_status))[ set econ_stat "Looking for first job" ] [ let items-to-pick ["Work" "Looking for first job" "Unemployed" "Sick/disabled" "Work" ] let cum-pmf econ_F set cum-pmf map [ [??1] -> ??1 / den_econ_F ] cum-pmf ; to normalize set econ_stat item random-from-cum-pmf cum-pmf items-to-pick ] ] ] ] while[count turtles with [age >= 15 and adult? = FALSE and small_area = word "" item j SA_ids and sex = (item 2 (item 0 econ_status)) and econ_stat = 0] > 0][ ask one-of turtles with [age >= 15 and adult? = FALSE and small_area = word "" item j SA_ids and sex = (item 2 (item 0 econ_status)) and econ_stat = 0] [ ifelse count turtles with [age >= 15 and adult? = FALSE and small_area = word "" item j SA_ids and sex = (item 2 (item 0 econ_status)) and econ_stat = "Student"] < (item 2 (item 4 econ_status))[ set econ_stat "Student" ] [ ifelse count turtles with [age >= 15 and adult? = FALSE and small_area = word "" item j SA_ids and sex = (item 2 (item 0 econ_status)) and econ_stat = "Looking for first job"] < (item 2 (item 2 econ_status))[ set econ_stat "Looking for first job" ] [ let items-to-pick ["Work" "Looking for first job" "Unemployed" "Sick/disabled" "Work" ] let cum-pmf econ_M set cum-pmf map [ [??1] -> ??1 / den_econ_M ] cum-pmf ; to normalize set econ_stat item random-from-cum-pmf cum-pmf items-to-pick ] ] ] ] while[count turtles with [age >= 15 and adult? = TRUE and small_area = word "" item j SA_ids and sex = (item 1 (item 0 econ_status)) and econ_stat = 0] > 0][ ask one-of turtles with [age >= 15 and adult? = TRUE and small_area = word "" item j SA_ids and sex = (item 1 (item 0 econ_status)) and econ_stat = 0] [ ifelse count turtles with [age >= 15 and adult? = TRUE and small_area = word "" item j SA_ids and sex = (item 1 (item 0 econ_status)) and econ_stat = "Stay-at-home" and couple = TRUE] < (item 1 (item 5 econ_status))[ if couple = TRUE [ set econ_stat "Stay-at-home" ] ] [ let items-to-pick ["Work" "Looking for first job" "Unemployed" "Sick/disabled" "Work" ] let cum-pmf econ_F set cum-pmf map [ [??1] -> ??1 / den_econ_F ] cum-pmf ; to normalize set econ_stat item random-from-cum-pmf cum-pmf items-to-pick ] ] ] while[count turtles with [age >= 15 and adult? = TRUE and small_area = word "" item j SA_ids and sex = (item 2 (item 0 econ_status)) and econ_stat = 0] > 0][ ask one-of turtles with [age >= 15 and adult? = TRUE and small_area = word "" item j SA_ids and sex = (item 2 (item 0 econ_status)) and econ_stat = 0] [ ifelse count turtles with [age >= 15 and adult? = TRUE and small_area = word "" item j SA_ids and sex = (item 2 (item 0 econ_status)) and econ_stat = "Stay-at-home" and couple = TRUE] < (item 2 (item 5 econ_status))[ set econ_stat "Stay-at-home" ] [ let items-to-pick ["Work" "Looking for first job" "Unemployed" "Sick/disabled" "Work" ] let cum-pmf econ_M set cum-pmf map [ [??1] -> ??1 / den_econ_M ] cum-pmf ; to normalize set econ_stat item random-from-cum-pmf cum-pmf items-to-pick ] ] ] ask turtles with [age <= 4][ let child who let id familyid ifelse any? turtles with [familyid = id and adult? = TRUE and econ_stat = "Stay-at-home"][ ask turtle child[ ifelse random-float 1 < .4 [ set econ_stat "Student" ][set econ_stat "Infant"] ] ] [ask turtle child[ set econ_stat "Student" ] ] ] ask turtles with [econ_stat = "Stay-at-home"][ let parent who let id familyid if any? turtles with [familyid = id and age <= 12 and econ_stat = "Student"][ ask turtles with [familyid = id and age <= 12 and econ_stat = "Student"][ let school work-patch ask turtle parent[ set work-patch school ] ] ] ] ask turtles with [econ_stat = "Infant"][ let child who let id familyid ask turtles with [familyid = id and adult? = TRUE and econ_stat = "Stay-at-home"][ set infant child ] ] ask turtles with [econ_stat = 0][ ifelse age > 18 [ if sex = (item 1 (item 0 econ_status)) [ let items-to-pick ["Work" "Looking for first job" "Unemployed" "Sick/disabled" "Work" ] let cum-pmf econ_F set cum-pmf map [ [??1] -> ??1 / den_econ_F ] cum-pmf ; to normalize set econ_stat item random-from-cum-pmf cum-pmf items-to-pick ] if sex = (item 2 (item 0 econ_status)) [ let items-to-pick ["Work" "Looking for first job" "Unemployed" "Sick/disabled" "Work" ] let cum-pmf econ_M set cum-pmf map [ [??1] -> ??1 / den_econ_M ] cum-pmf ; to normalize set econ_stat item random-from-cum-pmf cum-pmf items-to-pick ] ] [ set econ_stat "Student"] ] ] set students turtles with [econ_stat = "Student"] set workers turtles with [econ_stat = "Work"] set non-workers turtles with [econ_stat = "Unemployed" or econ_stat = "Looking for first job" or econ_stat = "Retired" or econ_stat ="Sick/disabled"] set stay-at-home turtles with [econ_stat = "Stay-at-home"] set infants turtles with [econ_stat = "infants"] end ;;setting up social class/groups of workers to setup-soc_class foreach SA_labels[ [?1] -> let j position ?1 SA_labels let datasetsocialclass (word "C:/Users/D15127585/Google Drive/DIT/data/" town "/python/soc_stat" ?1 ".csv") ;;sets path of dataset set soc_class csv:from-file datasetsocialclass ;; setup of cumulative probability function for assigning social class set den_soc_F 0 set soc_F [] set den_soc_F (item 1 (item 1 soc_class)) + (item 1 (item 2 soc_class)) + (item 1 (item 3 soc_class)) + (item 1 (item 4 soc_class)) + (item 1 (item 5 soc_class)) +(item 1 (item 6 soc_class)) set soc_F (list (item 1 (item 1 soc_class)) ((item 1 (item 1 soc_class)) + (item 1 (item 2 soc_class))) ((item 1 (item 1 soc_class)) + (item 1 (item 2 soc_class)) + (item 1 (item 3 soc_class))) ((item 1 (item 1 soc_class)) + (item 1 (item 2 soc_class)) + (item 1 (item 3 soc_class)) + (item 1 (item 4 soc_class))) ((item 1 (item 1 soc_class)) + (item 1 (item 2 soc_class)) + (item 1 (item 3 soc_class)) + (item 1 (item 4 soc_class)) + (item 1 (item 5 soc_class))) ((item 1 (item 1 soc_class)) + (item 1 (item 2 soc_class)) + (item 1 (item 3 soc_class)) + (item 1 (item 4 soc_class)) + (item 1 (item 5 soc_class)) + (item 1 (item 6 soc_class))) ) set den_soc_M 0 set soc_M [] set den_soc_M (item 2 (item 1 soc_class)) + (item 2 (item 2 soc_class)) + (item 2 (item 3 soc_class)) + (item 2 (item 4 soc_class)) + (item 2 (item 5 soc_class)) + (item 2 (item 6 soc_class)) set soc_M (list (item 2 (item 1 soc_class)) ((item 2 (item 1 soc_class)) + (item 2 (item 2 soc_class))) ((item 2 (item 1 soc_class)) + (item 2 (item 2 soc_class)) + (item 2 (item 3 soc_class))) ((item 2 (item 1 soc_class)) + (item 2 (item 2 soc_class)) + (item 2 (item 3 soc_class)) + (item 2 (item 4 soc_class))) ((item 2 (item 1 soc_class)) + (item 2 (item 2 soc_class)) + (item 2 (item 3 soc_class)) + (item 2 (item 4 soc_class)) + (item 2 (item 5 soc_class))) ((item 2 (item 1 soc_class)) + (item 2 (item 2 soc_class)) + (item 2 (item 3 soc_class)) + (item 2 (item 4 soc_class)) + (item 2 (item 5 soc_class)) + (item 2 (item 6 soc_class))) ) while[count turtles with [econ_stat = "Work" and small_area = word "" item j SA_ids and sex = (item 1 (item 0 soc_class)) and job_type = 0] > 0][ ask one-of turtles with [econ_stat = "Work" and small_area = word "" item j SA_ids and sex = (item 1 (item 0 soc_class)) and job_type = 0] [ let items-to-pick ["Professional workers" "Managerial and Technical" "Non-Manual" "Skilled Manual" "Semi-Skilled" "Unskilled" ] let cum-pmf soc_F set cum-pmf map [ [??1] -> ??1 / den_soc_F ] cum-pmf ; to normalize set job_type item random-from-cum-pmf cum-pmf items-to-pick ] ] while[count turtles with [econ_stat = "Work" and small_area = word "" item j SA_ids and sex = (item 2 (item 0 soc_class)) and job_type = 0] > 0][ ask one-of turtles with [econ_stat = "Work" and small_area = word "" item j SA_ids and sex = (item 2 (item 0 soc_class)) and job_type = 0] [ let items-to-pick ["Professional workers" "Managerial and Technical" "Non-Manual" "Skilled Manual" "Semi-Skilled" "Unskilled" ] let cum-pmf soc_M set cum-pmf map [ [??1] -> ??1 / den_soc_M ] cum-pmf ; to normalize set job_type item random-from-cum-pmf cum-pmf items-to-pick ] ] ] ask turtles with [familyid = who][ ifelse job_type != 0 [ if job_type = "Professional workers" [ ask home-patch [set family_soc_class "Professional" ] ask turtles with [familyid = [familyid] of myself] [set soc_cl "Professional"] ] if job_type = "Managerial and Technical" [ ask home-patch [set family_soc_class "Managerial" ] ask turtles with [familyid = [familyid] of myself] [set soc_cl "Managerial"] ] if job_type = "Non-Manual" [ ask home-patch [set family_soc_class "Non-Manual" ] ask turtles with [familyid = [familyid] of myself] [set soc_cl "Non-Manual"] ] if job_type = "Semi-Skilled" or job_type = "Skilled Manual" [ ask home-patch [set family_soc_class "Semi/skilled" ] ask turtles with [familyid = [familyid] of myself][set soc_cl "Semi/skilled"] ] if job_type = "Unskilled"[ ask patch-here [set family_soc_class "Other"] ask turtles with [familyid = [familyid] of myself][set soc_cl "Other"] ] ] [ ask turtles with [adult? != FALSE and familyid = [who] of myself][ if job_type != 0 [ if job_type = "Professional workers" [ ask home-patch [set family_soc_class "Professional" ] ask turtles with [familyid = [familyid] of myself] [set soc_cl "Professional"] ] if job_type = "Managerial and Technical" [ ask home-patch [set family_soc_class "Managerial" ] ask turtles with [familyid = [familyid] of myself] [set soc_cl "Managerial"] ] if job_type = "Non-Manual" [ ask home-patch [set family_soc_class "Non-Manual" ] ask turtles with [familyid = [familyid] of myself] [set soc_cl "Non-Manual"] ] if job_type = "Semi-Skilled" or job_type = "Skilled Manual" [ ask home-patch [set family_soc_class "Semi/skilled" ] ask turtles with [familyid = [familyid] of myself][set soc_cl "Semi/skilled"] ] if job_type = "Unskilled"[ ask patch-here [set family_soc_class "Other"] ask turtles with [familyid = [familyid] of myself][set soc_cl "Other"] ] ] ] ] ] ask turtles with [familyid = who and soc_cl = 0 ][ if econ_stat = "Retired" [ ask patch-here [set family_soc_class "Retired" ] ask turtles with [familyid = [familyid] of myself][set soc_cl "Retired"] ] if econ_stat = "Looking for first job" or econ_stat = "Unemployed" or econ_stat = "Sick/disabled" or econ_stat = "Stay-at-home" [ ask patch-here [set family_soc_class "Other" ] ask turtles with [familyid = [familyid] of myself][set soc_cl "Other"] ] ] end ;;creating home and work for agents to setup-work ask students [ if age < 4 [ set work-patch min-one-of schools with [use = "preschool"] [distance myself] set to-work? TRUE ] if age <= 12 and age >= 4 [ set work-patch min-one-of schools with [use = "primary school" ] [distance myself] set to-work? TRUE ] ; if econ_stat = "Student" and age <= 12 and age >= 4 and sex = "Female"[ ; set work-patch one-of patches with [use = "primary school" or use = "G primary school"] ; set to-work? TRUE ;] if age > 12 [ set work-patch min-one-of schools with [use = "secondary school"] [distance myself] set to-work? TRUE ] ] ask workers[ set work-patch one-of work set to-work? TRUE ] end to get-sick ifelse SEIR [ if days_exposed = 0 and exposed? = FALSE and sick? = FALSE[ set days_exposed random-normal 10 .5 ;;normal distribution of days exposed should be about 10 days set days_exposed round (days_exposed * 12) ;;gets number of ticks exposed set color orange set exposed? TRUE set tick_exposed ticks set ticks_exposed 1 ;;testing variables ] ] [ if immune? = FALSE [ set sick? TRUE set color red ] ] end to get-healthy set sick? FALSE ifelse SIR [ set color white set immune? TRUE ] [set color yellow] end to infect_1 ask turtles with [sick? = TRUE and immune? = FALSE][ set i 0 while [i < length contacts][ if random-float 1 < (infectivity * item i contacts)[ ask turtle i [ if random-float 1 > immunity [ get-sick ] ] ] set i i + 1 ] ] ask turtles with [exposed? = TRUE][ ifelse days_exposed + tick_exposed = ticks[ set sick? TRUE set color red set days_sick round((random-normal 8 .5) * 12) set ticks_when_sick ticks ;;testing variables set ticks_sick 1 ;;testing variables ] [set ticks_exposed ticks_exposed + 1] ;;testing variables ] end to infect ask turtles with [sick? = TRUE and immune? = FALSE][ let cont_t table:to-list my-contacts-table let len length cont_t set i 0 while [i < len][ if random-float 1 < (infectivity * item 1 item i cont_t)[ ask turtle item 0 item i cont_t [ if random-float 1 > immunity [ get-sick ] ] ] set i i + 1 ] ] ask turtles with [exposed? = TRUE][ ifelse days_exposed + tick_exposed = ticks[ set sick? TRUE set color red set days_sick round((random-normal 8 .5) * 12) set ticks_when_sick ticks ;;testing variables set ticks_sick 1 ;;testing variables ] [set ticks_exposed ticks_exposed + 1] ;;testing variables ] end to reset-contacts ; ask turtles [ ; set contacts [] ; set cont_table 0 ;] ; file-open "Output_Schull_contacts.csv" ;ask turtles with [sick? = TRUE][file-print contacts ] ;file-close let contacts_list_everyone n-values NUM_HUMANS [0] ask turtles [ ;set contacts contacts_list_everyone table:clear my-contacts-table ] end to recover ask turtles with [sick? = TRUE][ ifelse days_sick + days_exposed + tick_exposed = ticks [ get-healthy ] [set ticks_sick ticks_sick + 1] ;;testing variables ] end to update-global-variables if count turtles > 0 [ set infected count turtles with [ sick? ] set susceptible count turtles with [not sick? and not immune? and not exposed?] set immune count turtles with [immune?] set exposed count turtles with [exposed? and not sick? and not immune?] set %infected (infected / NUM_HUMANS) * 100 set %susceptible (susceptible / NUM_HUMANS) * 100 set %immune (immune / NUM_HUMANS * 100) set %exposed (exposed / NUM_HUMANS * 100) set seconds timer ] ; ifelse time = day-length [set time 0][set time time + 1] end to who-sick set sick_turts 0 set sick_turts_age 0 set sick_turts_econ 0 ask turtles with [sick? and days_exposed + tick_exposed = ticks][ let n [who] of self let a [age] of self let s [econ_stat] of self ;let ns (list n a s) set sick_turts n set sick_turts_age a set sick_turts_econ s ] end to update-contacts if sick? or immune? [ let turts-here ([who] of other turtles-here) set i 0 while [i < length turts-here][ ifelse table:has-key? my-contacts-table item i turts-here [ ;increase the number of contacts with person by 1 let cont_count table:get my-contacts-table item i turts-here table:put my-contacts-table item i turts-here (cont_count + 1) ] [ ; new contact table:put my-contacts-table item i turts-here 1 ] set i i + 1 ] ] ; if sick? = TRUE[ ; show turts-here ; show my-contacts-table ;] ; foreach turts-here[ [turt] -> ;set contacts lput turt contacts ;] ;set i 0 ; while [i < length turts-here][ ;set contacts replace-item (item i turts-here) contacts (item (item i turts-here) contacts + 1) ;(item (position turts-here i) contacts + 1) ;set i i + 1 ;] ;create-links-to other turtles-here ;ask links [hide-link] end to update-numcontacts ask turtles [ set i table:length my-contacts-table set num_contacts lput i num_contacts ] end to find_contacts set count_list [] ask turtles with [sick? or immune?] [ set avg_contacts mean num_contacts set count_list lput avg_contacts count_list ] if count turtles with [sick? or immune?] > 0 [ set tot_contacts lput mean count_list tot_contacts ] set mean_tot_contacts mean tot_contacts end to move if ticks > 3[ ask workers [ ifelse time < 4 or time > 10 [ if patch-here != home-patch[ while [patch-here != home-patch] [ face home-patch forward 1 update-contacts ] ] ] [ ifelse day = 6 or day = 7 [ ifelse sick? [ ifelse random-float 1 < 0.25 [ set dest-patch one-of community while [patch-here != dest-patch] [ face dest-patch forward 1 update-contacts ]] [update-contacts] ] [ ifelse random-float 1 < 0.5 [ set dest-patch one-of community while [patch-here != dest-patch] [ face dest-patch forward 1 update-contacts ] ] [update-contacts] ] ] [ ifelse sick? [ ifelse random-float 1 < .3 [ while [patch-here != work-patch] [ face work-patch forward 1 update-contacts ] ] [update-contacts] ] [ifelse time = 4 [ while [patch-here != work-patch] [ face work-patch forward 1 update-contacts ] ][ifelse time = 10 [while [patch-here != home-patch][ face home-patch forward 1 update-contacts ]][update-contacts]] ] ] ] ] ;;student movement ask students [ ifelse time < 4 or time > 10 [ if patch-here != home-patch[ while [patch-here != home-patch] [ face home-patch forward 1 update-contacts ] ] ] [ ifelse day = 6 or day = 7 or ((start_week + week) > 26 and (start_week + week) < 36) [ ifelse sick? [ ifelse random-float 1 < 0.25 [ set dest-patch one-of community while [patch-here != dest-patch] [ face dest-patch forward 1 update-contacts ]] [update-contacts] ] [ ifelse random-float 1 < 0.5 [ set dest-patch one-of community while [patch-here != dest-patch] [ face dest-patch forward 1 update-contacts ] ] [update-contacts] ] if patch-here = dest-patch [ ifelse random-float 1 < 0.33 [ set dest-patch one-of community while [patch-here != dest-patch] [ face dest-patch forward 1 update-contacts ] ] [if random-float 1 < 0.33 [ while [patch-here != home-patch] [ face home-patch forward 1 update-contacts ] ] ] ] ] [ ifelse time = 4 [ ifelse sick? [ ifelse random-float 1 < home_sick [ while [patch-here != work-patch] [ face work-patch forward 1 update-contacts ] ] [update-contacts] ][ while [patch-here != work-patch] [ face work-patch forward 1 update-contacts ] ]][ifelse time = 8 [while [patch-here != home-patch][ face home-patch forward 1 update-contacts ]][update-contacts]] ] ] ] ;;movement for unemployed agents ask non-workers[ ; if ticks > 3[ ifelse not sick? or random-float 1 < .25[ if patch-here = home-patch and time > 3 and time < 11 [ ifelse random-float 1 < 0.5 [ set dest-patch one-of community while [patch-here != dest-patch] [ face dest-patch forward 1 update-contacts ] ][update-contacts] ] if patch-here = dest-patch and time < 10 [ ifelse random-float 1 < 0.33 [ set dest-patch one-of community while [patch-here != dest-patch] [ face dest-patch forward 1 update-contacts ] ] [ ifelse random-float 1 < 0.33 [ while [patch-here != home-patch] [ face home-patch forward 1 update-contacts ] ] [update-contacts] ] ] if patch-here != home-patch and time = 10 [ while [patch-here != home-patch] [ face home-patch forward 1 update-contacts ] ] ][update-contacts] ;] ] ;;stay at home parent movements ask stay-at-home[ if work-patch != 0[ ;if ticks > 3[ ifelse not sick? or random-float 1 < .95 [ if time = 4 and day != 6 and day != 7[ while [patch-here != work-patch] [ face work-patch forward 1 update-contacts if infant != FALSE[ ask turtle infant[ if econ_stat = "Infant" [ face [work-patch] of myself forward 1 update-contacts ] ] ] ] while [patch-here != home-patch] [ face home-patch forward 1 update-contacts if infant != FALSE[ ask turtle infant[ face home-patch forward 1 update-contacts ] ] ] ] ][update-contacts] ifelse not sick? or random-float 1 < .95 [ if time = 7 and day != 6 and day != 7[ while [patch-here != work-patch] [ face work-patch forward 1 update-contacts if infant != FALSE[ ask turtle infant[ if econ_stat = "Infant"[ face [work-patch] of myself forward 1 update-contacts ] ] ] ] while [patch-here != home-patch] [ face home-patch forward 1 update-contacts if infant != FALSE[ ask turtle infant[ if econ_stat = "Infant"[ face home-patch forward 1 update-contacts ] ] ] ] ] ][update-contacts] ifelse not sick? or random-float 1 < .5 [ if time > 4 and time < 7 [ if random-float 1 < 0.33 [ set dest-patch one-of community while [patch-here != dest-patch] [ face dest-patch forward 1 update-contacts if infant != FALSE[ ask turtle infant[ face [dest-patch] of myself forward 1 update-contacts ] ]] ] if random-float 1 < 0.33 [ while [patch-here != home-patch] [ face home-patch forward 1 update-contacts if infant != FALSE[ ask turtle infant[ if econ_stat = "Infant" [ face home-patch forward 1 update-contacts ] ] ] ] ] ] if patch-here != home-patch and time = 8 [ while [patch-here != home-patch] [ face home-patch forward 1 update-contacts if infant != FALSE[ ask turtle infant[ if econ_stat = "Infant" [ face home-patch forward 1 update-contacts ] ] ] ] ] ][update-contacts] ;] ] if work-patch = 0[ ;if ticks > 3[ ifelse not sick? or random-float 1 < .5[ if patch-here = home-patch and time > 3 and time < 8 [ if random-float 1 < 0.5 [ set dest-patch one-of community while [patch-here != dest-patch] [ face dest-patch forward 1 update-contacts if infant != FALSE[ ask turtle infant[ face [dest-patch] of myself forward 1 update-contacts ] ] ] ] ] if patch-here != home-patch and time > 3 and time < 8 [ if random-float 1 < 0.33 [ set dest-patch one-of community while [patch-here != dest-patch] [ face dest-patch forward 1 update-contacts if infant != FALSE[ ask turtle infant[ face [dest-patch] of myself forward 1 update-contacts ] ] ] ] if random-float 1 < 0.33 [ while [patch-here != home-patch] [ face home-patch forward 1 update-contacts if infant != FALSE[ ask turtle infant[ if econ_stat = "Infant" [ face home-patch forward 1 update-contacts ] ] ] ] ] ] if patch-here != home-patch and time = 8 [ while [patch-here != home-patch] [ face home-patch forward 1 update-contacts if infant != FALSE[ ask turtle infant[ if econ_stat = "Infant" [ face home-patch forward 1 update-contacts ] ] ] ] ] ] [update-contacts] ] ] ;] ] end to clock set time ticks mod 12 if time = 0 [ set day day + 1 ] if day = 8 [ set week week + 1 if week = 52 [ set week 0 ] set day 1 ] end to test_within_agent_model file-open "Output_Schull_withinagentmodel_3.csv" file-print "Agent-id, tick_exposed, ticks_exposed, days_exposed, days_sick, ticks_when_sick, ticks_sick" ask turtles with [immune? = TRUE][file-print (word who "," tick_exposed "," ticks_exposed "," days_exposed "," days_sick "," ticks_when_sick "," ticks_sick ",")] file-close end to profile profiler:start ; setup ;setup-loadworld repeat 300[go] profiler:stop print profiler:report profiler:reset end to find-dissimlarity set N_p count patches with [use = "home" and count turtles-here > 0 and family_soc_class = "Professional"] set N_m count patches with [use = "home" and count turtles-here > 0 and family_soc_class = "Non-Manual"] set N_ma count patches with [use = "home" and count turtles-here > 0 and family_soc_class = "Managerial"] set N_s count patches with [use = "home" and count turtles-here > 0 and family_soc_class = "Semi/skilled"] set N_r count patches with [use = "home" and count turtles-here > 0 and family_soc_class = "Retired"] set N_o count patches with [use = "home" and count turtles-here > 0 and family_soc_class = "Other"] set T N_p + N_m + N_s + N_r + N_o set diss_list_p [] set diss_list_ma [] set diss_list_m [] set diss_list_s [] set diss_list_r [] set diss_list_o [] ask center_patches[ set N_pi count patches in-radius neighbor_radius with [use = "home" and count turtles-here > 0 and family_soc_class = "Professional" ] set N_mi count patches in-radius neighbor_radius with [use = "home" and count turtles-here > 0 and family_soc_class = "Non-Manual" ] set N_mai count patches in-radius neighbor_radius with [use = "home" and count turtles-here > 0 and family_soc_class = "Managerial" ] set N_si count patches in-radius neighbor_radius with [use = "home" and count turtles-here > 0 and family_soc_class = "Semi/skilled" ] set N_ri count patches in-radius neighbor_radius with [use = "home" and count turtles-here > 0 and family_soc_class = "Retired" ] set N_oi count patches in-radius neighbor_radius with [use = "home" and count turtles-here > 0 and family_soc_class = "Other" ] set ti count patches in-radius neighbor_radius with [use = "home" and count turtles-here > 0 ] if ti > 0 [ if N_pi > 0 [ set diss_sim_patch_p (ti * abs ((N_pi / ti) - (N_p / T) ))/(2 * (N_p / T) * (T) * ( 1 - (N_p / T))) if diss_sim_patch_p != 0 [set diss_list_p lput diss_sim_patch_p diss_list_p] ] if N_mai > 0 [ set diss_sim_patch_ma (ti * abs ((N_mai / ti) - (N_ma / T) ))/(2 * (N_ma / T) * (T) * ( 1 - (N_ma / T))) if diss_sim_patch_ma != 0 [set diss_list_ma lput diss_sim_patch_ma diss_list_ma] ] if N_mi > 0 [ set diss_sim_patch_m (ti * abs ((N_mi / ti) - (N_m / T) ))/(2 * (N_m / T) * (T) * ( 1 - (N_m / T))) if diss_sim_patch_m != 0 [set diss_list_m lput diss_sim_patch_m diss_list_m] ] if N_si > 0 [ set diss_sim_patch_s (ti * abs ((N_si / ti) - (N_s / T) ))/(2 * (N_s / T) * (T) * ( 1 - (N_s / T))) if diss_sim_patch_s != 0 [set diss_list_s lput diss_sim_patch_s diss_list_s] ] if N_ri > 0 [ set diss_sim_patch_r (ti * abs ((N_ri / ti) - (N_r / T) ))/(2 * (N_r / T) * (T) * ( 1 - (N_r / T))) if diss_sim_patch_r != 0 [set diss_list_r lput diss_sim_patch_r diss_list_r] ] if N_oi > 0 [ set diss_sim_patch_o (ti * abs ((N_oi / ti) - (N_o / T) ))/(2 * (N_o / T) * (T) * ( 1 - (N_o / T))) if diss_sim_patch_o != 0 [set diss_list_o lput diss_sim_patch_o diss_list_o] ] ] ] set diss_sum_p sum diss_list_p set diss_sum_m sum diss_list_m set diss_sum_ma sum diss_list_ma set diss_sum_s sum diss_list_s set diss_sum_r sum diss_list_r set diss_sum_o sum diss_list_o end to find-similar ask turtles[ set count_similar_sc count patches in-radius neighbor_radius with [use = "home" and family_soc_class = [soc_cl] of myself] ; set count_similar_hh count patches in-radius neighbor_radius with [use = "home" and house_type = [hh_type] of myself] ; set count_similar_es count turtles in-radius neighbor_radius with [econ_stat = [econ_stat] of myself] set count_neighbors count patches in-radius neighbor_radius with [use = "home" and house_type != 0] ; set count_neighbors_turts count turtles in-radius neighbor_radius ;set count_similar_child count patches in-radius neighbor_radius with [use = "home" and child_age = [child_type] of myself] ifelse count_neighbors != 0 [set happiness (count_similar_sc / count_neighbors) ] [set happiness tolerance] ] end to move-house ask turtles with [familyid = who][ ifelse happiness >= tolerance [ ] [ let current_home patch-here let sc [soc_cl] of self let fam [who] of self let houset [hh_type] of self let hp [happiness] of self let turt [who] of self ;let es [econ_stat] of self ;let child [child_type] of self set possible_home (patches with [use = "home" and family = FALSE and sm_area = [small_area] of myself and not any? turtles-here and (count patches in-radius neighbor_radius with [use = "home" and house_type != 0]) != 0 ] ) set new_hap [] ask possible_home [ let xcord [pxcor] of self let ycord [pycor] of self let hap_sc (count patches in-radius neighbor_radius with [use = "home" and family_soc_class = sc]) / (count patches in-radius neighbor_radius with [use = "home" and house_type != 0]) ; let hap_hh (count patches in-radius neighbor_radius with [use = "home" and house_type = houset]) / (count patches in-radius neighbor_radius with [use = "home" and house_type != 0]) ; let hap_es (count turtles in-radius neighbor_radius with [econ_stat = es]) / (count turtles in-radius neighbor_radius) ;let hap_child (count patches in-radius neighbor_radius with [use = "home" and child_age = child]) / (count patches in-radius neighbor_radius with [use = "home" and house_type != 0]) let hap (hap_sc ) set cord (list xcord ycord hap) ] foreach (sort possible_home) [[q] -> let hap_home [cord] of q set new_hap lput hap_home new_hap] let j length new_hap if j > 0 [ set i 0 set hh [] while [i < j] [ set hh lput (item 2 item i new_hap) hh set i i + 1 ] let m max hh if m > hp [ let p position m hh let new_home patch (item 0 item p new_hap) (item 1 item p new_hap) move-to new_home set home-patch patch-here set small_area [sm_area] of patch-here ask turtles with [familyid = fam] [ move-to [new_home] of myself set home-patch patch-here set small_area [sm_area] of patch-here ] ask new_home [ set family TRUE set house_type houset set family_soc_class sc ] ask current_home [ set family FALSE set house_type 0 set family_soc_class 0 ] set count_moved count_moved + 1 ] ] ] ] end to set_centers set centers [] let x_s (range -180 (180 + neighbor_radius) (neighbor_radius * 2)) let y_s x_s set i 0 while [i < length (x_s)][ set z 0 while [z < length (y_s)][ let patch_center patch item i x_s item z y_s ask patch_center [ let count_sm_n count patches in-radius neighbor_radius with [sm_area != 0] if count_sm_n > 0 [ set centers lput patch_center centers ] ] set z z + 1 ] set i i + 1 ] set center_patches patches with [member? self centers] end to find_neighbors ask center_patches [ let px [pxcor] of self let py [pycor] of self set neighbor_cpatch center_patches with [pxcor <= (px + 11) and pxcor >= (px - 11) and pycor <= (py + 11) and pycor >= (py - 11)] set ncp count neighbor_cpatch ] end @#$#@#$#@ GRAPHICS-WINDOW 261 10 862 620 -1 -1 0.3 1 10 1 1 1 0 0 0 1 -300 300 -300 300 0 0 1 ticks 30.0 BUTTON 26 29 89 62 NIL setup NIL 1 T OBSERVER NIL NIL NIL NIL 1 SWITCH 25 125 128 158 SIR SIR 0 1 -1000 BUTTON 95 32 158 65 NIL go T 1 T OBSERVER NIL NIL NIL NIL 1 PLOT 26 220 226 370 plot 1 NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "default" 1.0 0 -1184463 true "" "plot %susceptible" "pen-1" 1.0 0 -2674135 true "" "plot %infected" "pen-2" 1.0 0 -16777216 true "" "plot %immune" "pen-3" 1.0 0 -955883 true "" "plot %exposed" INPUTBOX 30 405 127 465 num_infected 1.0 1 0 Number MONITOR 37 488 116 541 NIL %infected 17 1 13 INPUTBOX 31 607 120 667 year 2012.0 1 0 Number SWITCH 31 175 141 208 vaccinations vaccinations 0 1 -1000 SWITCH 144 125 247 158 SEIR SEIR 0 1 -1000 INPUTBOX 143 604 224 664 infectivity 0.001 1 0 Number INPUTBOX 133 532 243 592 vaccine_immunity 0.995 1 0 Number INPUTBOX 151 380 237 440 start_week 15.0 1 0 Number INPUTBOX 141 459 232 519 home_sick 0.35 1 0 Number BUTTON 163 174 229 207 NIL profile\n NIL 1 T OBSERVER NIL NIL NIL NIL 1 CHOOSER 62 70 200 115 town town "Schull" "Tramore" "Kinsale" 0 BUTTON 42 690 111 723 NIL cluster T 1 T OBSERVER NIL NIL NIL NIL 1 INPUTBOX 143 737 220 797 tolerance 0.5 1 0 Number INPUTBOX 22 730 111 790 neighbor_radius 5.0 1 0 Number BUTTON 140 692 229 725 NIL reset-ticks\n NIL 1 T OBSERVER NIL NIL NIL NIL 1 INPUTBOX 10 815 243 875 path C:/Users/D15127585/Google Drive/DIT/Netlogo/Schull/burn_in model/ 1 0 String @#$#@#$#@ ## WHAT IS IT? The model simualtes the spread of an infectious disease in an Irish town. ## HOW IT WORKS The disease component of the model is based off a SIR or SEIR component model. Depending on the type of model selected (SIR or SEIR) agents are either in the susceptible, infected or recovered category or the susceptible, exposed, infected or recovered category. If a susceptible agent comes into contact with an infected agent the susceptible agent has a chance, determined by the infectivity, of becoming exposed or infected. If an agent becomes exposed they have a time period where they are exposed to the disease but not yet infectious. Once infected the agent has a set period of time where they will remain infectious before moving to the recovered stage. Agent movement in the model is in a straight line. Agents move between their current location and desired destination. A set of rules determine when an agent will move. During week days agents typically move between home and work or home and school and on weekend days agents will move freely through the community. If two agents are on the same patch they are considered in contacct with each other. ## HOW TO USE IT First make sure the path variable is set to the location of the town files. Select a town to run the model on and use the setup button to setup the model. Once the world is imported select the user can decide if they want to cluster by socioeconomic status. If they do they can press the cluster button and once the clustering has completed press the reset-ticks button. To run the infectious disease model the user should make sure all necessary parameters are set and then press go. The model will run until no agents are exposed or infected. load-world -- loads a precreated world (before burnin) Town -- selection of which town to model SIR -- is the model an SIR type model SEIR -- is teh model an SEIR type model (SIR must also be selected) vaccinations -- are vaccinations used in the model num_infected -- the number of initially infected agents start_week -- the week of the year the outbreak starts in. (week can affect movement patterns as students do not go to school in the summer) home_sick -- the percent chance an agent will go to work if sick vaccine_immunity -- the percent chance the vaccination will work year -- the year the outbreak takes place infectivity -- the percent chance a susceptible agent will be infected after each contact with an infected agent cluster -- starts the burn in model that allows agents to move home location based on the percent of similar households in a given radius with the same socioeconomic status neighbor_radius -- the radius agents will look for similar socioeconomic neighbors tolerance -- what percentage of neighbors agents would like to have the same socioeconomic status reset-ticks -- sets ticks to 0 (used after clustering) path -- location of the files containing the exported worlds for each town. ## THINGS TO TRY Run the model with and without socioeconomic clustering to see differences in results. Change the parameters of the disease such as infectivity or home_sick to see how these changes can influence the outbreak. ## RELATED MODELS epiDEM Basic model is an example model with SIR model dynamics ## CREDITS AND REFERENCES Model described in greater detail in the following paper: https://pdfs.semanticscholar.org/8d7c/cbfddf44741e2bea11ec22f9cc8245847c83.pdf @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 airplane true 0 Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 arrow true 0 Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box false 0 Polygon -7500403 true true 150 285 285 225 285 75 150 135 Polygon -7500403 true true 150 135 15 75 150 15 285 75 Polygon -7500403 true true 15 75 15 225 150 285 150 135 Line -16777216 false 150 285 150 135 Line -16777216 false 150 135 15 75 Line -16777216 false 150 135 285 75 bug true 0 Circle -7500403 true true 96 182 108 Circle -7500403 true true 110 127 80 Circle -7500403 true true 110 75 80 Line -7500403 true 150 100 80 30 Line -7500403 true 150 100 220 30 butterfly true 0 Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 Circle -16777216 true false 135 90 30 Line -16777216 false 150 105 195 60 Line -16777216 false 150 105 105 60 car false 0 Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 Circle -16777216 true false 180 180 90 Circle -16777216 true false 30 180 90 Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 Circle -7500403 true true 47 195 58 Circle -7500403 true true 195 195 58 circle false 0 Circle -7500403 true true 0 0 300 circle 2 false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 cow false 0 Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 Polygon -7500403 true true 73 210 86 251 62 249 48 208 Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 cylinder false 0 Circle -7500403 true true 0 0 300 dot false 0 Circle -7500403 true true 90 90 120 face happy false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 face neutral false 0 Circle -7500403 true true 8 7 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Rectangle -16777216 true false 60 195 240 225 face sad false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 fish false 0 Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 Circle -16777216 true false 215 106 30 flag false 0 Rectangle -7500403 true true 60 15 75 300 Polygon -7500403 true true 90 150 270 90 90 30 Line -7500403 true 75 135 90 135 Line -7500403 true 75 45 90 45 flower false 0 Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 Circle -7500403 true true 85 132 38 Circle -7500403 true true 130 147 38 Circle -7500403 true true 192 85 38 Circle -7500403 true true 85 40 38 Circle -7500403 true true 177 40 38 Circle -7500403 true true 177 132 38 Circle -7500403 true true 70 85 38 Circle -7500403 true true 130 25 38 Circle -7500403 true true 96 51 108 Circle -16777216 true false 113 68 74 Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 house false 0 Rectangle -7500403 true true 45 120 255 285 Rectangle -16777216 true false 120 210 180 285 Polygon -7500403 true true 15 120 150 15 285 120 Line -16777216 false 30 120 270 120 leaf false 0 Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 line true 0 Line -7500403 true 150 0 150 300 line half true 0 Line -7500403 true 150 0 150 150 pentagon false 0 Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 person false 0 Circle -7500403 true true 110 5 80 Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 Rectangle -7500403 true true 127 79 172 94 Polygon -7500403 true true 195 90 240 150 225 180 165 105 Polygon -7500403 true true 105 90 60 150 75 180 135 105 plant false 0 Rectangle -7500403 true true 135 90 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 sheep false 15 Circle -1 true true 203 65 88 Circle -1 true true 70 65 162 Circle -1 true true 150 105 120 Polygon -7500403 true false 218 120 240 165 255 165 278 120 Circle -7500403 true false 214 72 67 Rectangle -1 true true 164 223 179 298 Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 Circle -1 true true 3 83 150 Rectangle -1 true true 65 221 80 296 Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 Polygon -7500403 true false 276 85 285 105 302 99 294 83 Polygon -7500403 true false 219 85 210 105 193 99 201 83 square false 0 Rectangle -7500403 true true 30 30 270 270 square 2 false 0 Rectangle -7500403 true true 30 30 270 270 Rectangle -16777216 true false 60 60 240 240 star false 0 Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 target false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 Circle -7500403 true true 60 60 180 Circle -16777216 true false 90 90 120 Circle -7500403 true true 120 120 60 tree false 0 Circle -7500403 true true 118 3 94 Rectangle -6459832 true false 120 195 180 300 Circle -7500403 true true 65 21 108 Circle -7500403 true true 116 41 127 Circle -7500403 true true 45 90 120 Circle -7500403 true true 104 74 152 triangle false 0 Polygon -7500403 true true 150 30 15 255 285 255 triangle 2 false 0 Polygon -7500403 true true 150 30 15 255 285 255 Polygon -16777216 true false 151 99 225 223 75 224 truck false 0 Rectangle -7500403 true true 4 45 195 187 Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 Rectangle -1 true false 195 60 195 105 Polygon -16777216 true false 238 112 252 141 219 141 218 112 Circle -16777216 true false 234 174 42 Rectangle -7500403 true true 181 185 214 194 Circle -16777216 true false 144 174 42 Circle -16777216 true false 24 174 42 Circle -7500403 false true 24 174 42 Circle -7500403 false true 144 174 42 Circle -7500403 false true 234 174 42 turtle true 0 Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 wheel false 0 Circle -7500403 true true 3 3 294 Circle -16777216 true false 30 30 240 Line -7500403 true 150 285 150 15 Line -7500403 true 15 150 285 150 Circle -7500403 true true 120 120 60 Line -7500403 true 216 40 79 269 Line -7500403 true 40 84 269 221 Line -7500403 true 40 216 269 79 Line -7500403 true 84 40 221 269 wolf false 0 Polygon -16777216 true false 253 133 245 131 245 133 Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 x false 0 Polygon -7500403 true true 270 75 225 30 30 225 75 270 Polygon -7500403 true true 30 75 75 30 270 225 225 270 @#$#@#$#@ NetLogo 6.0.2 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ setup go %immune > 0 and %infected = 0 %susceptible %infected %immune setup go immune > 0 and infected = 0 susceptible infected immune setup go immune > 0 and infected = 0 %susceptible %infected %immune mean_tot_contacts seconds setup go seconds_to_run setup go immune > 0 and infected = 0 and exposed = 0 susceptible infected immune exposed mean_tot_contacts seconds setup go immune > 0 and infected = 0 and exposed = 0 susceptible infected immune exposed mean_tot_contacts seconds setup cluster go susceptible exposed infected immune mean_tot_contacts setup go immune = 1 exposed setup cluster reset-ticks go susceptible exposed infected immune mean_tot_contacts sick_turts sick_turts_age sick_turts_econ @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@ 0 @#$#@#$#@