如何在Netlogo中找到无向网络中的所有三角形,即列出A-B,B-C,C-A的所有实例?
谢谢,
托马斯
答案 0 :(得分:3)
这是一种相当天真的方法。如果您的网络不是太大,那就足够了:
to-report find-triangles
let triangles (list)
ask turtles [
let t1 self
; find all the triangles that the turtle is a part of
ask link-neighbors [
let t2 self
ask link-neighbors [
let t3 self
if link-with t1 != nobody [
set triangles lput (turtle-set t1 t2 t3) triangles
]
]
]
]
report remove-duplicates triangles
end
让我们用一个简单的网络测试它:
to setup
clear-all
create-turtles 4
ask turtle 0 [
create-link-with turtle 1
create-link-with turtle 2
]
ask turtle 1 [
create-link-with turtle 2
]
ask turtle 3 [
create-link-with turtle 1
create-link-with turtle 2
]
ask turtles [ set label who ]
repeat 30 [ layout-spring turtles links 0.2 5 1 ]
show map sort find-triangles
end
从命令中心,结果是:
observer> setup
observer: [[(turtle 1) (turtle 2) (turtle 3)] [(turtle 0) (turtle 1) (turtle 2)]]