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

霸气de小男生 提交于 2019-12-18 09:05:56

问题


how to randomly select among all the neighbour patches that are higher instead of the highest neighbour patch? I was thinking to remove (if elevation >= [elevation] of max-one-of neighbors [elevation] [stop]) and place "[stop]" in [move-to-one-of 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

回答1:


one-of randomly selects an agent from the agentset and with creates an agentset of those agents satisfying the condition. You will also need to test that there is at least one location to go to. The selection would look like this (with threshold condition to be determined):

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

If you are instead wanting to choose amongst the higher neighbours regardless of whether they are higher than some threshold, you want max-n-of. Looks like this to choose one of the 3 highest:

to move-up
  move-to one-of max-n-of 3 neighbors [elevation]
end



回答2:


; 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


来源:https://stackoverflow.com/questions/34081116/how-to-randomly-select-a-neighbor-patch-that-has-a-higher-elevation-in-netlogo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!