sf61
sf61

Reputation: 55

How to create a network of neighbors?

Hi I am new to netlogo with no programming background, I am trying to create a network of "neighbours" , using GIS extension , so far I'm using in-radius function but i am not sure if it's the one that is suitable. since i don't understand the unit of radius in Netlogo

here's the code :

to setup
  clear-drawing
  clear-all
  reset-ticks

  ; zoom to study area
  resize-world 00 45 0 20
  set-patch-size 20

  ; upload city boundries
  set mosul-data gis:load-dataset"data/MosulBoundries.shp"
  gis:set-world-envelope gis:envelope-of mosul-data
  gis:apply-coverage mosul-data "Q_NAME_E" neighbor


to Neighbour-network
  ;; set 7 neighbour agents inside the city  
  ask turtles [ 
    let target other turtles in-radius 1 
    if any? target
    [ask one-of target [create-link-with myself]]
  ]
  print count links

I want for each neighberhood neighbor each agent is linked to the 7 nearst neighbors. my guess is that in the line if any? target something has to change , but all my attempts are useless so far.

Thank in advance

Upvotes: 0

Views: 308

Answers (2)

JenB
JenB

Reputation: 17678

I am unclear how GIS relates to this question and you haven't provided the code for creating the agents so I can't give a complete answer. NetLogo has a coordinate system, automatically built in. Each agent has a position on that coordinate system and each patch occupies the space 1 unit by 1 unit square (centred on integer coordinates). The in-radius and distance primitives are in the distance units.

However, if all you want to do is connect to the 7 nearest turtles, you don't need any of that because NetLogo can simply find those turtles directly by finding those with the minimum distance to the asking turtle. This uses min-n-of to find the given number of turtles with the relevant minimum, and distance [myself] for the thing to minimise. The whole thing, including creating the links with the generated turtleset, can be done in a single line of code.

Here is a complete model to show you what it looks like:

to testme
  clear-all
  create-turtles 100 [setxy random-xcor random-ycor]
  ask n-of 5 turtles
  [ create-links-with min-n-of 7 other turtles [distance myself]
  ]
end

Upvotes: 2

Aniruddha Belsare
Aniruddha Belsare

Reputation: 56

Sarah:

1) This helped me understand the use of 'in-radius' in NetLogo (or the unit of radius): When you use 'in-radius 1' in a patch-context, 5 patches will be selected (patch where the asking turtle is located and four neighbors, not all 8 neighboring patches).

enter image description here

2) Consider using 'min-one-of target [ distance myself ]' instead of 'one-of target'.

min-one-of: http://ccl.northwestern.edu/netlogo/docs/dict/min-one-of.html

distance myself: http://ccl.northwestern.edu/netlogo/docs/dict/distance.html

to Neighbour-network
; set 7 neighbour agents inside the city
ask turtles [
    let target other turtles in-radius 1
    let counter 0
    while [ count target > 0 and counter < 8 ]
    [ ask min-one-of target [ distance myself ] [
        create-link-with myself
        set counter counter + 1
      ]
    ]
    show my-links
  ]

3) Consider exploring Nw extension: https://ccl.northwestern.edu/netlogo/docs/nw.html

Upvotes: -1

Related Questions