Infective Community Network
Model was written in NetLogo 5.0.1
•
Viewed 1022 times
•
Downloaded 80 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
;; GLOBAL BREEDS breed [house_centres house_centre] ;; Breed for households breed [people person] ;; Breed for the people in the simulation breed [school_centres school_centre] ;; Breed for the schools in the simulation ;; LINK BREEDS directed-link-breed [familylinks familylink] ;; Links created between family members directed-link-breed [schoollinks schoollink] ;; Links created between students and schools undirected-link-breed [friendlinks friendlink] ;; Links created between friends directed-link-breed [infectorlinks infectorlink] ;; GLOBAL VARIABLES globals[ world_halfwidth ;; World variable to store world width for calculations simulation_state ;; Used to record simulation status on interface tab temp_spouse_stop_command ;; World variable used to store a stop variable if required by formulas temp_spouse_friends_agentset ;; World variable used to transmit agentsets between agents percentage_susceptible ;; Global percentage susceptible percentage_infected ;; Global percentage infected percentage_immune ;; Global percentage immune percentage_ever_infected ;; Global percentage ever infected temp_infector_who ;; Transitory variable to transmit who of infectors temp_school_who temp_ptype_sou temp_ptype_rec size_modifier ] ;; PERSON VARIABLES people-own[ ptype ;; What type of person (1 = adult 2 = student) friends_wanted ;; How many friends person would like spouse ;; Are there two adults in family spouse_friends_done ;; Stores if friends already transferred household_who ;; ID of household that made them exclude_friend_set ;; Carrier variable used to exclude friends in the linking stage person_infective_status ;; 1 = Susceptible 2 = About to be infected 3 = Infected 4 = Recovered 5 = Immune quarantined ;; 0 = none 1 = off school infective_recovery_time ;; Days remaining infective ever_infected ;; Whether person ever infected infected_by_who ;; If infected, records the who of the infector infected_by_school ;; Records the who of the school if infected via this route people_infected ;; Number of people infected ] ;; SCHOOL VARIABLES school_centres-own[ school_percentage_infected ;; Not in use school_infective_risk ;; Not in use ] ;; HOUSEHOLD VARIABLES house_centres-own[ family_percentage_infected ;; Not in use family_infective_risk] ;; Not in use ;; LINK VARIABLES familylinks-own [ link_type] schoollinks-own [ link_type] friendlinks-own [ link_type] infectorlinks-own [ age initialcolor] to reset-world clear-all-plots ask people [set ever_infected 0 set person_infective_status 1 set quarantined 0 set infected_by_who 0 set infective_recovery_time 0 set size 0.5 * size_modifier] ask infectorlinks [die] ask people with [ptype = 1] [set color magenta] ask people with [ptype = 2] [set color violet] ask school_centres [set size 3 * size_modifier set color blue] vaccinate-people infect-initial end ;; ======================================================================== ;; SETUP PROCEDURE ;; Sets up world, households, schools, friends, vaccinations and infections ;; ======================================================================== to setup clear-all reset-ticks set simulation_state "SETTING UP" set world_halfwidth world_width / 2 let temp_patch_size (500 / world_width) resize-world (- world_halfwidth) world_halfwidth (- world_halfwidth) world_halfwidth set-patch-size temp_patch_size set size_modifier 2 set simulation_state "CREATING HOUSEHOLDS" make-households set simulation_state "CREATING SCHOOLS" make-schools set simulation_state "CREATING ADULT FRIENDS" make-friends set simulation_state "VACCINATING PEOPLE" vaccinate-people set simulation_state "INFECTING PEOPLE" infect-initial hide-links generate-values set simulation_state "READY TO GO" end ;; VACCINATE PROCEDURE to vaccinate-people ask people with [person_infective_status = 1] ;; ASK PEOPLE WHO ARE SUSCEPTIBLE [IF random-float 100 < vaccinated_percentage ;; DECIDE IF TO BE VACCINATED [set person_infective_status 5 set color 61]] ;; SET THEIR STATUS AND CHANGE COLOUR end ;; INITIAL INFECTION PROCEDURE to infect-initial IFELSE count people with [person_infective_status = 1] < initial_infections ;; IF THE NUMBER OF SUSCEPTIBLES IS < REQUIRED INFECTIONS [ask people with [person_infective_status = 1] ;; MAKE ALL SUSCEPTIBLES INFECTED [become-activeinfected]] [ask n-of initial_infections people with [person_infective_status = 1] ;; IF NOT, MAKE CORRECT NUMBER OF THEM INFECTED [become-activeinfected]] end ;; MAKE HOUSEHOLDS PROCEDURE to make-households create-house_centres Households ;; Create a number of house_centres equivalent to the slider [set xcor random-float (world_width - 2) - (world_halfwidth - 1) ;; Distribute house centres through the world set ycor random-float (world_width - 2) - (world_halfwidth - 1) ;; As above but for y axis set shape "house" set color blue set size 0.5 * size_modifier] ;; Set some display attributes ask house_centres [let temp_numadults_tomake one-of [1 2 2] ;; Ask each of these houses to set number of adults 1 or 2 let temp_household_who who ;; Create a temp variable of the creating household number hatch-people temp_numadults_tomake ;; Ask house centres to make adults [set shape "circle" ;; Set a shape create-familylink-from myself [set link_type 1] ;; Link the created people to the household creator set xcor xcor + 1 ;; Bump them away from creator set color magenta ;; Set a colour set ptype 1 ;; Set a type set size 0.5 * size_modifier ;; Change size if necessary set household_who temp_household_who ;; Store the household creator as a variable in each adult IFELSE temp_numadults_tomake > 1 [set spouse 1] ;; Mark if spouse exists [set spouse 0] ;; ...or doesn't set friends_wanted 10 + random 11 ;; Decide how many friends each adults wants (10-20) set quarantined 0 ;; Set quarantine state to 0 set person_infective_status 1 ;; Set their state to susceptible ] ] ask house_centres with [count out-link-neighbors > 0] ;; Ask house centres with adults to make children [let temp_household_who who ;; Create a temp variable of the creating household number hatch-people random 3.1 [set shape "circle" create-familylink-from myself [set link_type 2] set ycor ycor - 1 set color violet set ptype 2 set size 0.5 * size_modifier set household_who temp_household_who set quarantined 0 set person_infective_status 1 ] ] ask house_centres [IF count out-link-neighbors = 0 [die]] ;; Ask any house centres with no adults/children to die ask house_centres [ ;; Ask each household to arrange themselves in a circle let temp_xcor xcor ;; Create a temp variable with house_centre x co-ordinate let temp_ycor ycor ;; Create a temp variable with house_centre x co-ordinate if count out-link-neighbors = 0 [stop] ;; Stop if no neighbours layout-circle out-link-neighbors 0.5 * size_modifier ;; Ask my linked neighbours to layout in a circle radius 1 (around centre of map) ask out-link-neighbors [set xcor xcor + temp_xcor ;; Move this circle to centre on location of household set ycor ycor + temp_ycor] ] end ;; MAKE SCHOOLS PROCEDURE to make-schools create-school_centres Schools ;; Make some schools [set xcor random-float (world_width - 2) - (world_halfwidth - 1) ;; Scatter schools around map set ycor random-float (world_width - 2) - (world_halfwidth - 1) set shape "square" ;; Setup display variables set color blue set size 3 * size_modifier] ask people with [ptype = 2] ;; Allocate pupils to schools by asking each pupil [IFELSE random 3.1 < 3 ;; 3 times out of 4... [create-schoollink-from min-one-of school_centres [distance myself] [set link_type 3]] ;; ... to link to nearest school [create-schoollink-from one-of school_centres [set link_type 3]] ;; ... else link to a random school (inc. nearest) ] end ;; MAKE CONTACTS PROCEDURE to make-friends ask people with [ptype = 1] ;; Ask all adults [acquire_adult_spouse_friends ;; Acquire some of their spouses friends make_adult_radius_friends ;; Then make nearby friends make_adult_remaining_friends] ;; Then make remaining friends end to acquire_adult_spouse_friends ;; run by a 'person' agent, not the observer IF spouse = 0 [stop] ;; Stop if no spouse let temp_my_householdwho household_who ;; Put my household number in a temporary variable ask other people with [ptype = 1 AND household_who = temp_my_householdwho] ;; Ask my spouse (the one with my household number) to run the following; [IF count my-friendlinks = 0 [stop] ;; Stop if spouse doesn't have friends IF spouse_friends_done = 1 [set temp_spouse_stop_command 1 stop] ;; Don't run if friends already transferred other way set temp_spouse_friends_agentset n-of (round (0.75 * count friendlink-neighbors)) friendlink-neighbors] ;; Create a temporary agentset of 75% of my spouses friends (note this is not my-links command) IF temp_spouse_stop_command = 1 [set temp_spouse_stop_command 0 ;; Once stop command has triggered, reset this back to 0 then... stop] ;; ...stop as my spouse reported they've already taken my links IF temp_spouse_friends_agentset = 0 [stop] ;; If that agentset is empty, stop let temp_spouse_friends_count count temp_spouse_friends_agentset ;; Create a temporary variable of number of spouse friends let temp_friends_count count my-friendlinks ;; Count how many friends I already have let temp_friends_needed (friends_wanted - temp_friends_count) ;; Count how many friends I still need IF temp_friends_needed < 1 [stop] ;; Don't run if no friends needed IFELSE temp_spouse_friends_count <= temp_friends_needed [create-friendlinks-with temp_spouse_friends_agentset [set link_type 6]] ;; if agentset is smaller than friends needed acquire all of them [create-friendlinks-with n-of temp_friends_needed temp_spouse_friends_agentset [set link_type 6]] ;; if agentset is larger than friends needed acquire the number I need from them set spouse_friends_done 1 ;; set that I have done my spouse friends transfer to make sure we don't do it back the other way end to make_adult_radius_friends ;; THIS IS A VERY HELPFUL PROCESSING STEP ;; let temp_existing_friends_set friendlink-neighbors ;; Create a temporary set of people already friends with me let temp_adults_in_radius people with [ptype = 2] in-radius (world_width * 0.15) ;; Create a temporary set of people within 10 of me ask temp_adults_in_radius [set exclude_friend_set 1] ;; Ask everyone in radius to set their exclusion variable to 1 ask temp_existing_friends_set [set exclude_friend_set 0] ;; Ask everyone already my friend to set exclusion variable to 0 set temp_adults_in_radius temp_adults_in_radius with [exclude_friend_set = 1] ;; Update the temporary set to be only those not identified as a friend already let temp_friends_count count my-friendlinks ;; Set a temp variable as number of existing adult friends let temp_friends_needed (friends_wanted - temp_friends_count) ;; Check how many friends still needed let temp_radius_adults count temp_adults_in_radius ;; Check how many adults are in radius IFELSE temp_radius_adults <= temp_friends_needed ;; If number of friends in radius is less that friends needed [create-friendlinks-with n-of temp_radius_adults temp_adults_in_radius [set link_type 4]] ;; ...make friends with all of these people [create-friendlinks-with n-of temp_friends_needed temp_adults_in_radius [set link_type 4]] ;; ...else make friends with number of friends needed from these people ask temp_existing_friends_set [set exclude_friend_set 0] ;; Reset the temporary group variable end to make_adult_remaining_friends ;; REPEAT FOR ALL ;; let temp_existing_friends_set friendlink-neighbors ;; Create a temporary set of people already friends with me let temp_adults_in_radius people with [ptype = 2] ;; Create a temporary set of adults ask temp_adults_in_radius [set exclude_friend_set 1] ;; Ask everyone to set their exclusion variable to 1 ask temp_existing_friends_set [set exclude_friend_set 0] ;; Ask everyone already my friend to set exclusion variable to 0 set temp_adults_in_radius temp_adults_in_radius with [exclude_friend_set = 1] ;; Update the temporary set to be only those not identified as a friend already let temp_friends_count count my-friendlinks ;; Set a temp variable as number of my existing adult friends let temp_friends_needed (friends_wanted - temp_friends_count) ;; Check how many friends still needed let temp_radius_adults count temp_adults_in_radius ;; Check how many adults are in radius IFELSE temp_radius_adults <= temp_friends_needed ;; If number of friends in radius is less that friends needed [create-friendlinks-with n-of temp_radius_adults temp_adults_in_radius [set link_type 5]] ;; ...make friends with all of these people [create-friendlinks-with n-of temp_friends_needed temp_adults_in_radius [set link_type 5]] ;; ...else make friends with number of friends needed from these people ask temp_existing_friends_set [set exclude_friend_set 0] ;; Reset the temporary group variable end to hide-links ask links [hide-link] end ;; =================== ;; =================== ;; MAIN GO PROCEDURE ;; =================== ;; =================== to go set simulation_state "ACTIVE" tick IF Decay_Infectivity_Paths = TRUE [ask infectorlinks [IFELSE age <= 0 [hide-link] [set color (color - decay_turns + age) set age age - 1]]] quarantine-children ;; ASSESS IF ANY CHILDREN QUARANTINED infect-schools ;; RUN SCHOOL INFECTION ASSESSMENTS infect-households ;; RUN FAMILY INFECTION ASSESSMENTS infect-friends ;; RUN FRIEND INFECTION ASSESSMENTS activate-infection recover-infection generate-values if count people with [person_infective_status = 3 OR person_infective_status = 2] = 0 ;; RUN IF NO INFECTIONS STARTED [IFELSE count people with [ever_infected = 1] <= (initial_infections) [infect-initial go] [set simulation_state "COMPLETED" stop]] IF simulation_state = "COMPLETED" [stop] end to quarantine-children ASK people with [ptype = 2 AND person_infective_status = 3 and quarantined = 0] [IF random-float 1 < 0.3 [set quarantined 1]] end to infect-schools ;; TO INFECT SCHOOLS ask people with [ptype = 2 AND person_infective_status = 3 AND quarantined = 0] ;; ASK EACH CHILD IN TURN WHO IS INFECTIVE AND IN SCHOOL [set temp_infector_who who ;; TO SET THE TEMP WHO VARIABLE AS THEIR OWN... ask in-schoollink-neighbors [ ;; ...AND ASK THEIR CONNECTED SCHOOL... set temp_school_who who ask out-schoollink-neighbors with [person_infective_status = 1] ;; ...TO ASK SUSCEPTIBLES THEY ARE CONNECTED TO... [IF random-float 1 < school_transmission_prob ;; ...TO MAKE AN ASSESSMENT OF WHETHER TO BECOME INFECTED [set person_infective_status 2 set infected_by_who temp_infector_who set infected_by_school temp_school_who] ;; ...AND IF SO, TO SET THEMSELEVES AS SO, AND TO RECORD WHO INFECTED THEM ] ]] set temp_school_who 0 end to infect-households ask people with [person_infective_status = 3] ;; ASK INFECTIVE PEOPLE... [set temp_infector_who who ;; TO SET THE TEMP WHO VARIABLE AS THEIR OWN... ask in-familylink-neighbors ;; ...AND ASK THEIR HOUSEHOLD... [ask out-familylink-neighbors with [person_infective_status = 1] ;; ...TO ASK ALL FAMILY MEMBERS WHO ARE SUSCEPTIBLE... [IF random-float 1 < family_transmission_prob ;; ...TO EVALUATE WHETHER TO BECOME INFECTED... [set person_infective_status 2 set infected_by_who temp_infector_who] ;; ...AND IF SO, TO SET THEMSELVES AS SO, AND TO RECORD WHO INFECTED THEM ]]] end to infect-friends ask people with [person_infective_status = 3] ;; ASK INFECTIVE PEOPLE... [ set temp_infector_who who ;; ...TO SET THE TEMP WHO VARIABLE AS THEIR OWN... ask friendlink-neighbors with [person_infective_status = 1] ;; ...AND TO ASK EACH OF THEIR SUSCEPTIBLE FRIENDS... [IF random-float 1 < friend_transmission_prob ;; ...TO EVALUATE WHETHER TO BECOME INFECTED... [set person_infective_status 2 set infected_by_who temp_infector_who] ;; ...AND IF SO, TO SET THEMSELVES AS SO, AND TO RECORD WHO INFECTED THEM ]] end ;; ACTIVATE INFECTED INDIVIDUALS - ONLY WANT INFECTIONS TO DEVELOP AT THE END OF EACH TURN to activate-infection ASK people with [person_infective_status = 2] ;; ASK THOSE MARKED TO BE INFECTED TO BECOME INFECTIOUS [become-activeinfected] end to become-activeinfected ;; SUB FUNCTION RUN BY TURTLES set infective_recovery_time random 5 + 4 ;; SET HOW LONG RECOVERY WILL TAKE set person_infective_status 3 ;; SET STATUS TO INFECTIOUS set size 1 * size_modifier ;; SET SIZE set color red ;; SET COLOUR set ever_infected 1 ;; RECORD AS A CASE IF infected_by_who <= 0 [stop] ;; IF AN INITIAL INFECTION, STOP HERE... IFELSE infected_by_school > 0 [create-infectorlink-from school_centre infected_by_school [set color red set thickness 0.02 set age decay_turns - 1 set initialcolor red] let temp_myschool infected_by_school ask school_centre temp_myschool [set size 5 set color red] ask person infected_by_who [create-infectorlink-to school_centre temp_myschool [set color red set thickness 0.02 set age decay_turns - 1 set initialcolor red]]] [create-infectorlink-from person infected_by_who [ ask end1 [set temp_ptype_sou ptype] ;; ELSE CREATE A LINK BASED ON START AND END POINT TURTLES ask end2 [set temp_ptype_rec ptype] IF temp_ptype_sou = 2 AND temp_ptype_rec = 2 [set color yellow set thickness 0.02 set age decay_turns - 1 set initialcolor yellow] IF temp_ptype_sou = 2 AND temp_ptype_rec = 1 [set color cyan set thickness 0.02 set age decay_turns - 1 set initialcolor cyan] IF temp_ptype_sou = 1 AND temp_ptype_rec = 1 [set color orange set thickness 0.02 set age decay_turns - 1 set initialcolor orange] IF temp_ptype_sou = 1 AND temp_ptype_rec = 2 [set color green set thickness 0.02 set age decay_turns - 1 set initialcolor green]]] end to recover-infection ASK people with [person_infective_status = 3] ;; ASK ALL THOSE INFECTED [set infective_recovery_time infective_recovery_time - 1] ;; TO REDUCE THEIR RECOVERY TIME BY 1 ASK people with [person_infective_status = 3 AND infective_recovery_time <= 0] ;; AND IF THEIR RECOVERY TIME IS 0 OR BELOW [set person_infective_status 4 set color yellow set size 0.75 * size_modifier] ;; TO CHANGE STATUS TO RECOVERED end ;; VALUES FOR PLOTS AND OUTPUTS ;; to generate-values set percentage_susceptible 100 * count people with [person_infective_status = 1] / count people set percentage_infected 100 * count people with [person_infective_status = 3] / count people set percentage_immune 100 * count people with [person_infective_status > 3] / count people set percentage_ever_infected 100 * count people with [ever_infected = 1] / count people ask people with [person_infective_status > 2][set people_infected count my-out-infectorlinks] end ;; OLD CODE - KEPT FOR INTEREST ;; to infect-schools ;; ask school_centres ;; [let temp_infected_children count out-schoollink-neighbors with [(quarantined = 0 AND person_infective_status = 3)] ;; Temp variable of number of children not quarantined and infected ;; let temp_attending_children count out-schoollink-neighbors with [quarantined = 0] ;; Temp variable of number of children not quarantined ;; IF temp_attending_children = 0 [stop] ;; If no children attending, stop ;; IF temp_infected_children = 0 [stop] ;; If no children infected, stop ;; set school_percentage_infected temp_infected_children / temp_attending_children ;; Set school_percentage_infected as percentage ;; set school_infective_risk 0.05 ;; set school infective risk at 0.05 ;; IF school_percentage_infected < 0.10 [set school_infective_risk 0.02] ;; Lower it to 0.02 if less than 10% infected ;; IF school_percentage_infected < 0.02 [set school_infective_risk 0.01] ;; Lower it to 0.01 if less than 2% infected ;; let temp_school_infective_risk school_infective_risk ;; Set temporary variable of the schools infective risk ;; ask out-schoollink-neighbors with [(quarantined = 0 AND person_infective_status = 1)] ;; [IF random-float 1 < temp_school_infective_risk [SET person_infective_status 2]] ;; Ask each of the schools susceptible pupils to evaluate risk ;; ] ;; end ;; to infect-households ;; ask house_centres ;; [let temp_infected_members count out-familylink-neighbors with [person_infective_status = 3] ;; Create temp variable of family members infected ;; let temp_active_members count out-familylink-neighbors ;; Create temp_variable of all family members ;; IF temp_active_members = 0 [stop] ;; Stop if no family members (only use if add conditions to above) ;; IF temp_infected_members = 0 [stop] ;; Stop if no family members infected ;; set family_percentage_infected temp_infected_members / temp_active_members ;; Percent family infected ;; set family_infective_risk 0.05 ;; IF family_percentage_infected < 0.10 [set family_infective_risk 0.02] ;; IF family_percentage_infected < 0.02 [set family_infective_risk 0.01] ;; let temp_family_infective_risk family_infective_risk ;; ask out-familylink-neighbors with [person_infective_status = 1] ;; [IF random-float 1 < temp_family_infective_risk [SET person_infective_status 2]] ;; ] ;;end
There is only one version of this model, created over 11 years ago by Christopher Chiswell.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Infective Community Network.png | preview | Preview for 'Infective Community Network' | over 11 years ago, by Christopher Chiswell | Download |
This model does not have any ancestors.
This model does not have any descendants.