I'm not sure where of why I am getting a runtime error associated with the citizen-movement action. The employee-movement action does not trigger a runtime error. Here is the error:
OF expected input to be a turtle agentset or patch agentset or turtle or patch but got NOBODY instead.
error while citizen 33 running OF
called by procedure CITIZEN-MOVEMENT
called by procedure GO
called by Button 'go'
to go
employee-movement
citizen-movement
tick
end
to employee-movement
ask employees [
ifelse [pcolor] of patch-ahead 1 = black
[ rt random-float 360]
[ forward 1 ]
]
end
to citizen-movement
ask citizens [
ifelse [pcolor] of patch-ahead 1 = grey
[ rt random-float 360]
[ forward 1 ]
]
end
Is your world wrapping turned off? This error can happen if you have world wrapping off and a turtle is facing the edge. In that case, the primitive patch-ahead doesn't have any patch to refer to, so it returns NOBODY.
Related
In brief below is the code I wrote to show whether there is a turtle on the neighbor patches
to play-the-game
ifelse any? turtles-on neighbors4
[show "turtles-found"]
[show "turtles-not-found"]
end
I need to change it to perform the procedures I have already written out;
if they are the same breed they 'gain-energy'
different breed 'fight-opponent'
I am not sure as to how to change the first part to carry out the other procedures.
If I understand correctly, you need to check the breed of both the asking turtle and the 'opponent' turtle. You're certainly on the right track by checking if there are any neighbors present, the next step is to make the breed check and then the turtles can choose what action to take. For example, look at this toy model where wolves and cows can identify whether they've landed on a patch next to the same breed or not:
breed [ cows cow ]
breed [ wolves wolf ]
to setup
ca
ask n-of 10 patches [
sprout-cows 1 [
set shape "cow"
set color white
]
]
ask n-of 10 patches with [ not any? turtles-here ] [
sprout-wolves 1 [
set shape "wolf"
set color red - 1
]
]
reset-ticks
end
to go
ask turtles [
face one-of neighbors
fd 1
play-the-game
]
tick
end
to play-the-game
if any? turtles-on neighbors4 [
let current-neighbor-turtle one-of turtles-on neighbors4
ifelse [breed] of current-neighbor-turtle = breed [
show "I see one of my own breed!"
] [
show "I see an opponent!!!"
]
]
end
If that's not quite what you had in mind, please edit your question above to provide more detail.
I think you should consider dropping ifelse. In your example, the two possible outcomes of the any? turtles-on neighbors4 condition are mutually exclusive: either there are turtles, or there are not.
However what you want to achieve in your model is a bit different: (I imagine that) on the neighboring cells there can be turtles of the same breed AND turtles of a different breed at the same time. In this case, the two scenarios are not mutually exclusive and using ifelse (where only one or the other of the two command blocks will be executed) would potentially overlook one of the two cases, depending on how you specify the condition.
I think two if statements would be more appropriate:
to play-the-game
if (any-friends-nearby?) [gain-energy]
if (any-opponents-nearby?) [fight]
end
to-report any-friends-nearby?
report (any? (turtles-on neighbors4) with [breed = [breed] of myself])
end
to-report any-opponents-nearby?
report (any? (turtles-on neighbors4) with [breed != [breed] of myself])
end
It is still relevant for you to choose which condition will be checked first (and therefore which action, between gain-energy and fight, will be executed first in case both conditions are satisfied)
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]
I have a model where humans and a door are created. Humans face the door and run to it and exit. The problem is that some humans stop for some reason. Even if only one human is used, it some times reaches the door, and some times it doesn't. What do I have to do so humans always reach the door? This is the model, and this is the code:
globals [ID-door]
breed [door doors]
breed [human humans]
to setup
clear-all
set-default-shape door "star"
crt number [
setxy random-xcor random-ycor
set color cyan
set breed human]
new-door
reset-ticks
end
to new-door
ask one-of patches [sprout-door 1]
ask door [
set color yellow
set size 2
set ID-door who]
end
to go
if count human = 0 [stop]
ask human [
move-human
check-door]
tick
end
to move-human
face doors ID-door
ifelse any? human-on patch-ahead 1
[rt random 40 lt random 40]
[fd 1]
end
to check-door
if any? door-on patch-here [die]
end
Your problem is patch-ahead 1. This looks a distance of 1 in whatever direction the turtle is facing. Imagine the turtle is at the top left corner and looking toward the bottom right corner. The distance to the corner is >1 and the turtle is triggering the 'stay here' check and will be stuck until it is sufficiently turned around so that there is a different patch in front of it.
So you need to get the turtle to exclude itself from the check, which is a job for other. Change ifelse any? human-on patch-ahead 1 to ifelse any? other human-on patch-ahead 1.
I changed the move-human procedure to the following, and now the model works:
to move-human
ifelse patch-ahead 1 = nobody or any? other humans-on patch-ahead 1
[rt random 40 lt random 40]
[fd 1
face door ID-door]
end
As stated by JenB, patch-ahead 1 was the problem, so:
a) Because the world has horizontal and vertical limits (it´s not a wrapped space) the line patch-ahead 1 = nobody checks the absence of patches when such limits are reached.
b) The line other humans-on patch-ahead 1 excludes the current turtle as it may be counted because of the possibility that the distance of 1 may still be inside the current patch, like this image:
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
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: