Reporter not coded correctly?

Hello. I’m running an epidemiology model on a network. I have a turtle(node) boolean variable that determines if my node is infected. I want the model to stop running if there are no infected nodes present (they clear the infection). Here is my code. I put this first in the GO statement so it checks before running anything else. I’m getting an error that says “Expected reporter’. And ‘stop’ is highlighted. I don’t understand why stop is the reporter. the reporter for the with statement should be [infected-node? = FALSE], no? Basically, i’m trying to say, if none of the nodes present are infected, then stop running.

Update- ok, wait, i think it’s missing the reporter for the all? statement. but I tried putting the brackets

and

Neither of these work either. What reporter do i put with all? and where do I put the square brackets.

I appreciate the feedback.
thank you!

Hi @pandora,

The syntax for all? requires two arguments, an agentset followed by a reporter to test on each agent in the set. However, the with primitive that you’re using causes the reporter to be applied directly to nodes to create a new agentset before using it for all?, rather than using nodes and the reporter as separate inputs to all?. To fix this problem, you can simply remove the with primitive; it should look something like if all? nodes [ infected-node? = FALSE ]. Hopefully this makes the issue more clear, but let me know if you still have any questions!

Isaac B.

The standard way to do this is:

if not any? (nodes with [infected-node?])
[

stop

print…

]

Thank you both! It worked.

Is there a reason why Steve’s answer may be better in terms of programming? why use the not any? instead of the all? will this increase speed at all; bc right now, it’s running realllllly slow and i’ll have to go through and figure that out in a bit.

Thanks again!

I don’t think speed is really a concern here, but you could argue that not any? more accurately represents your intended check. Also, then you don’t need anything in the reporter block except the target variable, which is a bit nicer to look at and understand. If it’s really running that slowly, the cause is most likely somewhere else in your code.

Isaac B.

1 Like

My two cents: I would definitely put print before stop, or you won’t see the message…

:slight_smile: HAHHAHA, yeah, i caught that!