0

I'm trying to implement YOYO leader election algorithm in netlogo first step in this algorithm is to orient links ( direct link )from the minimum to the maximumbut between neighbors only ! I tried the command

   [`ask turtles with [ [ who ] of self < [who] of one-of link-neighbors ] 
        create-direct-to turtle [who] of one-of link-neighbors ]`

this creates direct link from min to max ( neighbors ) but also creates a direct link from max to min ( neighbors ) and I don't know what's wrong :( here's a screenshot , if you notice theres' a direct link from 0 to 2 and also from 2 to 0 and my goal is to have only from 0 to 2

JPRLCol
  • 749
  • 11
  • 28
Safa Lola
  • 1
  • 1

1 Answers1

1

Your problem is that every time you do one-of, it randomly selects. So you test against a random link-neighbor in the first line, find it's true and then randomly select a link-neighbor to connect to.

 [ ask turtles with [ [ who ] of self < [who] of one-of link-neighbors ] 
   create-direct-to turtle [who] of one-of link-neighbors
 ]

More generally, this seems an odd way to achieve your goal. To start with, link-neighbors are the turtles that the turtle is already linked to. link is the generic name for all link breeds (I think you have created a breed called direct-link).

I am not entirely clear what you mean by minimum and maximum since your code is just from smaller to larger who value, regardless of what other who values are available. If you want to create a link from every turtle to every turtle with a higher who value, here is some code:

ask turtles
[ let targets turtles with [who > [who] of myself]
  create-links-to targets
]

In general, it is bad practice to use who in NetLogo code. who is a completely arbitrary identifier that simply tracks the order that turtles are created. If you have turtles that die, then your code may crash because it is referring to a turtle that no longer exists. Or perhaps at some point you will have two breeds of turtles - who doesn't care if your turtle is a person or a dog or a factory or...

This may be one of the very few exceptions, but you might want to think about what you are intending who to mean. For example, as this is a leadership model, perhaps you could have a variable called 'charisma' and all the links are from turtles with lower values of charisma to higher values of charisma.

JenB
  • 17,620
  • 2
  • 17
  • 45
  • 0 thank you so much for your explanation , my goal is to tranforme undirected link into directed links from each node to the neighbors who has higher who number ( just like screenshot above ) so that's why I created undirected links and then created directed links if you have any suggestion on how to tranforme an undirected link into a directed link from each node to its higher neighbors who number , I would appreciate it thank you for explaning abt one-of – Safa Lola Aug 22 '20 at 12:37
  • all I want is to edit the code above in order to link all neighbors and not one of link neighbors( random link ) @JenB – Safa Lola Aug 22 '20 at 12:50
  • The code I wrote does exactly what you appear to want - it creates undirected links from all turtles to all turtles with higher `who` values. You don't need to have directed links first. Have you actually tried the code? – JenB Aug 24 '20 at 07:35
  • I wanna ask you if you have an idea on reversing a direct link or changing its direction :/ ? – Safa Lola Aug 24 '20 at 07:51
  • If you want to change the direction of a link, you need to create a new link (from `end2` to `end1` of the chosen link) and then delete (`die`) the original link. – JenB Aug 24 '20 at 08:22