FalconX
FalconX

Reputation: 53

Making links based on turtles-own variable

In this example I am trying to make two directed-link-breed links based on turtles-own Value. The condition is as follows ask turtles to link to other turtles who have a smaller Value than me.

directed-link-breed [active-links active-link]
turtles-own [ Value ] 

to setup

crt 100 [setxy random-xcor random-ycor set value random 500]
ask turtles [ create-active-links-to min-n-of 2 other turtles [Value < myself] ][set links to have xxxxx ]
end

when I do the following:

  ask turtles [ create-active-links-to  min-n-of 2 other turtles with [value  < [ value ] of myself ] [set links to have xxxxx ]

I am getting the following error:

Requested 3 random agents from a set of only 2 agents.
error while turtles 8 running N-OF
  called by procedure GO
  called by Button 'go'

Upvotes: 0

Views: 92

Answers (1)

JenB
JenB

Reputation: 17678

That message is telling you that (for the particular lettuce), there were only two that satisfied the criteria, but you wanted to link with 3 of them. Looking at your question, you want turtles to send links to turtles with lower values of a specific variable. What do you want the turtle with the lowest value of that variable to do? Clearly it can't link to lower valued turtles because there aren't any.

I'm also not clear why you are using min-n-of. Do you want to link to the lowest valued turtles (in which case every turtle will send links to the same few turtles) or do you want to link to randomly selected turtles with lower values (in which case turtles with higher values will have more choices)?

There are a couple of ways you can handle this once you have the logic sorted out. If you definitely want the lowest value, then use min-n-of first to find the candidates, then link to any with a lower value than the asking turtle. If you want to randomly select from a potentially larger group, use up-to-n-of instead of n-of. Or you could count the number found before trying to link to make sure there's enough.

Upvotes: 1

Related Questions