我想在遵循幂律的环境 ABM 中添加自然灾害的可能性(通常很少损坏,不太常见的中等损坏,很少有强烈的损坏,很少有完全损坏)。
到目前为止,我编写了以下代码:
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
现在,我不知道如何添加“命中”的强度(因此,可以影响多少补丁)以及发生(或不发生)的可能性(根据幂律)的随机因素) 每个刻度。有人可以帮帮我吗?
这是最终代码(由 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