What is the difference between turtle size, patch size and frame rate in netlogo? - netlogo

I want to know the Relationship between turtle size and patch size in Netlogo. Also I want to make those sizes in a way such that any turtle moves from one patch to another at every tick.

Patch size is measured in pixels. It is configurable in the "Model Settings" dialog.
You can think of turtle size as measured in "patches". A turtle of size 1 should appear to be the size of one patch. (Note, however, that turtle size is a "display only" property. Conceptually, turtles are just points. They don't really occupy space in the NetLogo world even if they appear to do so.)
Changing the xcor or the ycor of a turtle by 1 should move it by exactly one patch. If you want them to move diagonally, things are a bit more messy. You might be better off targeting destination patches directly, e.g.:
; move to the patch north-east of current position:
ask one-of turtles [ move-to patch-at 1 1 ]
; move to an adjacent patch at random:
ask one-of turtles [ move-to one-of neighbors ]
Those are just examples, of course. The code to use will depend on what exactly you are trying to do. If you tell us more in a separate question, we might be able to help you.

Related

Can't run Netlogo code - asking turtles to look around themselves and select the lowest patch variable

I am trying to get my turtles to look around themselves in netlogo and select a patch with the lowest slope variable in radius 2 - and if there isn't one to just select any patch.
I check my code, and it says everything is fine, but when I run it I keep getting this error: this code can't be run by a patch - error while patch X X running ifelse - called by procedure move - called by procedure go - called by button "go"
This is my move code:
to move
ask turtles [ask patches in-radius 2
[ifelse slope < 5
[fd 1]
[move-to one-of patches in-radius 2]
]
]
end
I have already tried downhill and downhill4 but my agents seemed to get stuck at the bottom of the slope and couldn't move anywhere.
Thank you for any help and advice!
Thank you - my code now works!
Because you are asking turtles to ask patches, the code inside the ask patches is run by the patch! A patch can’t use turtle variables, and doesn’t know that you mean to refer to the variables of the turtle that asked the patch.
This is what “of myself” is for. It lets an agent (self) talk to the agent that is telling it what to do. You’ll see stuff like “set heading [heading] of myself” But that’s not what you need here.
we could use an ask patches like you are doing here, but we really don’t want them to do anything, and it’s going to make the code much more complex looking. Anyway, We just want to find a patch that meets the turtle’s needs and move to it.
So instead. We can query the nearby patches using a WITH and store the set of patches found in a “patch set” variable.
If there are any, we can move to one of them.
Else, we can just move forward.
So
To move
Ask turtles
[
;; here the turtle tells patches to test the patch’s own slope
Let good-spots patches in-radius 2 with [ slope < 5 ]
;; are there some patches that pass the test?
If-else any? Good-spots
[ ;; Yes, pick one and go there
move-to one-of good-spots
]
[ ;; No, just move forward
Fd 1
]
]
End
Edit to add : Matteo’s answer correctly identifies the actual requirement, based on the question: move directly to the flattest patch, versus what the code above does, move to one of the flatter patches, if there is one.
Move-to min-one-of patches in-radius 2 [ slope ]
As you noted, This is similar but not identical to
Downhill slope
And neither of these may prevent turtles from getting stuck in a pit. You may need more code to detect pits and jump out of them.
The problem is not about variables but about commands: you are asking patches to run forward or to run move-to, while these are turtles' commands.
Now, for the purpose of the question, there is another issue: you said that you want
turtles to look around themselves in netlogo and select a patch with the lowest slope variable in radius 2 - and if there isn't one to just select any patch
However, even if we ignore the problem about asking patches to run forward or move-to, the structure of your code implies something very different. Your code seems to intend:
Turtles, check if there are any nearby patches with slope lower than a specific threshold;
If there are, move forward in whatever direction you are already facing;
If there are not, move to a random nearby patch.
The solution below is based on the assumption that what you want is what you said, and not what your code seems to imply.
The solution is very simple and only needs min-one-of (check it here):
to move
ask turtles [
move-to min-one-of patches in-radius 2 [slope]
]
end
As a demonstration, consider this full example:
patches-own [
slope
]
to setup
clear-all
ask patches [
set slope random 10 + 5
set pcolor scale-color green slope 5 14
]
create-turtles 10 [
setxy random-xcor random-ycor
set color yellow
]
end
to go
ask turtles [
move-to min-one-of patches in-radius 2 [slope]
]
end
You will see that turtles tend to go to darker patches, that are those with lower slope.

NetLogo: move turtles until they find the optimal location

I have NetLogo file and assigned for each patch a optimal value (the lower the value, the better). I would like to move my turtles until they all find a spot with the most optimal value. How can I implement this in a piece of code?
I already have this piece of code that prevents the turtles from directing to a patch that is not 'beach'. Still, their movements are randomly and I would now like them to move to a patch where the optimal value is the lowest possible.
to go
ask turtles
[
;ensures that next patch is a beach-patch
ifelse [value] of patch-ahead 1 != "beach"
[ lt random-float 360 ] ;; We see a patch that is not beach in front of us. Turn a random amount.
[ fd 1 ] ;; Otherwise, it is safe to move forward.
]

How do I make turtles avoid patches in NETLOGO?

My agents are boats moving on water, surrounding and at some places within that water are bits of land which need to be impossible to pass. I'm struggling to conceptualize how to tell an agent this information in netlogo.
I've assigned
patches-own
[DEPTH
PASSABLE?
]
with
ask patches with [DEPTH > 0] [set PASSABLE? FALSE]
How do I tell a turtle to not cross over or occupy a patch with PASSABLE? = FALSE while engaging in an otherwise random walk search for
patches in-radius VISION with [DEPTH = 10]
?
sorry for the lack of a reproducible example, but this is a more conceptual question than anything. I will rough out a simple example model if need be.
When your agent is about to take a step forward, you can have them check if they can, then make them pick a new destination if they are going onto dry land
You can do this with Patch-Ahead or In-Cone if you want. Use that to set the destination.
Somthing like:
to walk
"pick destination"
ifelse destination = water [fd 1] [walk]
end
To pick what the possible destination is, you use what the turtle's current heading is like this:
to pick-destination
let destination patch-ahead 1
end

How to create a fixed number of turtles at a certain point?

This may seem like a very simple question to ask but at present I do not know how to create a controllable number of turtles. In addition to this I do not know how to set the coordinates where the turtles should spawn. Ideally I would like the turtles to spawn on a patch that the user will draw out in the U.I. so that the turtles can then move along the network the user will have drawn in the U.I. Any answers would be greatly appreciated.
Patches use the sprout command
Ask patches [
Sprout 5 [set color red ]
]
Asks all the patches to make 5 red turtles.
Netlogo has fantastic documentation
The netlogo dictionary in help is insanely useful.
Or just ask one
Ask patch 4 5 [sprout 1]
create-turtles takes in the number of turtles to create. It also allows you to pass in a block of code that will then be run by the created turtles. So you can do:
create-turtles 50 [
setxy 3.5 4.7
]
This will create 50 turtles at the coordinates (3.5, 4.7).

NetLogo: How can the heading of a turtle be passed onto another turtle within a radius?

A turtle reaches a point and for a set amount of time, can relate it's heading to other turtles within it's range.
Pseudo code
if any? turtles within 5
[pass on heading to other turtle]
The other turtle I'm assuming would need a call to use this heading, so something like
Pseudo code
if has received heading?
set heading new heading
Also I need to reverse this heading, so that the turtle receiving the heading does not travel at this heading, but rather travels in the opposite direction i.e the direction the other turtle was travelling from
ask turtles in-radius 5 [
set heading [ heading ] of myself
]
myself, aka the worst named primitive in NetLogo, refers to the turtle doing the asking.