Count links with specific type of agent

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Count links with specific type of agent

NetLogo-Users mailing list
Dear,

I am struggling to count links with specific type of agent..

For examples, there are three different types of agents with three different
colors.
Basically, I want to count of links connected with red colored agents.

Intuitively, the code,
count links of [self] with turtles [color = red],
looks okay, but it does not work.

Would you help me to figure out this?

Best,
Woosung






--
View this message in context: http://netlogo-users.18673.x6.nabble.com/Count-links-with-specific-type-of-agent-tp5006507.html
Sent from the NetLogo-Users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Count links with specific type of agent

NetLogo-Users mailing list


> On Jun 16, 2017, at 4:23 PM, kws908 [hidden email] [netlogo-users] <[hidden email]> wrote:
>
> I am struggling to count links with specific type of agent..
>
> For examples, there are three different types of agents with three different
> colors.
> Basically, I want to count of links connected with red colored agents.
>
> Intuitively, the code,
> count links of [self] with turtles [color = red],
> looks okay, but it does not work.
>
> Would you help me to figure out this?
>
> Best,
> Woosung


Woosung,
Look up `link-neighbors’ in the NL dictionary. That is the key to this problem. Here is a test to show how it could be used. Paste this into a new model and enter ’test’ in the command center. Repeat to see that it works for different numbers of red turtles.


to test
  clear-all
  create-ordered-turtles 10 [
    set color one-of [red green blue]
    jump 5
  ]
  create-turtles 1 [
    create-links-with other turtles
    print word "Number of links with red turtles is "
      count link-neighbors with [color = red]
  ]
end


HTH,
Jim