i'm new using NetLogo and I'm trying to learn it using the 'Hello World' model found on the net. I'm running NetLogo 5.2 on Mac OS X (Yosemite). When I try to set the turtles randomly, in this way
setxy random screen-size-x random screen-size-y
I get this error: Nothing named SCREEN-SIZE-X has been defined
screen-size-x appears in capitalization and so i get an error on this built-in function. Can anyone help me? Thank you
This is the NetLogo code I'm using:
globals [buttons] ; Global variables
to setup ; Initializes model for new run.
set-default-shape turtles "circle" ; Turtles are circles
clear-all ; Reset turtles and patches
set buttons 500 ; Set number of buttons to 500
create-turtles (buttons) ; Create "buttons" number of turtles
ask turtles [setup-turtles] ; Initialize each turtle
end
to setup-turtles ; Called for each turtle during setup
setxy random screen-size-x random screen-size-y ; Set our x,y randomly
end
I think screen-size-x and screen-size-y are NetLogo history. You can use max-pxcor, max-pycor and min-pxcor, min-pycor to get the world borders or world-width and world-height to get just the size.
To get a random position there are random-xcor and random-ycor.
to setup-turtles
setxy random-xcor random-ycor
end
Related
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 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.
I set up the environment where every tick, 3 pieces of information show up, and the turtles create links with them, meaning they integrate the information into their knowledge.
I'd like to count their accumulated knowledge with every tick.
But the problem is, the count function always count the number of all the existing links, not just the number of newly created links.
Of course, I can count properly when I make the links die, but that is not what I want.
What can I do?
directed-link-breed [infolinks infolink]
breed [guys guy]
breed [infobits infobit]
globals [newinfos x]
guy-own [knowledge]
to setup
ca
create-guys 2[
setxy random-xcor random-ycor
set knowledge random 100
set label knowledge
reset-ticks
end
to go
create-infobits 3[
setxy random-xcor random-ycor
ask guys [
set newinfos myself
expose newinfos
]]
ask guys
[update-knowledge]
tick
end
to expose [new]
if random-float 1 < 0.8 [
create-infolink-to new
]
set x count infolink-neighbors
end
to update-knowledge
set knowledge knowledge + x
set label knowledge
end
The best way is to use a guys-own counter that is set to zero at each tick and then incremented every time a new link is made during that tick. I've added such a counter, new-knowledge in the code below, and deleted the globals since they play no "global" role in your code as it stands.
directed-link-breed [infolinks infolink]
breed [guys guy]
breed [infobits infobit]
guys-own [knowledge new-knowledge]
to setup
ca
create-guys 2 [
setxy random-xcor random-ycor
set knowledge random 100
set label knowledge
]
reset-ticks
end
to go
ask guys [set new-knowledge 0]
create-infobits 3 [
setxy random-xcor random-ycor
ask guys [expose myself]
]
ask guys [update-knowledge]
tick
end
to expose [new]
if random-float 1 < 0.8 [
create-infolink-to new
set new-knowledge new-knowledge + 1
]
end
to update-knowledge
set knowledge knowledge + new-knowledge
set label knowledge
end
I am a high school student and I have to make a model about plants and plagues. I want to setup turtles with a preset distance from each other, but I can't figure out how to do that without creating an infinite loop. This is what my code looks like. Now it creates 20 turtles with random distance between them, but I want them to have a preset distance and as much turtles there can be on the screen with that distance between them.
to setup
clear-all
ask patches [ set pcolor 33 ]
make
repeat 20 [maken]
reset-ticks
end
to make
create-aardappelplanten 1[
setxy random-xcor random-ycor
set color green
set size 1.5
set shape "plant"
set age 1
]
end
Thank you so much!!
I am currently learning NetLogo and I need help. In my model I have same sized 10 turtles which moves randomly. When 2 or more turtles are on the same patch they will combine and form a new turtle with the double size. In this manner, the main rule is max. 5 turtles can combine to each other. And this formation will continue until the there will be 2 turtles (with each contain 5 turtles) remain.
I had created turtles and made them move randomly, but I could not managed to combine them. Can you show me a way to do this? Any help appreciated. Regards.
EDIT: I tried the "in-radius" command unsuccessfully. 5-5 distribution of the turtles (as you can can see from the code, they represent H2O molecules) is vital for the system definition and any other distributions are not allowed in the model.
In detail, when randomly moving 2 H2O molecules meet on the same patch, they will combine to form a new molecule (2H2O). The main rule is as previously mentioned, max. 5 molecules can combine which ends with forming 5H2O. Since, initially there are 10H2O molecules in the system, there will be 2 5H2O molecules at the end.
The code I tried to implement is as follows,
breed [h2o-molecules h2o]
to setup
clear-all
reset-ticks
create-h2o-molecules h2o-num [
set color 105
set sIze .5
set shape "circle"
setxy random-xcor random-ycor
set pen-mode "up"
]
end
to setup-patches
ask patches [set pcolor 0]
show count turtles
end
to set-label
ask patches [
ifelse count turtles-here > 0
[set plabel count turtles-here]
[set plabel ""]
]
end
to move-h2o-molecules
ask h2o-molecules [
let dice random 1000
let change (dice - 1)
forward 2
set HEADING (HEADING + change * 2)
]
end
to go
setup-patches
move-h2o-molecules
ask turtles [rt random 1
fd 0.3]
set-label
tick
end
Thanks for your time and patience. Regards,
Using turtles-here
You don't need to ask patches for turtles-here (as you did to set patches labels). The function runs as well if called by a turtle (and is more efficient when there are more patches than turtles). But take care to use other turtles-here if you don't want to include the calling turtle.
Combine procedure
If you declare
a turtle variable after your breed declaration:
h2o-molecules-own [
turtles-inside
]
(set the variable value inside your create-h2o-molecules)
and your combination limit max-inside as a global variable (use slider widget with 5 as default value)
then the combine procedure can look like:
to combine ;; turtle procedure
; take one turtle from the same patch as a target
; which has turtles-inside low enough to combine with
let target one-of other h2o-molecules-here with
[turtles-inside <= max-inside - [turtles-inside] of myself]
if target != nobody
[
set turtles-inside turtles-inside +
[turtles-inside] of target ;; increase turtles-inside
ask target [ die ] ;; kill the target
set size sqrt turtles-inside ;; increase size
]
end
Stop
You can stop the simulation by
if not any? h2o-molecules with [turtles-inside < max-inside] [ stop ]
Comment
The condition used to select the target turtle is using turtles-here, other and the maximum constraint which is compared to the sum of turtles inside the target and turtles inside the calling turtle (using myself function).