我如何使用原语 no-patches no-links no-turtles?

How do I use the primitives no-patches no-links no-turtles?

NetLogo 词典包含这些没有示例的条目: 无补丁无链接无海龟

对他们的所有描述都是 "Reports an empty patch/link/turtle agentset."

有人可以举例说明它们是如何使用的吗?

你几乎从不需要它们。通常,它们是这样的,因此您可以初始化您将迭代或随时间构建的代理集。

例如,假设我们有一个文件,其中列出了一堆像这样的补丁坐标:

15 7
-3 18
11 -2

假设我们要获取相应的补丁。你可以这样做:

file-open "my-patch-data.txt"
let specified-patches no-patches
while [ not file-at-end? ] [
  let x file-read
  let y file-read
  set specified-patches (patch-set (patch x y) specified-patches)
]

然而,大多数时候,仅使用 NetLogo 的代理集查询原语(如 withofn-of 等)来构建代理集要容易得多,因此你不需要太多。

编辑:正如 Nicolas 指出的那样,通过构建补丁列表然后将其转换为代理集来执行此操作实际上更快:

file-open "my-patch-data.txt"
let specified-patch-list []
while [ not file-at-end? ] [
  let x file-read
  let y file-read
  set specified-patch-list lput (patch x y) specified-patch-list
]
let specified-patches patch-set specified-patch-list

不过我确实想到了另一个例子。假设您的每只海龟都需要跟踪它们四处移动时遇到的海龟。您可以将其作为海龟集存储在海龟自己的变量中。不过,您需要以某种方式初始化海龟组。这就是 no-turtles 的目的。