pablo
pablo

Reputation: 385

create turtles and move to a position in a radius of another breed agent

I would like to create some turtles in a radius of another breed agent.

I have this example code:

breed [ readers reader ]
undirected-link-breed [ rris rri ]
breed [ tags tag ]

to setup
  clear-all
  set xy-file "locations.txt"
  setup-readers
  setup-tags
end

to setup-readers
  create-readers num-readers [
    set shape "circle"
    set color white ; means idle state 'red' is active
    setxy random-xcor random-ycor
  ]
end

to setup-tags
  create-tags tag-population [
     setxy random-xcor random-ycor in-radius 6 of one-of readers
    ] 
end

The line setxy... to place the tags in a circle of distance 6 from one of the readers it does not work, but I do not know how to fix it. I have also tested move-to primitive without good result. What I would like is to have a population of tags in a radius of each reader and if possible select the number of tags for each reader to be different.

Upvotes: 1

Views: 867

Answers (1)

Luke C
Luke C

Reputation: 10336

The sprout primitive might get you what you need- instead of creating your tags and then moving them, just have the appropriate patches spawn them directly. For example, with this setup:

breed [ readers reader ]
breed [ tags tag ]

to setup
  clear-all
  setup-readers
  setup-tags
  reset-ticks
end

to setup-readers
  create-readers 5 [
    set shape "circle"
    set color white 
    setxy random-xcor random-ycor
  ]
end

You can make a population of patches that are within the radius of readers and have however many you like sprout a tag:

to setup-tags
  let radii-patches patch-set []
  ask readers [ 
    set radii-patches ( patch-set radii-patches patches in-radius 6  )
  ]
  ; Code above defines the patch-set of patches within 6 of readers
  ; Then, just ask 10 of those radii patches to sprout a tag
  ask n-of 10 radii-patches [
    sprout-tags 1
  ]
end

If you are doing this on a per-reader basis and you want each to have a different number of tags, you could try something like:

to setup-tags-reader
  let n-tag random 5
  ask readers [
    ask n-of n-tag patches in-radius 6 [
      sprout-tags 1
    ]
  ]
end

but then set the n-tag value some other way (for example, from another .csv file as you seem to be setting reader location).

Side note- when you post on here try to strip out any code than cannot be directly copied and pasted into Netlogo by other users (eg the 'xy-file' line, the tag-population and num-readers variables)- it just makes things super simple!

Edit

As per your comment- try this option (using the same setup as above)

to setup-tags
  create-tags 10 [
    move-to one-of readers
    rt random-float 360 
    fd random-float 6
  ]
end

This just creates tags, moves them to a reader, has them randomly select a direction, then has them step forward a random amount from 0 to 6.

As to how to assign patches to each reader- just make a readers-own variable then have them assign patches to that variable in their setup (eg, set my-patches patches in-radius 6). You could do a similar thing with tags to define a reader-specific set of tags (eg `set my-tags tags in-radius 6). Note that in both cases you can get overlap where two readers share patches/tags- you will have to account for that.

Upvotes: 2

Related Questions