使用Netlogo中的每个设置更改节点ID [英] Changing Node ID with every Setup in Netlogo

查看:172
本文介绍了使用Netlogo中的每个设置更改节点ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们尝试显示通过Netlogo进行的简单感染.为了我们的目的,我们需要多次用同一只乌龟开始感染. 但是现在,每次安装时,另一只乌龟都会开始感染.我们已经尝试使用Node ID,但是不幸的是,不同的Turtle的ID也会随着每次设置而改变.我们没有主意,但是 也许有办法解决这个问题,我很高兴得到任何答案:) 到目前为止,这是我们的代码:

We try to show a simple infection via Netlogo. For our purpose we need to start the infection with the same turtle for several times. But right now with every setup another turtle begins with the infection. We already tried to work with the Node ID, but unfortunately the ID of the different turtles changes with every setup, too. We are out of ideas but maybe there is a way to sove this problem I am happy for any answers :) This is our Code so far:

    extensions [nw]


    globals
    [
    num-informed
    informed-size
    ]

    turtles-own
    [
     informed?
     ]

    to setup
      clear-all
      nw:load-graphml "JK_nachnamen.graphml"
      ask turtles [ set size 1.5 ]
      layout-radial turtles links turtle 61
      ask turtles [set color red]
      ask turtles [set shape "dot"]
      ask links [set color grey + 1.5]
      ask patches [set pcolor white]
      ask turtles [set label-color black]
      ask turtles [set informed? false]
      ask turtle 72
      [
       set informed? true
        set color green
      ]
      set num-informed 1
      set informed-size 2
      reset-ticks
       nw:save-graphml "JKnachnamennetlogo.graphml"
    end

   to spread
if (count turtles with [informed? = true] > .7 * count turtles)    [stop]
    ask turtles with [ informed? = true ]
     [
        ask link-neighbors with [not informed?]
       [
         if (random-float 1 <= 0.01)
       [
         set informed? true
         show-turtle
        set color green
       ]
       ]
       ]

  set num-informed count turtles with [informed? = true]
   tick
  end

非常感谢您.

推荐答案

问题在于nw不存储WHO变量,这是为了避免与模型中已经存在的海龟发生冲突.

The problem is that nw does not store the WHO variable this is to avoid conflict with already existing turtles in a model.

一种解决方法是为每个乌龟分配一个单独的id变量,并将其设置为who.

A work-around would be assigning each turtle a separate id variable and setting that to who.

turtles-own [informed? id]

在创建海龟时,每个人都会为其分配一个ID

in turtles creation asign them each the id thus

set id who

您可能要编写这样的转换过程

you may want to write a conversion procedure like this

to convert 
   nw:load-graphml "JK_nachnamen.graphml"
   ask turtles [set id who]
   nw:save-graphml file-name "JK_nachnamen(id).graphml"
end

并使用副本.当然,您不会使用

and use the copy. Of course you would not use

turtle 74 

但是

one-of turtles with [id = 74]

这篇关于使用Netlogo中的每个设置更改节点ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆