Search code examples
netlogoagent-based-modelingmulti-agent

Netlogo - updating outlinks with turtles outside the network


I need to learn NetLogo rather quickly, so I turned here for help. I have spent quite a bit of time trying to solve this issue but I think anyone a bit more experienced will be able to help.

I am creating a network of influence for turtles, that needs to adapt itself randomly every so often. I have used the following command which works well:

ask turtles [create-links-to n-of (S) other turtles]

Where S is my total number of turtles. I use links-to because one turtle is influenced by another one but doesn't necessarily influence that other one. So far so good. The problem is that I need to make network updates also, so that with a 5% probability the turtles adjust their network by killing one of the links and creating a new one with someone outside their network. The following lines:

if random 101 < 5 [
  create-links-to n-of 1 other turtles
  ask one-of links [die]
]

don't really do the trick because the turtle may endup choosing one of the existing links with throughout the simulation ends up reducing the total number of links in the network, which should remain stable.

Any thoughts ?

Thanks a lot, Pedro


Solution

  • I can't test this, but you will want something like:

    if random 100 < 5
    [ let target one-of (other turtles with [not member? self link-neighbors])
      ask one-of links [die]
      create-links-to target
    ]
    

    The not member? self link-neighbors excludes all the turtles already linked to. The reason there is a selection followed by death followed by creation is to avoid the creation and death being the same link.

    I also cleaned up your code slightly. First, one-of does the same as n-of 1 but is a little easier to read. Second, random 101 generates any of 101 random numbers (0, 1, 2, ... 100) so 5/101 is less than 5%. So I changed the 101 to 100. Note that it's often easier to use random-float 1 < 0.05 so you can use the same code structure for any probability.