1
一個簡單的問題,但我完全失敗。麻煩使用與分
我有一羣需要找到最近鄰居的海龜,因爲我希望在它們之間創建一個鏈接。我試着下面的代碼,但我一直有一個空集回來[誰也沒有找到]:
ask turtles [create-links-with one-of other turtles with-min [distance myself]]
可有人請點我在正確的方向。
問候
西蒙
一個簡單的問題,但我完全失敗。麻煩使用與分
我有一羣需要找到最近鄰居的海龜,因爲我希望在它們之間創建一個鏈接。我試着下面的代碼,但我一直有一個空集回來[誰也沒有找到]:
ask turtles [create-links-with one-of other turtles with-min [distance myself]]
可有人請點我在正確的方向。
問候
西蒙
這裏有兩個問題。
一個是create-links-with
錯誤,因爲one-of
返回單個代理程序,而不是代理程序集。你需要create-link-with
。
但主要問題是這一部分:
other turtles with-min [...]
的NetLogo明白這是other (turtles with-min [...])
。這會報告一個空的代理程序集,因爲烏龜本身贏得with-min
競爭對手,因爲它的距離爲零,然後other
消除該烏龜,留下空的代理程序集。
相反,你必須寫:
(other turtles) with-min [...]
所以既修復在一起,我們得到:
ask turtles [
create-link-with one-of (other turtles) with-min [distance myself]
]
如果你想,這可以進一步再利用min-one-of
代替with-min
縮短,像這樣:
ask turtles [
create-link-with min-one-of other turtles [distance myself]
]
我做了一些海龜,並試過我T出在的NetLogo的指揮中心,和我:
真棒 - 感謝賽斯 –