WITH expected a TRUE/FALSE block, but got a TRUE/FALSE instead? - netlogo

I have the code
sum [plant-energy] of (patches-with-ash with (pycor > 0 and pxcor > 0)))
for a monitor in my model. plant-energy is a defined patch variable and patches-with-ash is a defined agentset. I'm trying to get a sum of all plant energies for the patches in patches-with-ash in the top-right half of the space, but this returns a weird error.
WITH expected this input to be a TRUE/FLASE block, but got a TRUE/FALSE instead
Any help would be much appreciated!
EDIT:
I'm just using the monitor as a test for my code. I'm trying to sum the plant energy of all patches in the agentset with xcor less than and ycor greater than a turtle (i.e. all patches of this agentset to the upper left of the turtle). I think this is the right avenue to go down but if anyone knows a better way I would appreciate that as well!

try it like this:
sum [plant-energy] of (patches-with-ash with [pycor > 0 and pxcor > 0]))
The [] basically tells NetLogo to do the test within the [] and return a true or false, which is then passed to the with

Related

netlogo: Minimum patch coordinate unit and monitoring availability?

I would like to change the minimum coordinate unit of the patch space, which is set to exist only one turtle per patch space, to less than one, and monitor it. We want to set the minimum spatial unit to the same tick size n as in tick-advance (e.g. n=0.1). Here is a piece of code, but it doesn't work. Can anyone help me? Thanks in advance.
globals [n] ; n<=1 i.e. n=0.1
; omitted
ask turtles [forward n]
tick-advance n
I find myself in the same boat as Matteo- I don't know that what you're looking to do is possible / makes sense in the context of NetLogo. The coordinates of patches are fixed (ie, one patch is one unit) but arbitrary (1 in Netlogo can mean 1 m or 1 km, depending on the model). In other words, a patch's coordinates are discrete, while turtles can move around in continuous space. So you can, of course, have a turtle wander around in step sizes of 1/10:
globals [n]
to setup
ca
set n 0.1
crt 10
reset-ticks
end
to go
ask turtles [
forward n
]
tick-advance n
end
After one run of go above, you could conceivably have a turtle at coordinates [xcor = 0.1, ycor = 0.1], although it would still be on patch 0 0 since pxcor values are integers.
It seems that what you are actually needing to do is not coming across as needed- can you edit your question to provide a little more detail / context? Perhaps knowing the why behind your need to model in this way will help askers get you pointed in the right direction. I personally am curious about:
Why you are using tick-advance instead of just tick
How you have implemented your one-turtle-per-patch restrictions- in other words, can you show a Minimal Reproducible Example? That may prompt other ways to approach what you're after.
Here is an example world with time tied to ticks:
globals [ seconds ]
to setup
ca
set seconds 0
resize-world 0 50 0 50
ask patches with [
floor (pxcor / 10) mod 2 + floor (pycor / 10) mod 2 = 1
] [
set pcolor white
]
crt 10
reset-ticks
end
to go
ask turtles [
fd 1
]
set seconds precision (seconds + 0.1) 2
if seconds mod 1 = 0 [print ( word "It has been " seconds " seconds.")]
tick
end

Averaging neighbors' variables to inform decision

The proejct I'm building is a little too big to post here; I think this snippet should suffice.
breed [CMs CM]
CMs-own [flag?]
to go
set flag? random 2
check-von-neumann-neighborhood
end
to check-von-neumann-neighborhood
create-links-with CMs-on neighbors4
ifelse mean flag? of CMs-on neighbors4 >= 0.5
[set flag? 1]
[set flag? 0]
end
What I'm trying (and failing) to do here is to ask each CM to average the values of "flag?" of its Von Neumann neighbors and then take on that value as its own flag?.
I slapped the create-link-with code on there because I thought it would allow CMs to sense its neighbor's flag?, but that doesn't appear to me the problem.
The error message highlights "flag?" in "ifelse mean flag? of CMs-on neighbors4 >= 0.5" and says "OF expected this input to be a reporter block, but got anything instead."
I would really appreciate any help! Thanks in advance.
You don't need the links, NetLogo can detect the turtles on the neighbouring patches and then access the variables of those turtles. Your problem is that you have flag? of but need [flag?] of.
The error message means that you have used of without telling NetLogo what to report. You need the [ ] to mark the boundary of the reporter block, even if it's simply a variable. Reporter blocks could be complicated calculations so NetLogo needs to know where to start and end the calculations for each entity that is reporting (in this case, all the CMs on the neighbors4).

how to create an agentset with more than 8 neighbors in Netlogo

Netlogo has a primitive "neighbors" that can select 8 neighbors surrounding directly to the target at one time. But what if I wanna create an agentset from multiple layer surroundings, like primitive "in-radius" but in rectangular way, what kind of primitives should I use or how to arrange the codes in Netlogo?
The following code is taken from the Models Library, Code Examples section, Moore & Von Neumann Example. If you want a rectangle rather than a square, you would still take the same approach of selecting particular pxcor and pycor values
to-report moore-offsets [n include-center?]
let result [list pxcor pycor] of patches with [abs pxcor <= n and abs pycor <= n]
ifelse include-center?
[ report result ]
[ report remove [0 0] result ]
end

How to change a turtle's attribute if one of its links disappear?

In NetLogo: suppose the model has
a turtle (0) of breed A with undirected links with 3 turtles (1, 2 and 3) of breed B;
the turtle 0 has an attribute named "number-of-links" that equals 3.
Now, let one of the 3 neighbors of 0 dies..
How can I program turtle 0 to change its number-of-links automatically to 2?
If all you want is a way of keeping track of the number links, use count my-links instead of a custom variable.
In general, the least bug prone way of having a value update when the number of links changes is to compute that value when you need it. For number of links, this is simply count my-links. For more complicated things, wrap them in a reporter:
to-report energy-of-neighbors
report sum [ energy ] of link-neighbors
end
If this doesn't work for whatever reason (agents need to react to a link disappearing or you're seeing a serious, measurable performance hit from calculating on the fly), you'll have to make the updates yourself when the number of links change. The best way to do this is to encapsulate the behavior in a command:
to update-on-link-change [ link-being-removed ] ;; turtle procedure
; update stuff
end
and then encapsulate the things that can cause the number of links to change (such as turtle death) in commands as well:
to linked-agent-death ;; turtle procedure
ask links [
ask other-end [ update-on-link-change myself ]
]
die
end

netlogo programing help on traffic simulation

I am trying to find if there is a turtle on patch-ahead n
whose speed - acceleration is <= 0. The code I came up with is:
if any? turtles on patch-ahead n with [speed <= (speed - acceleration)]
but this gives an error that:
patch-ahead expects a number, instead got agent set.
How do I remedy this?
n is a number variable. I want to access the turtle's 'speed', which is a user defined turtle-own variable, at the nth patch from the calling turtle. The command 'with' doesn't work here. Please suggest an alternative to access the speed of the turtle at, say, the 3rd patch from the calling turtle.
If you look at the patch-ahead documentation you will notice that it does require one argument: a number representing the distance to look ahead. You are using a patch 'n' instead of a number.
As per you comment, I think maybe you want turtles-on, and use parenthesis to make it clearer, as such:
if any? ((turtles-on patch-ahead n) with [speed <= (speed - aceleration)])
In the above I am assuming that n is a number: the distance you want to look ahead.