gpt4 book ai didi

netlogo - 如何将幂律可能性添加到 Netlogo 模型

转载 作者:行者123 更新时间:2023-12-05 05:26:06 25 4
gpt4 key购买 nike

我想在 power law 之后的环境 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

最佳答案

这只是对@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

关于netlogo - 如何将幂律可能性添加到 Netlogo 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28212700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com