简体   繁体   中英

Intersection of two lists in NetLogo

I need to calculate the size of the intersection of two lists in NetLogo. Here is my working example:

to calculate-intersection
ask turtles
 [ set first-list ( list turtles-on link-neighbors )
   foreach first-list <br>
    [ set second-list ( list turtles-on link-neighbors )
      set intersection intersection + count ( first-list with [ member? self second-list ] )]]
end

I have a network and I want to know how many of the nodes A is linked to are also linked between themselves. That is:

In a network of 5 nodes: A , B , C , D and E :

  1. Node A is linked to BCDE
  2. Node B is linked to D
  3. Node D is linked to B

Then I want intersection for Node A = 2

I have tried many different ways unsuccessfully.

I think this shows what you are asking for.

ask turtles [ 
  let nbrs1 link-neighbors
  show sum [count other nbrs1 with [link-neighbor? myself]] of nbrs1
]

You might be able to gain some efficiency using nw:with-context . (Maybe you could even use nw:clustering-coefficient instead?)

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