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.
Related
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.
I want a turtle to colour an area (in-radius 5), on top of the GIS data I have imported.
Please find attached the line of code I am using which is not working.
Is there any way how to do this?
Thanks!
extensions[gis]
globals [map-boundary]
to setup
ca
set map-boundary gis:load-dataset "/Users.shp"
create-turtles 50
ask turtles [setxy random-xcor random-ycor set size 1 set color grey]
gis:set-world-envelope (gis:envelope-union-of (gis:envelope-of map-boundary))
gis:import-wms-drawing "https://ows.terrestris.de/osm/service?" "EPSG:4326" "OSM-WMS" 1
reset-ticks
end
to go
ask turtle 1 [ask patches in-radius 5 [set pcolor blue]]
end
I'm not sure what you mean "not working", and lacking the datasets you have I can't reproduce the problem.
The Models Library has some GIS examples. What's not obvious is where Uri Walenski's "shared-dataset" files are that you need to run them models, but I found some version of them here:
https://ccl.northwestern.edu/netlogo/5.0/models/Code%20Examples/GIS/data/
and when I double-click countries.shp and countries.dbf they download and I can move them to my own new "shared-dataset" folder under the folder my model is in. That done, the model "create-turtles-inside-polygon" runs.
I removed most of and added a line to draw a blue region around turtle #1 and it seems to work. What does your attempt to draw the blue region do or not do that's different?
extensions [gis]
globals [dataset]
breed [citizens citizen]
citizens-own [cntry_name curr_type]
breed [manual-citizens manual-citizen]
manual-citizens-own [country-name currency-type]
to test-turtles
clear-all
set dataset gis:load-dataset "./shared-datasets/countries.shp"
gis:set-world-envelope gis:envelope-of dataset
gis:set-drawing-color red
gis:draw dataset 1
foreach gis:feature-list-of dataset [ country ->
gis:create-turtles-inside-polygon country turtles 1
;;clear-turtles
]
ask turtle 1 [ ask patches in-radius 5 [set pcolor blue]]
end
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.
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.
I am trying to make my turtle change the color of a patch when it comes into contact with it and have tried the following code:
to deesculateviolence
ask turtles [
if pcolor = red [set pcolor blue]
]
end
The code does not come up with any errors but when I play the model, the color of the patch does not change. I have tried similar codes from different models and still cannot get the patch to change color. If anyone knows where I am going wrong I'd really appreciate your help.
I think your code does the right thing :
to setup
clear-all
create-turtles 5 [
move-to patch random 20 random 20
]
ask n-of 25 patches [set pcolor red]
reset-ticks
end
to go
ask turtles [
rt random 10
fd 1
if pcolor = red [set pcolor blue]
]
tick
end
you can see the effect in following example better