NetLogo:所有乌龟死亡时出现n错误 [英] NetLogo: n-of error when all turtles die

查看:157
本文介绍了NetLogo:所有乌龟死亡时出现n错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模拟,乌龟会踩到红色斑点并死亡,这是可行的,但是只要大多数/所有乌龟都死了,其中所有带有n-of的东西都会报告错误.我确实理解错误,因为在没有乌龟的情况下模拟尝试获取n-of,但是我该如何解决?在模拟结束时,所有乌龟都死了,有没有办法使用n-of? 如果有,我该怎么办?, 如果不是,是否有其他方法可以使海龟死在红色斑块上? 我的模拟要求每只乌龟在红色斑块上行走时都必须走开,但它们不能彼此行走/越过,这将使它们很难聚集在一个红色斑块上(大约有500只海龟)

I have a simulation where turtles walk onto red patches and die, which works, but everything that has n-of in it reports an error as soon as most of/all turtles are dead. I do understand the error, since the simulation tries to get n-of while there is no turtle left, but how do i fix that? Is there a way to use n-of when at the end of the simulation all the turtles are dead? If there is, how do I do it?, and if not, is there an alternative way to making the turtles die on red patches? My simulation needs every turtle to be gone as soon as it walks on a red patch, but they can't walk on/over each other, which would make it hard to let them gather on one red patch (there are about 500 turtles).

谢谢! 我编辑了代码,因此不再需要n-.现在,我想要一只乌龟将笔模式设置为向下"的代码部分是

Thank you! edit: I edited my code so that I don't need n-of anymore. Now, the part of my code where I want one turtle to set pen-mode to "down" is

to go .... ask one-of turtles [set pen-mode "down"] .... end

to go .... ask one-of turtles [set pen-mode "down"] .... end

,现在错误消息是:

ASK期望输入是座席或座席集,但改为NOBODY. 观察者运行ASK时出错 通过过程GO调用 由Button'go'调用

ASK expected input to be an agent or agentset but got NOBODY instead. error while observer running ASK called by procedure GO called by Button 'go'

模拟结束后.

建议使用one-of turtles,但是现在每只乌龟都将其笔模式设置为向下",但是我只希望一只乌龟能够做到这一点.

The one-of turtles was suggested, but for now every turtle sets its pen-mode to "down", but I only want one turtle to do that.

推荐答案

您并没有告诉我们您正在使用n-of for 做什么,因此很难建议一种替代方法.但是总的来说,当没有足够的海龟可供选择时,防止n-of崩溃的方法是使用类似

You are not telling us what you are using n-of for, so it's hard to suggest an alternative approach. But in general the way to prevent n-of from crashing when there are not enough turtles to select, is to use something like:

n-of (min list n count turtles) turtles

其中n是您希望选择的海龟数量.

where n is the number of turtles that you would like to select if possible.

这篇关于NetLogo:所有乌龟死亡时出现n错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆