Netlogo:询问 "up to a maximum number"

Netlogo: asking "up to a maximum number"

有没有办法要求达到一定数量的补丁?例如,询问最多 100 个补丁,但只有 50 个可用,因此将对这 50 个补丁执行操作。谢谢

目前执行此操作的方法如下:

to-report at-most [n agents]
  report ifelse-value (n <= count agents) [ agents ] [ n-of n agents ]
end

然后你可以说ask at-most 100 patches [ ... ],你会得到你想要的。

请注意,如果您的变量有可能包含 nobody 而不是代理集,这将不起作用。在这种情况下,您可以使用 patch-setturtle-setlink-setnobody 转换为代理集,具体取决于您希望它包含的代理类型。例如:

ask one-of turtle-set other turtles-here [ ... ]

请注意,跳过所有这些障碍的需要在不久的将来可能会消失。目前有一个开放的提议,向 NetLogo 添加一个原语来处理这些情况:https://github.com/NetLogo/NetLogo/issues/1594.