1

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

Thank you a lot.

JenB
  • 17,620
  • 2
  • 17
  • 45

2 Answers2

1

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

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

turtles-own [informed? 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 

but

one-of turtles with [id = 74]
King-Ink
  • 2,096
  • 12
  • 18
  • Thank you for your answer, I´m a beginner with this, so please excuse my following question: My modell is an exported gephi file and the nodes of the gephi file are shown as turtles in Netlogo (if I´m not mistaken), I need to use a specific node (which I idenified with gephi) to start the infection. How do I assign a new ID for that specific node? How can I be sure, that I don´t assign the new ID for a different node? – Gabriela Katrin Jan 20 '16 at 21:07
  • I am not terribly familiar with gephi but this question on may help http://stackoverflow.com/questions/24858226/exporting-netlogo-data-to-graph-with-nodes-and-edges – King-Ink Jan 20 '16 at 21:49
  • Do you use color for meaning? – King-Ink Jan 20 '16 at 23:43
  • If I understand correctly, Gabriela, you start a network that's in Gephi, and then you export the network in one of Gephi's file formats. Then you read that file into NetLogo. It should not be hard to set the value of the turtles-own `id` variable (which King-Ink suggested using) to a node id created by Gephi. – Mars Jan 21 '16 at 05:26
  • thank you all so much, I do use color for meaning (red showing a turtle being not informed yet and green showing turtles who are already informed) of course the beginning turtle is green. I tried your code, but sadly it doesn´t let me put in ask turtle with [id = 74] . I get the error: TURTLE expected 1 input, a number. And also the ID of every turtle still changes with every setup, which makes the infection start with a different turtle than I want to. All the turtles have labels but they aren´t numbers and I dont know if i can use the labels instead of the ID for identification. – Gabriela Katrin Jan 21 '16 at 09:55
  • So sorry use one-of turtles with[id = 74]. you could also use assuming the other turtles are not green one-of turtles with [color = green] – King-Ink Jan 21 '16 at 13:10
  • assuming that you set it to green in gelphi – King-Ink Jan 21 '16 at 14:07
1

I am a little unclear so am giving bits of different answers for different situations.

If the turtles are different each time, what do you mean by 'the same turtle'. For example, do you mean the turtle in a particular position? If so, you could select the turtle on the appropriate patch.

If it doesn't matter which particular turtle it is (just that it's the same turtle), then the simplest approach is to set the random-seed. Then every time you run any random process (including choosing one-of the turtles to select the starting infection, or ask turtles to do something), NetLogo will use the same chain of random numbers. Of course, if you are still building your model, then adding new pieces of code that change how many calls are made to the random number generator will lead to a different chain, but rerunning with the same code will give the identical run.

You may need to use with-local-randomness and random-seed new-seed if you want to have some parts actually change.

JenB
  • 17,620
  • 2
  • 17
  • 45