netlogomulti-agent

Netlogo, changing link-with to link-to


I am trying to create a network of influence for my turtles on my setup. Each turtle has an AD variable randomly set between 0 and 1.Each of them will create 5 undirected links. Now if they have AD low (below 0.3), they should look for someone with high AD in their network (above 0.7) and create a link to that person (to become a follower).

I have tried with this code which doesn't work because some networks will not have anyone with AD > 0.7 and so when trying to kill the link I get runtime. Would anyone know a way around it? (Specially if we can avoid the two-step process and directly create links-to when the condition is met).

to setup
  ask turtles [
    create-links-with n-of 5 other turtles 
    if (AD < 0.3) [
      let target one-of (other turtles with [link-neighbor? myself and (AD > 0.7)])
    ask link-with target [die]
      create-link-to target
    ]
    ]

Thanks!


Solution

  • From your code I think you want (1) every agent to make links with 5 others (so on average they will all have 10, since they will also get links from others). (2) if own AD is low, then at least one of the links is with a high value AD node. The following code creates one link (with the AD if needed) and then another 4.

    to setup
      ask turtles
      [ ifelse AD < 0.3
        [ create-links with one-of other turtles with [AD > 0.7] ]
        [ create-links-with one-of 5 other turtles ]
        create-links with n-of 4 other turtles
      ]
    end
    

    UPDATE due to more specific question. The normal way to avoid errors is to create an agentset of possibles and then test if there's any members. Looks a bit like this:

    ...
    let candidates turtles with [AD > 0.7]
    if any? candidates
    [ create-links-with one-of candidates
    ]
    ...