How to segregate turtles in NetLogo in a specific region

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to segregate turtles in NetLogo in a specific region



Is it possibile, in NetLogo, to create a sort of fenced area (corral) in which I can isolate n sick turtles (not unlimited) while sane turtles can't access it?
If yes, how can I move sick turtles there? And how can I prevent sane turtles from getting there?




3 Answers
3



What i've done is isolating a bunch of patches.



Say your origin point is in the center of your frame. And your max-xcor is 30 and your max-ycor is 30 too.


max-xcor


max-ycor



Take this map as a reference.



NetLogo workspace



Say now that sick turtles must be in the first quadrant and healthy turtles must be in the third quadrant.



You want to ask turtles with sick status to face the upper right corner. This would be coordinates (30,30) then they should check if they are in the designated area. If not, keep moving forward. Since you want them to segregate around the first quadrant you want to make a procedure to make them move randomly once they're in there.


ask


turtles with


face



Same goes for healthy turtles, ask them to face coordinates -30,-30 and then ask them to go forward a random number of steps, then they should check if they are in the designated area. If not, keep moving forward.


face


ask


forward



Ask every healthy turtle which their coordinates are, if these coordinates are very close to sick turtle's area, make them face the other way (say random coords).



With an if!


Ifelse [turtles.coordinateX + 5 >= 30 && turtle.coordinateY + 5 >= 30] [true][false] < This means they're close by 5 patches!



Rewrite that in netlogo of course.



There's a lot of help here too. http://ccl.northwestern.edu/netlogo/docs/





The problem with this approach is the the program will have to contain lots of these tests. It would be very much easier by just naming a patch-set
– JenB
33 secs ago


patch-set



This could be more simple way of doing the same I think,


First design the quadrants during setup :


ask patches with [ pxcor <= max-pxcor and pxcor > 0 and pycor > 0]
[
set pcolor red
set quadrant 1

]

ask patches with [ pxcor >= min-pxcor and pxcor < 0 and pycor > 0]
[
set pcolor blue
set quadrant 2
]

ask patches with [ pxcor <= max-pxcor and pxcor > 0 and pycor < 0]
[
set pcolor green
set quadrant 3
]

ask patches with [ pxcor >= min-pxcor and pxcor < 0 and pycor < 0]
[
set pcolor yellow
set quadrant 4
]
Now on 'go'
to go
ask turtles with [gender = "Female"] [
let p one-of patches with [quadrant = 1]
move-to p
]
ask turtles with [gender = "Male"] [
let p one-of patches with [quadrant = 4]
move-to p
]
end



The easiest way to do this is to create a patch-set and label it hospital. To do this, you need:


patch-set


globals [hospital]

to setup
....
set hospital patches with [pxcor < -10 and pycor < -10 ]
...
end



Then any time you have turtles move, you can get the turtle to refer to the hospital. For example:


ask turtles
[ face one-of hospital
forward 1
]



Or you can jump to a random patch that's not in the hospital:


patch


ask turtles [ move-to one-of patches with [not member? self hospital ]]



Here's a complete model that puts this together:


globals [hospital]

to setup
clear-all
create-turtles 20
set hospital patches with [pxcor < -10 and pycor < -10 ]
ask hospital [set pcolor red]
ask turtles
[ move-to one-of patches with [not member? self hospital]
]
end






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP