简体   繁体   中英

Community detection in NetLogo

Does anyone have any code to detect communities in NetLogo by some attribute, let's say colour? By community I mean a group of turtles of the same colour surrounded by turtles of other colours. It's easy to do visually when the world doesn't wrap but viciously difficult when it does.

To be clear, there could be two distinct red communities that I would like to count as two (like islands in a sea of blue), and I've got multiple (more than two) colours.

If I set a link between a turtle and it's neighbour, if they are of the same colour, then using the Networks Extension I can do this using nw:weak-component-clusters. I just then need to count the number of items in the resulting list.

breed [people person]
to communities
ask links [die]
ask people [ask people-on neighbors [if color = [color] of myself [create-link-with myself]]]
nw:set-context people links
show length nw:weak-component-clusters
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM