如何随机 select 一个在 netlogo 中具有更高海拔的邻居补丁

how to randomly select a neighbor patch that has a higher elevation in netlogo

如何在所有相邻补丁中随机 select 而不是最高的相邻补丁? 我正在考虑删除(如果海拔> = [海拔] of max-one-of neighbors [elevation] [stop]) 并将“[stop]”放置在[move-to-one-one-neighbors [stop]]

to move ; a turtle procedure

if elevation >= [elevation] of max-one-of neighbors [elevation] [stop]


ifelse random-float 1 < q
[uphill elevation]
[move-to one-of neighbors]

end

one-of 从代理集中随机选择一个代理,with 创建满足条件的代理集。您还需要测试是否至少有一个位置可以去。选择将如下所示(阈值条件待定):

to move-up ; a turtle procedure
  let candidates neighbors with [elevation >= <thresholdhold condition> ]
  if any? candidates [ move-to one-of candidates]
end

如果您想要在较高的邻居中进行选择,而不管它们是否高于某个阈值,您需要 max-n-of。看起来像这样选择最高的 3 个之一:

to move-up
  move-to one-of max-n-of 3 neighbors [elevation]
end
; The butterfly move procedure in turtle context
to move ; a turtle procedure
  if elevation >= [elevation] of max-one-of neighbors [elevation] [stop]
  ; Decide whether to move uphill deterministically with probability q
  ifelse random-float 1 < q
   [ uphill elevation ] ; move uphill
   [ move-to one-of neighbors ] ; otherwise move randomly
   set patches-visited patches-visited + 1
end