Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
705 views
in Technique[技术] by (71.8m points)

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

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...