3

I would like to add a likelihood of natural disaster in my environmantal ABM that follows the power law (often few damage, less often mediocre damage, rarely strong damage, very rarely complete damage).

I coded so far the following:

to environment ;environmental hits
   create-hits 1 [ ; I do not know if it makes sense to do that?
     set shape "circle"
     set color white
     set size 0.05
     setxy random-xcor random-ycor
   ]
   ask hits [
     ifelse pcolor = red [die] ;if already red, then stop
     [ ask n-of random (count patches) patches [ set pcolor red ]]  ;otherwise turn red on an random amount of patches
   ]
end

Now, I do not know how to add the stochastic element of how strong the "hit" can be (thus, how much patches can be affected) and how likely (according to the power law) it is to happen (or not to happen) each tick. Can somebody help me out?

This is the final code (answered by Alan):

to environment 
   create-hits 1 [
     set shape "circle"
     set color white
     set size 0.05
     setxy random-xcor random-ycor
   ]
   ask hits [
     let %draw (random-float 100)
     let %strength 0  ;; no damage
     if (%draw < 50) [set %strength (%strength + 1)]  ;;1 for little damage
     if (%draw < 10) [set %strength (%strength + 1)]  ;;2 for middle damage
     if (%draw < 5) [set %strength (%strength + 1)]  ;;3 for strong damage
     if (%draw < 1) [set %strength (%strength + 1)]  ;;4 for complete destruction

     ifelse pcolor = red [die]
     [ ask n-of %strength patches [ set pcolor red ]]
   ]
end
Til Hund
  • 1,543
  • 5
  • 21
  • 37
  • 2
    It's not clear what what the strength of a hit is. However, there are several random-number generating functions in NetLogo, named `random` and `random-`something. To take the simplest kind of case, if you want the probability of something happening to be 0.73, you can say `if random-float 1 < 0.73 [...]`. The numbers returned by `random-float` follow a uniform distribution, but there are other functions that provide other distributions. Then figure out the math to construct the probability distribution you want from one of NetLogo's random functions. (That isn't really a NetLogo problem.) – Mars Jan 30 '15 at 05:01

1 Answers1

2

This is just an elaboration of the comment by @Mars.

to-report hit-strength
  let %draw (random-float 100)
  let %strength 0  ;; no damage
  if (%draw < 50) [set %strength (%strength + 1)]  ;;1 for little damage
  if (%draw < 10) [set %strength (%strength + 1)]  ;;2 for middle damage
  if (%draw < 5) [set %strength (%strength + 1)]  ;;3 for strong damage
  if (%draw < 1) [set %strength (%strength + 1)]  ;;4 for complete destruction
  report %strength
end
Alan
  • 9,410
  • 15
  • 20