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

时间:2017-12-02 14:03:38

标签: netlogo

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

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

1 个答案:

答案 0 :(得分:2)

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

您不需要表达式[my-links = max [count link-neighbors] of turtles],标准NetLogo包含非常有用的with-max原语。但是,如果您计算了my-links(例如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