still_learning
still_learning

Reputation: 806

Degrees of separation in Netlogo

I would like to know how I can count the degrees of separation among nodes within a network. I have created a network with two breeds that spread virus through time.

to setup
create-people_inf 5 [set label "Infected"]
create-people_well 20 [set label "Good health"]
end

Then I added new nodes to the preexisting ones as follows:

  ask people_inf
  [ create-links-to other people_inf
    [set color red ]
    let this_turtle self
    ask people_well
    [
     if random-float 1 < 0.5
     [
        create-link-to this_turtle [set color green]
    ]
    ]
  ]

This is just a default network. My question would be on how I can count the degrees of separation between one selected node and another one, randomly chosen. I thought of adding a flag and consider a logical condition (if connected?=true), but I do not know to consider the nodes in between. My approach would give me only information on one node and its directed connections.

Any suggestion is more than welcomed. Thanks.

Upvotes: 2

Views: 65

Answers (1)

JenB
JenB

Reputation: 17678

You need to use the Network (nw) extension, see documentation at https://ccl.northwestern.edu/netlogo/docs/nw.html. From that, you can use the nw:distance-to for any turtle to find the number of hops to any specified turtle

Upvotes: 3

Related Questions