How to identify triangles in Netlogo -
how can find triangles in undirected network in netlogo, is, list instances of a-b, b-c, c-a?
thank you,
thomas
here naive approach. if network not big, enough:
to-report find-triangles let triangles (list) ask turtles [ let t1 self ; find triangles turtle 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
let's test simple network:
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 ] repeat 30 [ layout-spring turtles links 0.2 5 1 ] show map sort find-triangles end
from command center, result is:
observer> setup observer: [[(turtle 1) (turtle 2) (turtle 3)] [(turtle 0) (turtle 1) (turtle 2)]]
Comments
Post a Comment