NetLogo: Topology: An error occurs when the turtle reaches the end (max-pxcor) of a boxed or cylindrical world with ends - netlogo

I tried the following syntax but got the following error.
Error messages: TURTLES-ON expected input to be an agent or agentset but got NOBODY instead.
In the 2D screen when an error message was issued, an error occurred when the turtle reached the rightmost cell. If the sintax "forward 1", this case works well withour any error. But I need to use the "forward 1 * 0.1" syntax with "tick-advance 0.1".
I already saw the following description, but I do not solve it still now.Does anyone know a good way? Thank you in advance.
https://ccl.northwestern.edu/netlogo/docs/programming.html#topology
The following is an example syntax:
ask turtles with [xcor < max-pxcor][
if not any? turtles-on patch-ahead 1
[forward 1 * 0.1]]

The can-move? reporter referenced in your link is one way (and references another: patch-ahead distance != nobody). In the dictionary definition, it notes that the reporter reports true when the turtle could move some distance without violating topology- in other words, if the turtle can move to an existing patch. Any patches "off the edge" of a world without world wrapping do not exist, and so return nobody.
tick or tick-advance shouldn't figure into this issue, as the evaluation of the patch-ahead is done by each turtle independent of timing. For example, here's a toy model that doesn't have tick or tick-advance at all:
to setup
ca
crt 200 [
move-to one-of patches with [ not any? turtles-here ]
pd
]
reset-ticks
end
to go
let speed 1 * 0.1
ask turtles [
if can-move? speed and not any? other turtles-on patch-ahead speed [
fd speed
]
]
end
Note that I've turned world-wrapping off entirely, and get a result like what is shown below- no errors, and turtles have stopped moving either because there is a turtle in there way or because they've bumped up against the edge of the world:

Related

Using the command move-to with max-one-of and the error appears: MOVE-TO expected input to be an agent but got NOBODY instead

I'm new to NetLogo and I have a question that I'm sure is pretty basic. But, I'm not getting over the difficulty.
If anyone can help me overcome this difficulty, I would be very grateful.
I would like from the patch where the turtle is found to consider the 8 neighboring cells in search of the highest pveg value. If it has equally high values, choose 1 of these randomly. Upon finding the highest pveg value of the neighbors, the turtle went there.
I am using the command: max-one-of. I think it serves my purpose. But, I'm making some syntax error that shows the following error: MOVE-TO expected input to be an agent but got NOBODY instead.
Thanks in advance
extensions [ gis ]
globals [ veg ]
patches-own [pveg]
to setup
clear-all
reset-ticks
setup-patches
crt 1 [
ask neighbors [ set pcolor blue ]
set color black
]
end
to setup-patches
end
to go
ask turtles [neighboring]
end
to neighboring
let my-neighWith-pveg [ neighbors with [pveg > 0.2] ]of patch-here
ifelse neighWith-pveg = 0
[ ]
[ move-to max-one-of patches [my-neighWith-pveg] set pcolor red ;;ERROR HERE
]
end
The NetLogo dictionary says, max-one-of needs an agentset and a reporter as input:
max-one-of agentset [reporter]
In your code, you use two agentsets: turtles and my-neighWith-pveg
Since you want to chose from the neighbors (and not all turtles) with the hightes pveg, you can write:
max-one-of my-neighWith-pveg [pveg]

Netlogo: two files that have same code: one works, the other marks error

I have two netlogo files with this identical code:
to setup
ca
crt 10
[setxy random-xcor random-ycor]
reset-ticks
end
to go
ask turtles [
ifelse any? turtles-on patch-ahead 1
[rt random 40 lt random 40]
[fd 1]]
tick
end
In this file works: test 1,
but not on this one: test 2. It states
TURTLES-ON expected input to be an agent or agentset but got NOBODY
instead.
Why does this happen?
The error code is part of a larger model that states the same error, how can I fix it?
This issue is due to the difference in world-wrapping in your two files- in Test 1 you have world wrapping on:
Whereas you have it turned off in Test 2:
This means any turtle that reaches the edge of the world is querying a patch that does not exist- a patch outside of the world (nobody). You can either turn world wrapping on, or address the movement model by checking that movement is possible either with something like can-move? or by coding it manually. For example, you could change your go in test 2 to
to go
ask turtles [
ifelse patch-ahead 1 = nobody or any? turtles-on patch-ahead 1
[rt random 40 lt random 40]
[fd 1]
]
tick
end
Note that order matters in this case- you have to check for nobody before checking any? turtles-on patch-ahead 1

Tell agent to not cross a road in Netlogo model

I'm trying to add a condition that doesn't allow an agent to cross over a road. The road patches are set to color red. I can't seem to figure out how to get this condition to work. I ultimately want the agent to turn around if the road is in the patch ahead. Here is my net logo code so far.
to go
ask turtles [
move
]
tick
if ticks >= 60 [stop]
end
to move
ifelse random-float 1 < q
[
ifelse random-float 1 < w
[let target-patch max-one-of neighbors [veg-suitability]
face target-patch]
[let target-patch max-one-of neighbors [pelev]
face target-patch]
]
[
ifelse [pcolor] of patch-ahead 1 = red
[lt random-float 180]
move-to one-of neighbors
ldd-normal
]
end
to ldd-normal
let ldd-distance (ldd-scale)
fd ldd-distance
end
The logic of your move procedure is a bit confused I think. First you have a random chance to either move to a patch with a higher value of a variable of interest (with the uphill primitive) or, if the random draw fails, it moves to a random neighbour. If you don't want it to move onto a red patch then you need to test if the patch that is chosen is red, but you just move it without checking.
After you have moved the turtle, you then check the colour of patch-ahead. Your problem here is that patch-ahead depends on the direction the turtle is facing, which has nothing to do with the direction it has already been moving. You either make it turn (though it may not turn enough) OR move forward. So it never actually moves away.
I can't give you an actual answer because I don't know what your logic is supposed to be. But you could look at structures like:
move-to one-of neighbors with [pcolor != red]
Or, if there are enough red patches that it is possible that there aren't any non-red neighbours (which would cause an error if you tried to move to one), you could use:
let okay-patches neighbors with [pcolor != red]
if any? okay-patches [move-to one-of okay-patches]
Another option is that you only meant to face rather than move to the patch in the first sections of code, then test whether it is facing a red patch and turn around if it is.

Netlogo Reporter Not Reporting

I've made a animal behavior model involving "turtles" and "roads" and I want the model to report back to me when the turtle "crosses" a road. All I want is that it tells me when the turtle moves from a patch that is the grey color to the red color. I've included the code asking it to report this and the program has no issue with the code. To give me a visual representation of what I want it to report, I put a monitor on interface. But it always gives me a "0" for road crossings, even as I can see that my turtle has crossed roads. I would count it by hand, but it's impossible to tell for certain how many road crossings there are and this is for scientific publication. My code is as follows...
turtles-own [
road-crossings
]
to setup
clear-all
;; create turtles on random patches.
ask patch 6 -15 [
sprout 1 [
set color one-of [green]
set size 1
set road-crossings 0
]
]
ask turtles [
if [pcolor] of patch-here = 14.9 [
set road-crossings road-crossings + 1
]
]
reset-ticks
end
to go
ask turtles [
repeat 100 [
repeat 39 [
pen-down
rt random-float 360
lt random-float 360
fd random-float 1.375
]
setxy 6 -15
]
]
tick
end
Any help is appreciated! Thank you!
There are several potential problems with this that I can see.
First, road-crossings is a turtle variable, which is the correct thing to do if you want each turtle to remember how many times it crosses a road. If so, however, the monitor must report sum [road-crossings] of turtles to get the road crossings of all turtles.
Second, which I think is actually your problem: you have the turtle checking whether it crosses the road in the setup procedure rather than the go procedure. The setup procedure is only run at the beginning.
Third, you don't actually have any roads in your example code, but I suspect that's just a failure to create a proper example. I assume that there are patches with pcolor of 14.9 in your real code. If not, though, that would also cause your error. You can make sure by going into the command center and asking count patches with [pcolor = 14.9]

bounce turtle from green patches in netlogo world

I'm trying to implement a bounce turtle logic. When any turtle move towards green patches, I want to set turtles head = set head ( - head)
My code is:
ask turtles [ask turtles [
ifelse [pcolor] of patch-ahead 2 !=[move]
[ set heading ( - heading) ]
Question: but it gives error ( OF expected input to be a turtle agentset or patch agentset or turtle or patch but got NOBODY instead).
How to solve this error?
There appear to be a number of typos in your code sample, but the answer to your immediate question is that if the patch that would be ahead 2 lies outside the world, patch-ahead 2 will return nobody, as there is no such patch. So, when you get nobody, your turtle is very close to the edge of the world. I assume you would want to turn around in that instance as well, so your ifelse might look something like
ifelse (patch-ahead 2 != nobody and [pcolor] of patch-ahead 2 != green)
[move]
[set heading (- heading)]
Note that you need to check for nobody before checking for the color.