Search code examples
netlogoagentagent-based-modeling

Loop through agents Netlogo


I want to link every agent from breed 1 to ONE other agent from breed 2.

create-breed1 20 [
 let breed2-number random 20
 create-link-with breed2 breed2-number
]

The problem is now that every agent from breed 1 is connected to one agent of breed 2 but breed 2 is sometimes linked to more than one agent of breed 1 and sometimes not linked at all.


Solution

  • You need to filter the breed2 turtles to remove those that already have a link before selecting turtles to create links with. You probably want something like:

    breed [breeds1 breed1]
    breed [breeds2 breed2]
    
    ask breeds1
    [ create-link-with one-of (breeds2 with [not any? link-neighbors])
    ]
    

    I am assuming you have more breeds2 turtles than breeds1 turtles so there is a turtle available to link to.