NetLogo - 将沙堆模型中的沙粒分配给随机邻居
NetLogo - Distributing grains of sand in sandpile model to random neighbours
此代码与 NetLogo 沙堆模型的改编有关。当每个补丁中的 go grains 计数超过阈值(在本例中为 3)时,grains 将重新分配给周围的邻居。我正在尝试将一粒谷物重新分配给 4 个随机相邻的补丁。
代码 returns 一个 运行 时间错误,因为边缘的补丁不会有所有 8 个邻居,所以当询问 4 个随机邻居时它 returns 一个错误说明可以不向 3 等请求 4 个赎金代理
我正在尝试找到一段代码来解决这个问题。
****代码如下*****
to-report stabilize [animate?]
let active-patches patches with [ n > threshold ]
;; The number iterations the avalanche has gone for. Use to calculate lifetimes.
let iters 0
;; we want to count how many patches became overloaded at some point
;; during the avalanche, and also flash those patches. so as we go, we'll
;; keep adding more patches to to this initially empty set.
let avalanche-patches no-patches
while [ any? active-patches ] [
let overloaded-patches active-patches with [ n > threshold ]
if any? overloaded-patches [
set iters iters + 1
]
ask overloaded-patches [
set base-color fired-color
;; subtract 'threshold' amount from this patch
update-n -4
if animate? [ recolor ]
;; edge patches have less than four neighbors, so some sand may fall off the edge
ask n-of 4 neighbors [
update-n 1
if animate? [ recolor ]
]
]
if animate? [ display ]
;; add the current round of overloaded patches to our record of the avalanche
;; the patch-set primitive combines agentsets, removing duplicates
set avalanche-patches (patch-set avalanche-patches overloaded-patches)
;; find the set of patches which *might* be overloaded, so we will check
;; them the next time through the loop
set active-patches patch-set [ neighbors ] of overloaded-patches
]
report (list avalanche-patches iters)
end
与其询问 4 个邻居,不如询问 min list 4 count neighbors
:
ask n-of (min list 4 count neighbors) neighbors [
...
]
但是从模型的角度来看,table的边缘会有不同的重分布,所以这不是一个好主意。也许最好有一个包裹的世界,然后手动 "push" 关闭 table: select 4 个邻居的颗粒,并只调用具有接近 pxcor 和 pycor 的那些。剩下的就关了table.
如果世界被包裹起来(水平和垂直),我们总是可以 select 4 个邻居:
let selected-neighbors n-of 4 neighbors
在这 4 个邻居中,只有真正的邻居在 table
set selected-neighbors selected-neighbors with [
(abs (pxcor - [ pxcor ] of myself) < 2)
and
(abs (pycor - [ pycor ] of myself) < 2)
]
ask selected-neighbors [
....
]
此代码与 NetLogo 沙堆模型的改编有关。当每个补丁中的 go grains 计数超过阈值(在本例中为 3)时,grains 将重新分配给周围的邻居。我正在尝试将一粒谷物重新分配给 4 个随机相邻的补丁。
代码 returns 一个 运行 时间错误,因为边缘的补丁不会有所有 8 个邻居,所以当询问 4 个随机邻居时它 returns 一个错误说明可以不向 3 等请求 4 个赎金代理
我正在尝试找到一段代码来解决这个问题。
****代码如下*****
to-report stabilize [animate?]
let active-patches patches with [ n > threshold ]
;; The number iterations the avalanche has gone for. Use to calculate lifetimes.
let iters 0
;; we want to count how many patches became overloaded at some point
;; during the avalanche, and also flash those patches. so as we go, we'll
;; keep adding more patches to to this initially empty set.
let avalanche-patches no-patches
while [ any? active-patches ] [
let overloaded-patches active-patches with [ n > threshold ]
if any? overloaded-patches [
set iters iters + 1
]
ask overloaded-patches [
set base-color fired-color
;; subtract 'threshold' amount from this patch
update-n -4
if animate? [ recolor ]
;; edge patches have less than four neighbors, so some sand may fall off the edge
ask n-of 4 neighbors [
update-n 1
if animate? [ recolor ]
]
]
if animate? [ display ]
;; add the current round of overloaded patches to our record of the avalanche
;; the patch-set primitive combines agentsets, removing duplicates
set avalanche-patches (patch-set avalanche-patches overloaded-patches)
;; find the set of patches which *might* be overloaded, so we will check
;; them the next time through the loop
set active-patches patch-set [ neighbors ] of overloaded-patches
]
report (list avalanche-patches iters)
end
与其询问 4 个邻居,不如询问 min list 4 count neighbors
:
ask n-of (min list 4 count neighbors) neighbors [
...
]
但是从模型的角度来看,table的边缘会有不同的重分布,所以这不是一个好主意。也许最好有一个包裹的世界,然后手动 "push" 关闭 table: select 4 个邻居的颗粒,并只调用具有接近 pxcor 和 pycor 的那些。剩下的就关了table.
如果世界被包裹起来(水平和垂直),我们总是可以 select 4 个邻居:
let selected-neighbors n-of 4 neighbors
在这 4 个邻居中,只有真正的邻居在 table
set selected-neighbors selected-neighbors with [
(abs (pxcor - [ pxcor ] of myself) < 2)
and
(abs (pycor - [ pycor ] of myself) < 2)
]
ask selected-neighbors [
....
]