如何从网络中提取高度链接的节点

How to extract a highly linked node from a network

我想从网络中提取中心度最高的节点。我不想提取仅具有最大链接的节点。我想提取节点以及与其相邻的节点。

下面是代码。在这段代码中,我使用 nw 扩展加载了一个网络。

    extensions [nw]

    turtles-own [ explored? ]

    to setup
      ca
      crt 25
      ask turtles [fd random 15]
      load-graph
      extract_deg
    end


    to load-graph
      let filename user-file
      if (filename != false) [
        nw:load-graphml filename [
          set shape "circle"
          set size 1
        ]
        nw:set-context turtles links
      ]
    end


    to extract_deg
      let n turtles with [my-links = max [count link-neighbors] of turtles]
      ask n [show other turtles network:in-link-radius 1 turtles]
    end

    to layout
      ask turtles [ set size sqrt count my-links ]
      layout-spring turtles links 0.5 2 1 
      ask turtles [
      facexy 0 0
      fd (distancexy 0 0) / 100 ]
    end

下面的代码将选择度数最大的节点之一(如果需要所有节点,只需删除 one-of),将其变为红色并使其网络邻居变为绿色。

您不需要表达式 [my-links = max [count link-neighbors] of turtles],标准 NetLogo 包含非常有用的 with-max 原语。但是,我认为如果您计算了我的链接(例如 let n turtles with [count my-links = max [count link-neighbors] of turtles]),您的构造就会成功。然后你在下一行有一些语法错误(扩展名是 nw 而你不需要 turtles.

to extract_deg
  let maxk-set one-of turtles with-max [count my-links]
  ask maxk-set
  [ set color red
    ask other nw:turtles-in-radius 1 [set color green]
  ]
end