📄 ---pestilence.nlogo
字号:
fd 25] if Left_Quadrant = "Low Outside" [set heading -90 fd 75 set heading 180 fd 25] if Left_Quadrant = "Low Center" [set heading -90 fd 25 set heading 180 fd 25] if Left_Quadrant = "Bottom Outside" [set heading -90 fd 75 set heading 180 fd 75] if Left_Quadrant = "Bottom Center" [set heading -90 fd 25 set heading 180 fd 75] set heading (random 360) repeat (random (100 - Density_Left)) [check-approp fd 1]] [if Right_Quadrant = "Top Outside" [set heading 90 fd 75 set heading 0 fd 75] if Right_Quadrant = "Top Center" [set heading 90 fd 25 set heading 0 fd 75] if Right_Quadrant = "High Outside" [set heading 90 fd 75 set heading 0 fd 25] if Right_Quadrant = "High Center" [set heading 90 fd 25 set heading 0 fd 25] if Right_Quadrant = "Low Outside" [set heading 90 fd 75 set heading 180 fd 25] if Right_Quadrant = "Low Center" [set heading 90 fd 25 set heading 180 fd 25] if Right_Quadrant = "Bottom Outside" [set heading 90 fd 75 set heading 180 fd 75] if Right_Quadrant = "Bottom Center" [set heading 90 fd 25 set heading 180 fd 75] set heading (random 360) repeat (random (100 - Density_Right)) [check-approp fd 1]] ] set isset 1end;;--------------------------------------------------------------------------------------------------------to infect set radius Infection_Radius check-radius if shade-of? blue color and (Contact_Infection > (random 100)) and any? turtles in-radius-no-wrap radius with [shade-of? red color] and not(size <= 5 + .001 + (.001 * Recover_Immune_Time) and size > 5) [ifelse color < 106 [if (color - blue) < (.001 * Susceptible_Below) or (color - blue) > (.001 * Susceptible_Above) [set weak true]] [if (color - blue) < 3 + (.001 * Susceptible_Below) or (color - blue) > 3 + (.001 * Susceptible_Above) [set weak true]] set color red + (color - blue) ;; add current age set size 5 if random 100 < Deadly_Mutations [set color (color + .010)] if random 100 < Percent_Recovery [set color blue + (color - red) set size size + .001 set weak false] ]end;;--------------------------------------------------------------------------------------------------------to check-radiusloop[ ifelse any? patches in-radius-no-wrap radius with [pcolor = black] [set radius radius - 1] [stop] ]end;;--------------------------------------------------------------------------------------------------------to reproducelocals[ mat-blue-trav mat-blue-meand nei-mat-blue-trav nei-mat-blue-meand mat-red-trav mat-red-meand nei-mat-red-trav nei-mat-red-meand myWho ;; any? turtles in-radius-no-wrap includes calling turtle ] if radius > 5 [set radius 5] set myWho who if ((random 100) < 25) and ;; 50% chance of running into opposite sex also, no reproduction 2x a time interval count turtles in-radius-no-wrap radius < Carrying_Capacity and count turtles in-radius-no-wrap radius > 1 [ set mat-blue-trav (shade-of? blue color and color >= blue + (.001 * Procreation_Age) and shape = "default") set mat-blue-meand (shade-of? blue color and color >= blue + (.001 * Procreation_Age) and shape = "circle") set nei-mat-blue-trav any? turtles in-radius-no-wrap radius with [not (who = myWho) and shade-of? blue color and color >= blue + (.001 * Procreation_Age) and shape = "default"] set nei-mat-blue-meand any? turtles in-radius-no-wrap radius with [not (who = myWho) and shade-of? blue color and color >= blue + (.001 * Procreation_Age) and shape = "circle"] set mat-red-trav (shade-of? red color and color >= (red + (.001 * Procreation_Age)) and shape = "default") set mat-red-meand (shade-of? red color and color >= (red + (.001 * Procreation_Age)) and shape = "circle") set nei-mat-red-trav any? turtles in-radius-no-wrap radius with [not (who = myWho) and shade-of? red color and color >= red + (.001 * Procreation_Age) and shape = "default"] set nei-mat-red-meand any? turtles in-radius-no-wrap radius with [not (who = myWho) and shade-of? red color and color >= red + (.001 * Procreation_Age) and shape = "circle"] ifelse mat-blue-meand and nei-mat-blue-meand and (random 1000) < (Healthy_Meanderer_Fertility * Healthy_Meanderer_Fertility) [hatch Healthy_Birth_Number [set color blue set weak false set size 5]] [ifelse mat-blue-trav and nei-mat-blue-trav and (random 1000) < (Healthy_Traveler_Fertility * Healthy_Traveler_Fertility) [hatch Healthy_Birth_Number ;; repetitive but nested ifelse the only way to do case [set color blue set weak false set size 5]] [ifelse ((mat-blue-meand and nei-mat-red-meand) or (nei-mat-blue-meand and mat-red-meand)) and (random 1000) < (Healthy_Meanderer_Fertility * Infected_Meanderer_Fertility) [ifelse (random 100) < 50 [hatch Healthy_Birth_Number [set color blue set weak false set size 5]] [hatch Infected_Birth_Number [set color red set weak true set size 5 if random 100 < Percent_Recovery [set color blue + (color - red) set size size + .001 set weak false] if random 100 < Deadly_Mutations [set color (color + .010)]]]] [ifelse ((mat-blue-trav and nei-mat-red-trav) or (nei-mat-blue-trav and mat-red-trav)) and (random 1000) < (Healthy_Traveler_Fertility * Infected_Traveler_Fertility) [ifelse (random 100) < 50 [hatch Healthy_Birth_Number [set color blue set weak false set size 5]] [hatch Infected_Birth_Number [set color red set weak true set size 5 if random 100 < Percent_Recovery [set color blue + (color - red) set size size + .001 set weak false] if random 100 < Deadly_Mutations [set color (color + .010)]]]] [ifelse mat-red-meand and nei-mat-red-meand and (random 1000) < (Infected_Meanderer_Fertility * Infected_Meanderer_Fertility) [hatch Infected_Birth_Number [set color red set weak true set size 5 if random 100 < Percent_Recovery [set color blue + (color - red) set size size + .001 set weak false] if random 100 < Deadly_Mutations [set color (color + .010)]]] [if mat-red-trav and nei-mat-red-trav and (random 1000) < (Infected_Traveler_Fertility * Infected_Traveler_Fertility) [hatch Infected_Birth_Number [set color red set weak true set size 5 if random 100 < Percent_Recovery [set color blue + (color - red) set size size + .001 set weak false] if random 100 < Deadly_Mutations [set color (color + .010)]]]]]]]] ]end;;--------------------------------------------------------------------------------------------------------to move ifelse shape = "default" [repeat Traveler_Moves ;; how many steps per move [check-approp fd 1]] [repeat Meanderer_Moves [check-approp fd 1]]end ;;--------------------------------------------------------------------------------------------------------to age set color (color + .001) if (color >= (blue + (.001 * Procreation_Age)) and color < 106) or (color >= (red + (.001 * Procreation_Age)) and color < 16) [set color color + 3] ifelse shade-of? blue color [if size > 5 [set size (size + .001)] ifelse color < 106 [if color >= (blue + (.001 * Healthy_Lifespan)) [set dead dead + 1 die]] [if color >= ((blue + 3) + (.001 * Healthy_Lifespan)) [set dead dead + 1 die]]] [set size (size + .001) ifelse color < 16 [if color >= (red + (.001 * Healthy_Lifespan)) [set dead dead + 1 die]] [if color >= ((red + 3) + (.001 * Healthy_Lifespan)) [set dead dead + 1 die]] ifelse weak [if size >= (5 + (.001 * Susceptible_Infection_Lifespan)) [set dead dead + 1 die]] [if size >= (5 + (.001 * Infection_Lifespan)) [set dead dead + 1 die]] ]end;;--------------------------------------------------------------------------------------------------------to do-plots set-current-plot "Healthy/ Infected" set-current-plot-pen "Healthy" plot count turtles with [shade-of? blue color] set-current-plot-pen "Infected" plot count turtles with [shade-of? red color] ;;---------------------------------------------- set-current-plot "Travelers (Arrows)" set-current-plot-pen "Healthy Adult" plot count turtles with [color > 106 and shape = "default"] set-current-plot-pen "Healthy Young" plot count turtles with [shade-of? blue color and color < 106 and shape = "default"] set-current-plot-pen "Infected Adult" plot count turtles with [shade-of? red color and color > 16 and shape = "default"] set-current-plot-pen "Infected Young" plot count turtles with [shade-of? red color and color < 16 and shape = "default"] ;;---------------------------------------------- set-current-plot "Meanderers (Circles)" set-current-plot-pen "Healthy Adult" plot count turtles with [color > 106 and shape = "circle"] set-current-plot-pen "Healthy Young" plot count turtles with [shade-of? blue color and color < 106 and shape = "circle"] set-current-plot-pen "Infected Adult" plot count turtles with [shade-of? red color and color > 16 and shape = "circle"] set-current-plot-pen "Infected Young" plot count turtles with [shade-of? red color and color < 16 and shape = "circle"]end;;--------------------------------------------------------------------------------------------------------to setup-filelocals[line] ifelse file-exists? "C:/WINDOWS/Desktop/Pestilence/Pestilence Data.csv" [set file "C:/WINDOWS/Desktop/Pestilence/Pestilence Data.csv"] ;;Because file locations will vary from system to system, you may want to change this to aviod continuous file selection. [ifelse file-exists? "C:/Documents and Settings/All Users/Desktop/Pestilence/Pestilence Data.csv" [set file "C:/Documents and Settings/All Users/Desktop/Pestilence/Pestilence Data.csv"] [set file user-choose-file] ] file-open file set line file-read-line ;; You need to close the Excel SS if you get an error here. file-close if line = "first" [file-delete file] file-open file if line = "first" [file-print "This file MUST be closed while running the pestilence model. Do NOT save when prompted." file-print "To format: 1) Open 'Template' Excel document(Enable Macros) 2) View this window 3)Press Alt + F8 4) Select Template.xls!Macro1 and Run" ] if line = "first" [user-message "File output will be found on the Desktop in the Pestilence folder (The image with a,). This Excel file must be closed while running the Pestilence model. Do NOT save when prompted."] file-print "___P_____,____E____,____S____,____T___,____I__,____L____,____E____,____N__,____C___,_____E___,_________,_________" file-closeend;;--------------------------------------------------------------------------------------------------------to disp-header file-type "Initial Conditions" file-type ",Density Left: " file-type Density_Left file-type ",Density Right: " file-type Density_Right file-type ",Travelers Left: " file-type Travelers_Left file-type ",Travelers Right: " file-type Travelers_Right file-type ",Meanderers Left: " file-type Meanderers_Left file-type ",Meanderers Right: " file-type Meanderers_Right file-type ",% Infected Left: " file-type %_Infected_Left file-type ",% Infected Right: " file-type %_Infected_Right file-type ",Background: " file-type Background file-type ",Left Quadrant: " file-type Left_Quadrant file-type ",Right Quadrant: " file-print Right_Quadrant file-type "Susceptible Infection Lifespan: " file-type Susceptible_Infection_Lifespan file-type ",Susceptible Below: " file-type Susceptible_Below file-type ",Susceptible Above: " file-type Susceptible_Above file-type ",Percent Recovery: " file-type Percent_Recovery file-type ",Recover Immune Time: " file-type Recover_Immune_Time file-type ",Infection Lifespan: " file-type Infection_Lifespan file-type ",Deadly Mutations: " file-type Deadly_Mutations file-type ",Healthy Traveler Fertility: " file-type Healthy_Traveler_Fertility file-type ",Healthy Meanderer Fertility: " file-type Healthy_Meanderer_Fertility file-type ",Infected Traveler Fertility: " file-type Infected_Traveler_Fertility file-type ",Infected Meanderer Fertility: " file-type Infected_Meanderer_Fertility file-type ",Procreation Age: " file-print Procreation_Age file-type "Healthy Birth Number: " file-type Healthy_Birth_Number file-type ",Infected Birth Number: " file-type Infected_Birth_Number file-type ",Healthy Lifespan: " file-type Healthy_Lifespan file-type ",Meanderer Moves: " file-type Meanderer_Moves file-type ",Traveler Moves: " file-type Traveler_Moves file-type ",Carrying Capacity: " file-type Carrying_Capacity file-type ",Contact Infection: " file-type Contact_Infection file-type ",Infection Radius: " file-type Infection_Radius file-print "" file-type "Time,Total,% Healthy,% Infected,Healthy Adult Travelers,Healthy Young Travelers," file-type "Infected Adult Travelers,Infected Young Travelers,Healthy Adult Meanderers," file-type "Healthy Young Meanderers,Infected Adult Meanderers," file-print "Infected Young Meanderers"end ;;--------------------------------------------------------------------------------------------------------to update-file file-type time file-type "," file-type count turtles file-type "," ifelse count turtles > 0 [file-type precision ((count turtles with [shade-of? blue color] / count turtles) * 100) 3 file-type "," file-type precision ((count turtles with [shade-of? red color] / count turtles) * 100) 3 file-type "," ] [file-type 0 file-type "," file-type 0 file-type ","] file-type count turtles with [color > 106 and shape = "default"] file-type "," file-type count turtles with [shade-of? blue color and color < 106 and shape = "default"] file-type "," file-type count turtles with [shade-of? red color and color > 16 and shape = "default"] file-type "," file-type count turtles with [shade-of? red color and color < 16 and shape = "default"] file-type "," file-type count turtles with [color > 106 and shape = "circle"] file-type "," file-type count turtles with [shade-of? blue color and color < 106 and shape = "circle"] file-type "," file-type count turtles with [shade-of? red color and color > 16 and shape = "circle"] file-type "," file-type count turtles with [shade-of? red color and color < 16 and shape = "circle"] file-print ""end@#$#@#$#@GRAPHICS-WINDOW432109125111001002.34151110CC-WINDOW56451026740Command CenterBUTTON3664743484NILGoNIL1TOBSERVERTNILBUTTON3661043447NILSetupNIL1TOBSERVERTNILSLIDER0412212445Healthy_LifespanHealthy_Lifespan01008011NILSLIDER0181212214Infection_LifespanInfection_Lifespan0502011NILSLIDER212313367346Procreation_AgeProcreation_Age0301611NILSLIDER0445212478Contact_InfectionContact_Infection0100831
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -