在Netlogo中遍历列表

在Netlogo中遍历列表,netlogo,Netlogo,在这里旋转我的轮子 我正在使用一个20K节点的网络,我想把它放到NetLogo中(最终目标是对模型库的简单病毒营销模型进行旋转)(这个工作很好!) 我已经使用Python预先编写了我想在Netlogo中使用的特定节点。例如,以下是我的图表中按中间值中心度排列的前20个节点的列表: 设置节点列表[“73647”“52658”“78667”“97632”“22987”“101425”“97788”“15439”“46269”“45942”“46016”“95372”“83259”“22757”“

在这里旋转我的轮子

  • 我正在使用一个20K节点的网络,我想把它放到NetLogo中(最终目标是对模型库的简单病毒营销模型进行旋转)(这个工作很好!)

  • 我已经使用Python预先编写了我想在Netlogo中使用的特定节点。例如,以下是我的图表中按中间值中心度排列的前20个节点的列表: 设置节点列表[“73647”“52658”“78667”“97632”“22987”“101425”“97788”“15439”“46269”“45942”“46016”“95372”“83259”“22757”“91392”“101355”“12915”“905”“95940”“88071”]

  • 这些节点表示按降序排序的图中的前20个节点 通过中间性中心性(在Python Networkx中大约25分钟到 得到这个)

所以,我想做的是:

  • 对于名为budget(n,0-19)的任意数字,取第一个n
    nodelist中的node_id(turtles自己的变量node_id)

  • 查找与节点\u id匹配的相应人员

  • 用谁的号码问一只乌龟做某事,例如[设定收养= 真的]


  • 非常感谢任何帮助或建议

    你可以用许多不同的方式浏览列表。 一种是使用“foreach”命令。 另一种方法是在索引编号上使用显式循环,从零开始

    这是他们两个的演示。 “安装程序”运行安装程序 “go”一旦找到物品,就把它们变大,并显示它们的标签 再“走”一次,它们又变小了

    globals [ NUMTURTLES BUDGET NODELISTSIZE nodelist ]
    turtles-own [ adopt?  node_id]
    
    to setup
      clear-all
      let rseed random 999999;
      print (word "random seed being used for this run is : " rseed );
      random-seed rseed;
      
      ;; globals or sliders, low values to see what's going on
      set BUDGET random  5;  ( 0 to 19 )
      set NUMTURTLES    30;
      set NODELISTSIZE  10; ;; something bigger than BUDGET!
      
      print (word "BUDGET = " BUDGET );
      
      
      create-turtles NUMTURTLES 
          [ setxy random-xcor random-ycor  
            set adopt? false 
            set node_id random 999999
           ]
      
      set nodelist [];
      ask N-of NODELISTSIZE turtles [ set nodelist lput node_id nodelist ]
      show nodelist;
      
      reset-ticks
    end
    
    to go
      if ( ticks = 0)
      [    ;; option #1: make a sublist and use the "foreach" command to walk down it
           let worklist sublist nodelist 0 BUDGET
           show worklist
           foreach worklist [ 
                 a -> print (word "next item in worklist " a)
             ask one-of turtles with [ node_id = a ] [ set adopt? true set size 3 set label a]
              ]
      ]
      
      ;; undo the above a different way
      
      if ( ticks = 1 )  
      [   ;; option #2:  use effectively for i = 0 to BUDGET to process list item i
          ;; do NOT forget the "set i ( i + 1 )" or this will run forever! 
          let i 0
          repeat BUDGET [
          let b item i nodelist
          print (word "item " i " which is " b " will be undone");
          ask one-of turtles with [ node_id = b ] [ set adopt? false set size 1 ]
          set i ( i + 1 )
          ]
        
      ]
      tick
    end
    

    你有没有尝试过拥有20000个节点的简单病毒式营销模式?网络扩展在计算介数方面可能与Python的Networkx一样快,然后您只需使用
    max-n-of
    创建代理集,而不用使用
    who
    数字列表