📄 aaa---smart-diverse.nlogo
字号:
globals[ generations ; counts how many generations have passed red-count ; population of red turtles blue-count ; population of blue turtles; red-lag ; lagged red population; blue-lag ; lagged blue population parent-type ; type of my parent environ ; integer environ indicator time-in-environ ; how long we stay in this environ]turtles-own[ my-type ; turtle-type (to match with environ) time-til-repro ; number of time steps remaining until reproduction (-1 means not counting down)]to setup clear-output setup-experimentendto setup-experiment cp ct clear-all-plots set generations 0 set environ 1 + random environ-max set time-in-environ 1 + random time-in-environ-max cct carrying-capacity / 10 [ setxy (random-float screen-size-x) (random-float screen-size-y) ; randomize turtle locations ifelse who < (carrying-capacity / 20) ; start out with equal numbers of reds and blues [ set color blue ] [ set color red ] set my-type 1 + random environ-max set time-til-repro -1 ]; set red-lag [0 0 0 0 0 0 0 0 0 0]; set blue-lag [0 0 0 0 0 0 0 0 0 0] setup-plot plot-countsendto go wander live grim-reaper set generations generations + 1 set time-in-environ time-in-environ - 1 if time-in-environ = 0 [ set environ 1 + random environ-max set time-in-environ 1 + random time-in-environ-max ]; set red-lag fput count turtles with [ color = red ] but-last red-lag; set blue-lag fput count turtles with [ color = blue ] but-last blue-lag plot-countsend;; to enable many repetitions with same settingsto go-experiment go if red-count < 10 [ output-print "red extinct after " + generations + " generations" setup-experiment ] if blue-count < 10 [ output-print "blue extinct after " + generations + " generations" setup-experiment ]endto wander ask turtles [ rt random-float 30 - random-float 30 fd 5 ]endto live ask turtles [ ifelse color = red [ if my-type < environ [ set my-type my-type + learning-rate ] if my-type > environ [ set my-type my-type - learning-rate ] ifelse time-til-repro < 0 [ if (abs (environ - my-type)) < 2 [ set time-til-repro red-gestation ] ] [ if time-til-repro = 0 [ set parent-type my-type hatch 1 [ set color red ifelse Memes [ set my-type round random-normal parent-type red-spread ] [ set my-type 1 + random environ-max ] set time-til-repro -1 setxy (random-float screen-size-x) (random-float screen-size-y) ; randomize turtle locations ] ] set time-til-repro time-til-repro - 1 ] ] ; blue: [ ifelse time-til-repro < 0 [ set time-til-repro 1 + round ( 0.75 * min list (abs environ - my-type) (abs my-type - environ) ) ] [ if time-til-repro = 0 [ set parent-type my-type hatch 1 [ set color blue ; set my-type parent-type + (3 - random 7) set my-type 1 + random environ-max set time-til-repro -1 setxy (random-float screen-size-x) (random-float screen-size-y) ; randomize turtle locations ] ] set time-til-repro time-til-repro - 1 ] ] ]end;; kill turtles in excess of carrying capacity;; note that reds and blues have equal probability of dyingto grim-reaper let num-turtles count turtles if num-turtles <= carrying-capacity [ stop ] let chance-to-die (num-turtles - carrying-capacity) / num-turtles ask turtles [ if random-float 1.0 < chance-to-die [ die ] ]endto plot-counts set-current-plot "Populations" set red-count count turtles with [ color = red ] set-current-plot-pen "Reds" plot red-count set blue-count count turtles with [ color = blue ] set-current-plot-pen "Blues" plot blue-count set-current-plot-pen "Total" plot count turtles set-current-plot "Type Distributions" set-current-plot-pen "my-type-red" histogram-from turtles with [ color = red ] [my-type] set-current-plot-pen "my-type-blue" histogram-from turtles with [ color = blue ] [my-type] ; if generations > 60; [ set-current-plot "Lagged"; ; set-current-plot-pen "Red-lag"; plotxy item Lag red-lag item 0 red-lag; ; set-current-plot-pen "Blue-lag"; plotxy item Lag blue-lag item 0 blue-lag; ] endto setup-plot set-current-plot "Populations" set-plot-y-range 0 floor ((carrying-capacity / environ-max ) * 1.2) set-current-plot "Type Distributions" set-plot-x-range 0 environ-max set-plot-y-range 0 round (10 * (count turtles) / environ-max) set-histogram-num-bars environ-max ; set-current-plot "Lagged"; set-plot-x-range 0 1.025 * carrying-capacity; set-plot-y-range 0 1.025 * carrying-capacityend; *** NetLogo Model Copyright Notice ***;; Portions of the code for this model were derived from a Simple; Birth Rates Model.;; That model was created as part of the project: CONNECTED MATHEMATICS:; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL; MODELS (OBPML). The project gratefully acknowledges the support of the; National Science Foundation (Applications of Advanced Technologies; Program) -- grant numbers RED #9552950 and REC #9632612.;; Copyright 1998 by Uri Wilensky. All rights reserved.;; Permission to use, modify or redistribute this model is hereby granted,; provided that both of the following requirements are followed:; a) this copyright notice is included.; b) this model will not be redistributed for profit without permission; from Uri Wilensky.; Contact Uri Wilensky for appropriate licenses for redistribution for; profit.;;; To refer to this model in academic publications, please use:; Carter, T. (2005). NetLogo Smart-Diverse model.;;; *** End of NetLogo Model Copyright Notice ***@#$#@#$#@GRAPHICS-WINDOW2901060334450503.00101110111CC-WINDOW5478960573Command Center0BUTTON1331025443run-experimentgo-experimentT1TOBSERVERTNILSLIDER94624679learning-ratelearning-rate01.00.330.011NILBUTTON5106543setupsetupNIL1TOBSERVERTNILBUTTON691012943gogoT1TOBSERVERTNILPLOT4245284464PopulationsGenerationsPopulation0.050.00.01200.0truetruePENS"Reds" 1.0 0 -2674135 true"Blues" 1.0 0 -13345367 true"Total" 1.0 0 -10899396 trueMONITOR819384242Num Redsred-count31MONITOR93193170242Num Bluesblue-count31MONITOR177193267242Generationsgenerations31OUTPUT291351603445SLIDER9118155151environ-maxenviron-max01007051NILSLIDER159118286151time-in-environ-maxtime-in-environ-max11005011NILSLIDER982154115carrying-capacitycarrying-capacity020000400010001NILPLOT63268951300Type DistributionsTypesPopulation1.070.00.0100.0true
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -