NetLogo 两个代理集操作

发布于 2024-12-20 06:37:48 字数 325 浏览 7 评论 0原文

我有两个代理集。是否有用于查找的函数:

  1. 两个中都存在的代理的代理集(交叉点)
  2. 一个中存在而不是另一个中存在的代理的代理集

我发现手动实现这一点非常困难,特别是当它需要在其中时三重 ask

理想的用法类似于 with 语法:

let cross set1 and-in set2
let uniq set1 with [color = red] not-in set2

简单的事情,例如“代理 A 在代理集 X 中吗?”有问题

I have two agentsets. Are there functions for finding:

  1. An agentset of agents that are present in both (intersection)
  2. An agentset of agents that are present in one and not the other

I'm finding it very difficult to implement this by hand, especially when it's needed inside of a triple ask

Ideal use would be similar to with syntax:

let cross set1 and-in set2
let uniq set1 with [color = red] not-in set2

Simple things like "Is agent A in the agentset X?" are problematic

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初心 2024-12-27 06:37:48

对于第一个,您使用turtle-set原语。对于第二个,您需要 member? 原语,它也适用于代理集。像这样:

to setup
  ca
  create-turtles 10 [set color red]
  create-turtles 10 [set color blue]
  let red-ones turtles with [color = red]
  let blue-ones turtles with [color = blue]

  ;join 2 agent sets
  let joinset (turtle-set red-ones blue-ones)
  show joinset

  let even-ones (turtles with [who mod 2 = 0])
  ;subtract even-ones from red-ones
  let subtractset red-ones with [not member? self even-ones]
  show subtractset
end

For the first one you use the turtle-set primitive. For the second one you need the member? primitive, which also works on agentsets. As such:

to setup
  ca
  create-turtles 10 [set color red]
  create-turtles 10 [set color blue]
  let red-ones turtles with [color = red]
  let blue-ones turtles with [color = blue]

  ;join 2 agent sets
  let joinset (turtle-set red-ones blue-ones)
  show joinset

  let even-ones (turtles with [who mod 2 = 0])
  ;subtract even-ones from red-ones
  let subtractset red-ones with [not member? self even-ones]
  show subtractset
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文