在 NetLogo 中构建自组织网络的困难

Difficulty in building a self-organized network in NetLogo

我是 netlogo 的新手,我正在尝试建立一个网络,其中的节点有一个随每个滴答而变化的随机数,并随机连接到其他节点。建立连接后,我需要:如果两个节点之间的数字相同,则 link 结晶并改变颜色,否则在该刻度中删除它,重复该过程,直到所有节点具有相同的随机数价值。 提前致谢

根据评论中的说明...

你提到的事情可以用一个相当简单的方法来完成,所以希望你可以使用下面的解释和关键字来浏览 NetLogo 手册(尤其是 NetLogo 词典)并完全熟悉正在发生的事情.

首先,让我们设置一些东西

globals [
; You'll probably want to declare these two variables directly
; in the Interface with a slider or something, but here I'll
; set them up from within the Code section.

 number-of-turtles
 level-of-randomness 
]

turtles-own [
 my-number
 connected?
]


to setup
  clear-all
  reset-ticks
  
  set-globals
  
  create-turtles number-of-turtles [
   setxy random-xcor random-ycor
   set connected? false
  ]
end


to set-globals
  set number-of-turtles 500
  set level-of-randomness 1000
end

到目前为止,您有许多分散在环境中的海龟、几个每个人都可以访问的全局变量,以及属于每个海龟的几个变量以跟踪它们的状态。

根据您的描述逐字逐句,您可以继续为:

to go.v1
; This first block of commands below is to get rid of the links that
; emerged in the previous iteration of 'go.v1', but that
; you don't want to keep because they link turtles with
; different 'my-number'. You will also need to include the
; stop condition that best suits you.
  ask links with [color != green] [
   die
  ]

; Insert here a stop condition.

  ask turtles with [connected? = false] [
   set my-number random level-of-randomness
  ]

; The 'let' command creates a local variable.
  ask turtles [
   let target one-of other turtles
   create-link-with target

; The statement below containing "[who] ..." is how you need to
; call a link: 'who' is a built-in turtle-own variable reporting
; the ID number of the turtle, and to report a link you will need
; to give it the two IDs of the two turtles being connected.

   if (my-number = [my-number] of target) [
     ask link ([who] of self) ([who] of target) [
       set color green
      ]
     if (connected? = false) [
       set connected? true 
      ]
     if ([connected?] of target = false) [
       ask target [
         set connected? true
        ]
      ]
    ]
  ]
  tick
end

上面的代码按照你说的做了:每只乌龟总是用另一只乌龟创建link,然后测试条件,并基于该条件(结果存储为link 的颜色:只有好的 link 变成 green) link 在 go.v1.[=18= 的下一次迭代开始时被保留或消除]

但是,尽管您可能有理由按照上述方式进行操作,但您可能只是对需要较少计算的替代方案感到满意:

to go.v2
  ; Insert here a stop condition.
  
  ask turtles with [connected? = false] [
   set my-number random level-of-randomness
  ]

  ask turtles [
   let target one-of other turtles
    
   if (my-number = [my-number] of target) [
     create-link-with target [
       set color green
       ask both-ends [
         if (connected? = false) [
           set connected? true
          ]
        ]
      ]
    ]
  ]
  tick
end

这样,海龟在创建任何 link 之前评估潜在的伙伴,并且只有在 my-number 相同时它们才会继续创建它。 这样,就不需要创建然后消除所有不需要的 link(并且即使在 go.v1 中也必须测试 my-number 条件)。