我搜索了上週的所有主題,但仍無法找到解決問題的方法。該方案如下:NetLogo:找出所有相互關聯的龜並將它們分配給組ID
- 我有鏈接到海龜的各種團體相互
- 我想給一組名稱或ID分配給每個組
爲了做到上面,我想我需要一個程序來找出一隻烏龜的身份證,然後告訴我這隻烏龜與哪隻其他烏龜有聯繫。例如,我有一組4只烏龜,所有這些烏龜都相互關聯。他們的ID是1,2,3,4。現在我想列出每隻烏龜,這也告訴我它與誰聯繫。這裏的一個例子列表:
Turtle 1 -> Linked to Turtle 2, 3 and 4
Turtle 2 -> Linked to Turtle 1, 3 and 4
...
Turtle 4 -> Linked to Turtle 1, 2 and 3
一旦我現在這(儘管也許有一個更簡單的方法)。我可以給這4只海龜分配一個組ID。
任何意見/幫助非常感謝。
下面是部分代碼:
to go
ask turtles [
set neighbours turtle-set turtles in-radius neighbourhood
set turtle-dim-similar min-one-of other neighbours [myfunc myself self]
create-link-with turtle-dim-similar
]
set beasts sort-by [[who] of ?1 < [who] of ?2] turtles
foreach beasts [
ask ? [ ;; each agent undertakes the list of commands
set closest sort [link-neighbors] of turtle who
print (word "id:" who " ; val1:" value1 " ; val2:" value2 " ; closest:" closest)
]
]
end
Out-link-neighbors給出了鏈接到的一組烏龜。 – 2014-10-31 01:02:24
非常感謝您的回覆。我曾嘗試使用out-link-neighbors和各種變體,但我不斷收到「品種」錯誤。我沒有在模型中定義任何品種,因爲我不需要它們。稍後會發布一些示例代碼... – Tina 2014-10-31 10:53:35
它是「鏈接是無向品種」嗎?如果是這樣,請嘗試鏈接鄰居或確保您使用「create-link-with」來製作它們。 – 2014-10-31 11:18:54