How do I create a vision cone that takes into account the size of other turtles? - netlogo

I was using in-cone, but then I noticed my turtle was "missing" a lot of other turtles inside the cone. From what I understand, this is due to the fact that, for instance:
ask other turtles in-cone 6 60 [set seen? true]
only "detects" turtles if their xy is within the cone. They are basically points without dimensions. Is there an easy way to make a turtle of size 20 be much more "visible" than one of size 2? I've searched this and the yahoo group for answers and didn't find what I was looking for... maybe I'm not searching for the right terms... I'm new to programming and netlogo and everything so I'm probably missing something obvious here.
Thank you very much.

Related

Set value of speed slider programmatically

In setup, I draw a bunch of turtles--as small circles--to display two curves defined by functions. A very simple way to do this is
ask patches with [pycor = (myfunction pxcor)] [sprout 1 [...]]
and that's what my code does at present. It's kind of wasteful, since every patch has to be consulted--in random order--for each curve, but it's simple and easy to read, and it only happens during setup.
However, there's a little bit of a pause as the curves are constructed. If I move the speed slider all the way to the right, the pause is not noticeable. If I wrap the curve display routines in no-display and display, the user doesn't see the curves being constructed, but the speed is unchanged, AFAICS. If I move the slider to the left, it takes a long time to construct the curves even with no-display; the user doesn't see the points being placed one by one, but nevertheless has to wait while twiddling her/his thumbs.
Is there a way to set the model speed programmatically (for normal, "headfull" use)? I don't want to tell users "Move the speed slider to the right, then press setup, then move it back to the center before pressing go.
If not, maybe I'll code the curves properly using loops, but I thought I'd ask. Seems like there would be a way to do this, but I haven't found anything in the dictionary or programming docs so far.
(edit: no-display, if it did help, isn't available in NetLogo Web, which I am targetting along with regular NetLogo.)
I don't believe there is. However, you are asking all patches, when you could simply ask the pxcor values. This should speed it up a lot - square root of the number of iterations if a square world. Something like:
to testme
clear-all
let counter min-pxcor
while [counter <= max-pxcor]
[ let fn-out (function counter)
if fn-out >= min-pycor and fn-out <= max-pycor
[ ask patch counter fn-out [ set pcolor red]
]
set counter counter + 1
]
end
to-report function [#invalue]
report #invalue ^ 2
end

In a Netlogo network, how can turtles "see" properties of other turtles?

I am trying to build a model in which turtles decide to change colour depending on their environment in a network.
The approach would be to "check" the colour of the surrounding turtles and then set an if statement for the turtle in question to switch colour (there will only be 2 colours).
Specifically I would like to know how can a turtle "see" or check other turtles' colour (or other properties).
If possible I would also like to create a slider for "how many links away" can turtles see their neighbouring turtles' (or neighbours of neighbours, etc) colour.
I am new to both Netlogo and Stackoverflow, so please let me know if I should make any modifications to my model and/or question.
Thanks!
Welcome to Stack Overflow! Typically you'll want to stick to a single question per post, both for simplicity and for the benefit of future users with similar questions. As well, in cases where its applicable you should try to include some code to show what you've tried so far, as well as any setup necessary- you want to make a minimal, complete, and verifiable example. In this case, I think you're okay since your questions are clear and well explained, but if you have more complex questions in the future you will be more likely to get useful answers by following those guidelines.
For your first question, it looks like you want the of primitive- check out the dictionary entry for details. of can be used in a few ways, including allowing agents to check the value of a variable (such as color) of another agent. Check out this example code:
to setup
ca
reset-ticks
crt 10 [
setxy random 30 - 15 random 30 - 15
create-link-with one-of other turtles
]
end
to go
ask turtles [
set color [color] of one-of link-neighbors
]
end
Every time the go procedure is called, one of the turtles changes its color to the color of one of its link-neighbors. If you run it long enough, all connected turtles should end up with the same color.
For your second question, I suggest you check out the Nw extension, which is an extension built to deal more easily with Netlogo networks. Specifically, have a look at nw:turtles-in-radius, which should work with your slider approach. To get it working, include the extension using
extensions [ nw ]
at the start of your code. Then, assuming the same setup as above, you can play around with something like
to network-radius
ask one-of turtles [
set color red
ask other nw:turtles-in-radius 2 [
set color white
]
]
end
When you call the network-radius procedure above, you should see one turtle turn red, and any turtles within 2 links of that turtle turn white. To switch to a slider, just swap the "2" out for your slider variable. Hope that helps!

How do I make linked turtles move together in NetLogo?

I'm trying to model fish movement and need them to form schools when there is more than 1 of the breed in a given patch. So far I have managed to get them to form links when they encounter each other with the function below, but then they continue moving independently. I'd also like to re-scale the color of turtles in a linked group so that the more turtles in the group the darker the color is (I'm guessing this is similar to the way you make contour maps according to environmental gradients but I haven't figured it out yet).
Any assistance is always appreciated!
to form_link
if count breed_1-here > 1
[
ask breed_1
[create-links-with other breed_1-here]]
end
If linking isn't the way to get them to move together, I'm fine with another method.

Query about hidden turtles

What actually happens to hidden turtle? I mean after we hide the turtle it continue to live in invisible mode occupying memory as I guess.
I hide few turtles but did not ask them to be shown back and when I inspected the hidden turtles continuing simulation their attribute were changing as per my commands. So, what exactly hiding a turtle sense for.
In one of my simulations, turtles represent people making decisions about whether to protect themselves during an epidemic. There are tens of thousands of these turtles, with potentially hundreds on some patches. The turtles don't move, but they each make their own decision based on personal characteristics like attitude and environmental perception such as how close the epidemic is.
Having these turtles visible would just clutter up the screen. Instead, I hide them and colour the patch based on what proportion have adopted protective behaviour. This is much more informative.
In my most recent simulation, though, I make the turtles size 0 instead of hiding them. This still makes them disappear, but I can still right-click on the world view to access the list of turtles where I have clicked.
Another reason to hide turtles is when you are simulating an infinite plane and turtles outside the view should simply be hidden.
Note that if you are moving turtles using setxy rather than forward you should test to make sure the patch you are about to move to exists since setxy throws a runtime error if it is given coordinates outside the world. From NetLogo documentation:
ifelse patch-at (new-x - xcor) (new-y - ycor) = nobody
[ hide-turtle ]
[
setxy new-x new-y
show-turtle
]

Trying to make a procedural environment in netlogo

So this simple block of code will create clusters of black patches in the environment.
I would like to know how to procedurally paint and repaint them in the environment.
The effect I'm going for is periodically disappearing patches and reappearing in a random location.
ask patches in-radius random 3.5
[
set pcolor black
]
I don't know how I would apply pseudo code logic like:
while(true)
{
if(ticks % 100)//If ticks are a multiple of hundred
{
clear black patches
paint clusters of patches
}else{ do nothing}
}.
-in netlogo syntax.
Any help is very much appreciated.
Thanks in advance!
ask patches with [pcolor = black and <near a certain point>] [...]
But ... if I am not misunderstanding the nature of your question, I think you need to work through at least the beginning of a tutorial on NetLogo first, or take a look at some of the examples in the Models Library that's available on the File menu. I'm not going to rewrite the tutorial here. For example, you don't need a while loop, given what you've said so far. You need to use a run procedure. That's the sort of basic idea you should learn before doing anything else. Since you already have some understanding of programming, it won't take long.