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



我想从网络中提取具有最高度中心性的节点。我不想仅提取具有最大链接的节点。我想将节点与与之相邻的节点一起提取。

以下是代码。在此代码中,我使用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

最新更新