2015-04-27 49 views
3

我想用半徑或距離定義鄰居。我的解決方案迄今:使用半徑或距離定義鄰居海龜

turtles-own [ 
    my-neighbors 
    num-neighbors] 

to setup 

ca 
crt 100 [ 
    move-to one-of patches with [ not any? turtles-here ] 
    set my-neighbors (other turtles) in-radius 3 
    set num-neighbors count my-neighbors 
] 

end 

這樣做的問題是,大多數龜有0〜4鄰國之間,但也有少數人有一個比較龐大的鄰國(例如,34和65)的數量。這些烏龜靠近世界的中心。

任何關於我在做什麼的想法都是錯誤的?

+2

這是一個很好的最低工作示例和問題的清晰描述一個非常好的問題。我不明白爲什麼有人會爲此投票。 –

回答

3

它與你的程序中副作用的時間有關。

假設第一隻移動的烏龜在中心附近移動。其他龜沒有移動,所以他們仍然在patch 0 0set my-neighbors (other turtles) in-radius 3將捕獲所有。即使他們移動到其他地方,它們仍將被包含在第一隻海龜的代理組中。

您可以通過第一避免此問題將所有的海龜然後計算他們的鄰居:

to setup 
    clear-all 
    crt 100 [ 
    move-to one-of patches with [ not any? turtles-here ] 
    ] 
    ask turtles [ 
    set my-neighbors (other turtles) in-radius 3 
    set num-neighbors count my-neighbors 
    ] 
end