问题
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