---discretelife.nlogo

来自「NETLOGO」· NLOGO 代码 · 共 491 行

NLOGO
491
字号
globals [ ticks total-mortals max-mortals]breeds [ mortals immortals ]patches-own [ mortalPop immortalPop]mortals-own [ deathRate birthRate diffusionRate ] immortals-own [ diffusionRate ]to setup   ca    set ticks 0  ask patches [set pcolor background-color]  set max-mortals init-mortals    create-custom-mortals init-mortals  ;; create the mortals, then initialize their variables  [     set color blue    set diffusionRate mortals-diffusion    set deathRate mortals-death-rate    set birthRate mortals-birth-rate    setxy random-int-or-float screen-size-x random-int-or-float screen-size-y  ]      create-custom-immortals init-immortals  ;; create the immortals, then initialize their variables  [     set color red    set diffusionRate immortals-diffusion    setxy random-int-or-float screen-size-x random-int-or-float screen-size-y  ]  do-plotendto go  ask patches [set mortalPop count mortals-here]  ask mortals [    moveMortal    reproduce    death  ]   ask immortals [    moveImmortal  ]  do-plot  ;; plot populations    set ticks ticks + 1  set total-mortals count mortals  if total-mortals > max-mortals [set max-mortals total-mortals]   if total-mortals = 0 [ stop ]  if limit-mortals and (total-mortals > upper-threshold) [stop]endto moveMortal  ;; turtle procedure  if random-int-or-float 100 < diffusionRate [  ;; code for random movement   ;; rt random 50 - random 50  ;; code for gradient movement    set heading downhill mortalPop    fd 1   ]end  to moveImmortal  ;; turtle procedure  if random-int-or-float 100 < diffusionRate [  ;; code for random movement   ;; rt random 50 - random 50  ;; code for gradient movement    set heading downhill immortalPop    fd 1   ]endto reproduce  ;; mortals procedurelocals [births]  set births count immortals-here               if births > 0   [                                 if random-int-or-float 100 < birthRate [  ;; throw "dice" to see if you will reproduce        hatch births [ moveMortal ]   ;; hatch an offspring and move it   ]]end to death  ;; turtle procedure  if random-int-or-float 100 < deathRate [ die ] endto do-plot   set-current-plot "populations"  set-current-plot-pen "mortals"   plot count mortals   set-current-plot-pen "immortals"  plot count immortalsend; Altarum copyright notice; Copyright Altarum Institute, 2003. All rights reserved.; Converted from StarLogoT to NetLogo, 2000.; 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 Altarum Institute.; Contact Altarum Institute for appropriate licenses for redistribution for; profit.; To refer to this model in academic publications, please use:; H.V.D. Parunak (2003).  Discrete Life Model.; http://www.erim.org/~vparunak/models/DiscreteLife.nlogo .; Altarum Institute, Ann Arbor, MI; The author may be contacted at van.parunak@altarum.org ; Altarum copyright notice@#$#@#$#@GRAPHICS-WINDOW4861082036540404.0110111CC-WINDOW480380823507Command CenterSLIDER987172120init-mortalsinit-mortals025025011NILSLIDER8130180163mortals-diffusionmortals-diffusion0.010025.011NILSLIDER8172182205mortals-death-ratemortals-death-rate01001111NILSLIDER20488358121init-immortalsinit-immortals02505011NILSLIDER8213190246mortals-birth-ratemortals-birth-rate0.010085.011NILBUTTON11168049setupsetupNIL1TOBSERVERTBUTTON961616349gogoT1TOBSERVERTPLOT11384312581populationstimepop.0.0100.00.0100.0truetruePENS"mortals" 1.0 0 -16776961 true"immortals" 1.0 0 -65536 trueMONITOR67325149374mortalscount mortals31MONITOR160325242374immortalscount immortals31TEXTBOX386117880Mortals settingsTEXTBOX2306234380Immortals settingsMONITOR1132561374ticksticks01SLIDER204130381163immortals-diffusionimmortals-diffusion01001411NILMONITOR254327326376balancemortals-birth-rate * init-immortals / (screen-size-x * screen-size-y) - mortals-death-rate01SLIDER2041737650background-colorbackground-color01395011NILSLIDER8287180320upper-thresholdupper-threshold0100001000101NILMONITOR337326418375max-mortalsmax-mortals01SWITCH8250128283limit-mortalslimit-mortals11-1000@#$#@#$#@WHAT IS IT? -----------NetLogo encourages the development of entity-based or agent-based models. Many of the systems for which NetLogo models are popular have also been modeled with alternative methods, such as systems of differential equations. The differences between these broad classes of techniques are non-trivial and of great importance to practicing modelers (Parunak et al. 1998).This model illustrates one such difference, identified by Shnerb et al. 2000. They present a simple scenario consisting of two interacting populations.* Immortals are never born and never die. They move by diffusion (modeled in NetLogo by invoking DOWNHILL on their concentration) at a velocity specified by IMMORTALS-DIFFUSION.* Mortals die, are born, and move. Their movement is by diffusion (driven by the concentration of other mortals). The probability that a mortal will die at a given time step is MORTALS-DEATH-RATE (expressed as 100 * the probability). Birth requires the presence of an immortal on the same patch. The probability that a mortal occupying a patch with an immortal will reproduce is given by MORTALS-BIRTH-RATE. The differential equations capturing this behavior are quite simple. Their solution predicts that the long-term population of mortals will grow without limit if MORTALS-BIRTH-RATE * the density of the immortal population is greater than MORTALS-DEATH-RATE, and go to zero if the product is less than the death rate. Shnerb et al. observe that this prediction is sometimes violated by an agent-based model of the same scenario. The reason is that the distribution of agents is not homogeneous. New mortals are not randomly distributed over the territory, but are born in the vicinity of their "father" immortals, and thus have a higher chance to encounter an immortal (namely, their father) than the mean field approximation would suggest. I built this model to see how robust this effect is and gain experience with its dynamics.HOW TO USE IT -------------1. Adjust the slider parameters (see below), or use the default settings.2. Press the SETUP button.3. Press the GO button to begin the simulation.4. View the POPULATIONS plot to watch the populations fluctuate over time5. The BALANCE window shows the difference (BIRTH-RATE * IMMORTAL-DENSITY) - DEATH-RATE. The equation-based mean-field theory predicts that the population should grow if this is positive and go to zero if it is negative.Parameters (all probabilities are expressed as whole-number percentages, and compared with random-int-or-float 100 to make decisions)BACKGROUND-COLOR: Default is black, but on some screens, the blue turtles (mortals) may be hard to see, so you can use this slider to adjust the background.INIT-MORTALS: The initial size of the population of mortals (default 250)INIT-IMMORTALS: The (constant) size of the population of immortals (default 50)MORTALS-DIFFUSION: The probability that a mortal will move a step on a given round (thus approximates velocity in patches-per-step) (default 25)IMMORTALS-DIFFUSION: The probability that an immortal will move a step on a given round (thus approximates velocity in patches-per-step) (default 14)MORTALS-DEATH-RATE: The probability that a mortal will die on a given step (default 15)MORTALS-BIRTH-RATE: The probability that a mortal sharing a patch with an immortal will give birth on a given step (default 85)UPPER-THRESHOLD: If the LIMIT-MORTALS switch is on, the model will stop when the mortal population reaches this level, making it easier to count runs at different population levels (see below). THINGS TO NOTICE ----------------The default settings give a balance of -14, predicting extinction, but in many runs the population of mortals explodes. In other runs for the same balance, the population collapses. You may need to press SETUP several times before finding an initial distribution of agents that permits the explosion of mortals.Explosion is not necessarily monotonic. The population of mortals can grow very large (10,000 or more, in which case the model slows down significantly!), and yet subsequently collapse.THINGS TO TRY------------- Try adjusting the parameters under various settings. How sensitive is the stability of the model to the particular parameters?You might count the proportion of setups that permit the population of mortals to grow to a certain threshold, as a function of the balance. What is the shape of this curve? How does diffusion speed affect the likelihood of a boom in mortals?EXTENDING THE MODEL-------------------What happens if we introduce a gestation period, by requiring a certain number of time steps to pass between a meeting between a mortal and an immortal, and the birth of the new mortal?What if new mortals are not born in the vicinity of their parents, but rather are assigned to a random location in the terrain?What happens if we make the immortals mortal? NETLOGO FEATURES----------------Note the use of breeds to model two different kinds of "turtles": mortals and immortals. DOWNHILL is a very easy way to model diffusion. (It would be nice to have a version of this primitive that makes the movement decision, not deterministically, but stochastically, selecting direction based on a roulette wheel whose segments are sized according to some function of the density to which DOWNHILL is responding.)RELATED MODELS---------------This model was constructed by beginning with the Wolf-Sheep predation model in the NetLogo distribution (Wilensky 1998), and retains much of its structure for dealing with interacting populations. (The logic is, of course, quite different.)CREDITS AND REFERENCES----------------------H. V. D. Parunak, R. Savit, and R. L. Riolo. Agent-Based Modeling vs. Equation-Based Modeling: A Case Study and Users' Guide. In Proceedings of Multi-agent systems and Agent-based Simulation (MABS'98), 10-25, Springer, 1998.N. M. Shnerb, Y. Louzoun, E. Bettelheim, and S. Solomon. The importance of being discrete: Life always wins on the surface. Proc. Natl. Acad. Sci. USA, 97(19 (September 12)):10322-10324, 2000.U. Wilensky.  NetLogo Wolf Sheep Predation model. http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL, 1998.To refer to this model in academic publications, please use:H.V.D. Parunak.  Discrete Life Model. http://www.erim.org/~vparunak/models/DiscreteLife.nlogo . Altarum Institute, Ann Arbor, MI, 2003.@#$#@#$#@defaulttrue0Polygon -7566196 true true 150 5 40 250 150 205 260 250sheep-shapefalse15Rectangle -1 true true 90 75 270 225Circle -1 true true 15 75 150Rectangle -16777216 true false 81 225 134 286Rectangle -16777216 true false 180 225 238 285Circle -16777216 true false 1 88 92wolf-shapefalse0Rectangle -7566196 true true 15 105 105 165Rectangle -7566196 true true 45 90 105 105Polygon -7566196 true true 60 90 83 44 104 90Polygon -16777216 true false 67 90 82 59 97 89Rectangle -1 true false 48 93 59 105Rectangle -16777216 true false 51 96 55 101Rectangle -16777216 true false 0 121 15 135Rectangle -16777216 true false 15 136 60 151Polygon -1 true false 15 136 23 149 31 136Polygon -1 true false 30 151 37 136 43 151Rectangle -7566196 true true 105 120 263 195Rectangle -7566196 true true 108 195 259 201Rectangle -7566196 true true 114 201 252 210Rectangle -7566196 true true 120 210 243 214Rectangle -7566196 true true 115 114 255 120Rectangle -7566196 true true 128 108 248 114Rectangle -7566196 true true 150 105 225 108Rectangle -7566196 true true 132 214 155 270Rectangle -7566196 true true 110 260 132 270Rectangle -7566196 true true 210 214 232 270Rectangle -7566196 true true 189 260 210 270Line -7566196 true 263 127 281 155Line -7566196 true 281 155 281 192@#$#@#$#@NetLogo 2.0.0@#$#@#$#@@#$#@#$#@@#$#@#$#@

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?