How to add power law likelihood to Netlogo Model

♀尐吖头ヾ 提交于 2019-12-12 21:37:22

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/28212700/how-to-add-power-law-likelihood-to-netlogo-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!