【问题标题】:Intersection of two lists in NetLogoNetLogo 中两个列表的交集
【发布时间】:2014-08-05 16:32:01
【问题描述】:

我需要计算 NetLogo 中两个列表的交集的大小。这是我的工作示例:

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

我有一个网络,我想知道 A 所链接的节点中有多少也相互链接。那就是:

在 5 个节点的网络中:ABCDE

  1. 节点 A 链接到 B C D E
  2. 节点 B 链接到 D
  3. 节点 D 链接到 B

然后我想要Node A = 2的交集

我尝试了很多不同的方法都没有成功。

【问题讨论】:

    标签: list netlogo set-intersection


    【解决方案1】:

    我认为这表明了您的要求。

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

    您可以使用nw:with-context 获得一些效率。 (也许您甚至可以改用nw:clustering-coefficient?)

    【讨论】:

    • other nw:turtles-in-radius 1 是否等同于 link-neighbors
    • 根据文档是:github.com/NetLogo/…
    • 顺便说一句,nw:with-context 在这里帮不上忙。它适用于您需要临时分析不同网络或在不同网络上运行多个永久按钮的特定情况。它对性能没有帮助。不过,保持在一种环境中确实有助于提高性能。 nw:clustering-coefficient 绝对应该更快(更不用说更简洁了)。如果不是,请报告,以便我们修复它!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 2014-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多