我搜索了上周的所有主题,但仍无法找到解决问题的方法。该方案如下: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