Net Logo tutorial #3 -- can't see turtles, only patches - netlogo

I'm going through Tutorial #3 on the NetLogo user manual and for some reason when I assign the patches to be green and write the setup-patches and setup-turtles functions, all I can see are green patches and no turtles. When I remove the setup-patches function, I can see the turtles so I know they've been created. I've tried shifting the order of the code around but nothing's worked so far. Here's the code I have, if anyone has any ideas I'm all ears.
to setup
clear-all
setup-patches
setup-turtles
reset-ticks
end
to setup-patches
ask patches [ set pcolor green ]
end
to setup-turtles
create-turtles 100
ask turtles [ setxy random-xcor random-ycor ]
end
to go
move-turtles
tick
end
to move-turtles
ask turtles [
right random 360
forward 1
]
end

Is there any chance you are using NetLogo 3D instead of just NetLogo? That is the only way I can reproduce your problem. (It's a common beginner mistake.)
(If you open NetLogo by clicking on a desktop icon, make sure it points to NetLogo.exe, not NetLogo 3D.exe)
Steve R.

Related

What is causing my patches to cover my turtles?

I have been following the tutorial listed here Netlogo tutorial pt3
In the section "Patches and variables" I simply do not observe the image shown when I followed the steps exactly.
Instead, I can only see a green cube with my agents seemingly stuck inside.
What am I missing here? My word is only a single cube.
These are the routines that I've copied from the tutorial that should show turtles scattered across the green patch.
to setup
clear-all
setup-patches
setup-turtles
reset-ticks
end
to setup-turtles
create-turtles 100
ask turtles [ setxy random-xcor random-ycor ]
end
to setup-patches
ask patches [ set pcolor green ]
end
It turns out the tutorial omits to tell you that you need to set the max-pzcor value in model settings to zero for this to work.

How to make n-of turtles move to the same place every loop?

I want to specify the number of turtles to go and back the same place every of my loop.
For example, in day1, some of turtles born in place1 and some of turtles born in place 2 and turtles its selves know the place where they want to go and come back to the same place where they born. For day2, turtles its selves still go the same place and go on like this every day.
Anyone have any ideas or suggestions?
It's a little hard to work out what you are asking but hopefully this is close and will give us a starting point to work out what you actually want. This model has a variable for each turtle to remember where it was born, and each tick some (5) of the turtles move back to their home patch. The other turtles move in a random direction.
turtles-own [myhome]
to setup
clear-all
create-turtles 20
[ setxy random-xcor random-ycor
set myhome patch-here
]
reset-ticks
end
to go
let homers n-of 5 turtles
ask turtles
[ ifelse member? self homers
[ move-to myhome ]
[ set heading random 360
forward 1
]
]
tick
end

How to get turtles run back and forth a coloured patch?

I have a simple image as a map. I would like the turtles to start from the lighter grey colour and run to the darker patches for resources. How can I do that?
My Code
to setup-patches
import-drawing "01.png"
import-pcolors "01.png"
ask patches [
setup-house
;setup-resource
]
end
to setup-house
create-turtles [setxy where pcolor = grey]
set house? where pcolor = grey
end
The image is at https://i.imgur.com/dmODyUW.png.
I can provide more details on request.
Okay, a patch is actually a NetLogo term for one of the grid cells in the World. Your image suggests that the grey areas will cover multiple NetLogo patches each. The following code creates some random grey multi-patch areas and a house at one of the patches in one of the grey areas.
breed [houses house]
to testme
clear-all
setup-patches
setup-houses
end
to setup-patches
ask n-of 3 patches
[ set pcolor gray
ask neighbors
[ set pcolor gray
ask neighbors
[ set pcolor gray
]
]
]
end
to setup-houses
ask one-of patches with [pcolor = gray]
[ sprout-houses 1
[ set color red
]
]
end
Your question is too vague to properly answer, but hopefully this will get you on the right track. I suggest you redo the NetLogo tutorials and look at some of the models in the library included in the software to find pieces of code that do tasks you are going to need.

How would I "target" patches within a certain area?

I have set up agents and nodes to represent people and stores and it is my intention that the agents will "target" the store in their "awareness" space with the highest value ("vulnerability"). I've largely coded what I have so far through trial and error however setting the turtle's target to the patch with the highest value within a 10 unit radius is a hurdle I can't get over. Currently they target the patch with the highest value regardless of its position in the world. Could somebody suggest what I might consider to achieve this please? I have pasted what I have written so far for reference.
Thanks.
breed [shoplifters a-shoplifter]
patches-own [vulnerability]
shoplifters-own [target
awareness]
to setup
clear-all
setup-patches
setup-turtles
reset-ticks
end
to setup-patches
setup-stores
end
to setup-stores
ask n-of num-stores patches [ set pcolor lime ] ;; create 'num-stores' randomly
ask patches [
if pcolor = lime
[ set vulnerability random 100
]
]
end
to setup-turtles
setup-shoplifters
setup-target
end
to setup-shoplifters
create-shoplifters num-shoplifters [ ;; create 'num-turtles' shoplifters randomly
set xcor random-xcor
set ycor random-ycor
set shape "person"
set color red
]
end
to setup-awareness
ask turtles [
set awareness
patches in-radius 10
]
end
to setup-target
ask turtles [
set target
max-one-of patches [vulnerability]
]
end
You are on the right track using max-one-of. At the moment, however, you are sending patches as the space to search through to look for the one with maximum vulnerability value, when you really want patches in-radius 10. So you could simply do this:
to setup-target
ask turtles [
set target max-one-of patches in-radius 10 [vulnerability]
]
end
However, this is going to be inefficient because NetLogo will have to first work out which are the patches within the radius. You have already asked the turtles to work this out and assign it to their variable 'awareness'. What you really want to do is therefore:
to setup-target
ask shoplifters [
set target max-one-of patches awareness [vulnerability]
]
end
Note that I also changed ask turtles to ask shoplifters. It is only shoplifters who have the attribute 'target' so you should only be asking them to calculate it. Same thing goes for 'awareness'. At the moment you don't have any other breeds so it's not causing an error, but it is good practice to use the breed, otherwise there is no point in creating it.

NetLogo: Apply set [variable] from sub-procedure to global process?

I want to simulate reproduction process of turtles in time when single patch can by used only once. If the patch is red and ticks mod 50 = 0 then turtles-here (on this patch) hatch new 10 turtles. Every patch can be used only once during the whole simulation run.
Please, how can I include this condition into my code? I tried simple to change patch color to green with hope that the next hatching process will run only with red ones. However next time step NetLogo doesn't keep this patch green but changes it back to red. Thus my reproduction run from the same patch.
Any suggestions will be highly appreciated
The part of my code:
to go
if ticks mod 50 = 0 [ask patches with [pcolor= red] [reproduce] ]
end
to reproduce
ask one-of turtles-here
[hatch 10 ;
die]
; set pcolor green - change infestlev from 2 to 5 only for specific tick, not for the rest of the simulation
end
The code you have should work fine. In your description, you state that the colour turns back to red - so that's why this code isn't working, somewhere else you have a colouring procedure. Alternatively, if you don't want to rely on colour (or if you want colours to mean something else), then you can add a variable to each patch to keep track of whether it has already reproduced.
patches-own [reproduced?]
to setup
...
ask patches [set reproduced? FALSE]
...
end
to go
if ticks mod 50 = 0 [ask patches with [not reproduced?] [reproduce] ]
end
to reproduce
ask one-of turtles-here
[ hatch 10
die ]
set reproduced? TRUE
end
Just as a general comment, it is a little odd to ask the patch to reproduce when what you are really trying to do is have the turtle on a patch reproduce. Logically you are saying that once one turtle on a patch has reproduced, then no other turtle on that patch can ever reproduce. If the reproduction is truly governed by the patch, it would be more usual to use sprout instead of hatch. That gets you code that looks like this:
to reproduce
sprout 10 [ any commands you want the new turtles to do ]
set reproduced? TRUE
end
My final working code with steps (available here: http://ulozto.cz/xRqtDDfV/timing-of-turtle-sprout-nlogo):
setup turtles
if turtle touch red patch, turn this patch blue
at the same time - tick 10 -> sprout from every blue patch 10 nwe turtles
every patch can be used only once during simulation run (turn red, assured by reproduced? variable)
enter code here
patches-own [reproduced?]
to setup
clear-all
setup-turtles
setup-patches
change-color
reset-ticks
end
to setup-patches
ask patches [set reproduced? FALSE]
ask patches [set pcolor green]
ask n-of 80 patches [set pcolor red] ; identify turles which could be a source for new turtles
end
to setup-turtles
crt 1
ask turtles [set color yellow]
end
to go
if ticks mod 10 = 0 [
ask patches with [(pcolor = blue) and not (reproduced?)]
[reproduce] ; set reproduction to every 10 ticks for all blue patches
]
move-turtles
change-color
tick
end
to move-turtles
ask turtles [fd 1]
end
to change-color ; if turtle touch red patch, red turns blue
ask turtles [if pcolor = red
[set pcolor blue]
]
end
to reproduce ; sprout 10 new turtles from blue patches at defined time step (multiply of 10 ticks)
sprout 10
set reproduced? TRUE
end