【问题标题】:How can I record the arrival order of agents in NetLogo?如何在 NetLogo 中记录代理的到达顺序?
【发布时间】:2015-12-01 12:34:46
【问题描述】:

在我的模型中,我希望一个龟品种(食物)记录许多其他品种(捕食者)到达它的顺序。

到目前为止,我有这段代码可以告诉我谁在那里,但不保留到达顺序:

if ticks = day-length [
print [who] of turtles-here with [who != [who] of myself]

任何建议都将一如既往地受到赞赏。如果提供更好的方法,我确实启动并运行了 RNetLogo。

谢谢

获取我想要的数据的一种丑陋方法是使用两行单独的代码

  ask other turtles-here [show got-here]

  foreach   sort-by < [got-here]  of turtles-here with [shape = "default"]
  [
  show   ? 
  ]]

【问题讨论】:

  • 作为一般评论,使用who 几乎总是使NetLogo 代码更复杂,而不是更简单。相反,直接比较和操作海龟turtles-here with [who != [who] of myself] 减少到turtles-here with [self != myself] 或只是other turtles-here

标签: netlogo


【解决方案1】:

首先,如果每块食物要记录自己的列表,您需要向food-own 代理变量列表添加一个变量(例如“predator-order”)。然后在创建食物时将列表初始化为空 (set predator-order [])。不要在列表中使用who。相反,将代理添加到列表中。没有看到周围的代码,很难得到正确的语法,但它会是这样的:

ask this-food
[ set predator-order lput myself predator-order ]

【讨论】:

  • 您好,我试过这个并得到“我自己没有代理可以参考。 food 4 运行 MYSELF 时出错'
  • 正如我所说,如果不查看周围的代码,我就无法获得正确的语法。但是,我假设你有类似ask predators [move and eat and find food .... 的东西然后在那个代码的某个地方,你有捕食者要求它找到的食物将自己(捕食者)添加到列表中。 myself 指的是问过食物的捕食者...
【解决方案2】:

您可以将它们保存为 Food 拥有的列表。但我认为最好的办法是让 Predators 记住。

让掠食者像这样跑

if food-here != nobody and been-here = 0 [set got-here ticks]     

来过最少的人到过那里的时间最长。

这样检查

  ask food [print [who] of predators-here with-min[got-here]]

这是假设您正在使用刻度

显示列表

foreach sort-by < [got-here]
  [
  show ? ;; 
  ]

最好还是列个清单

let here-list
foreach sort-by < [got-here]
  [
  set  here-list lput ? here-list
  ]

【讨论】:

  • 你的建议我差不多了。 with-min[got-here] 只给了我一个值,即最小值。我可以用show sort-by &lt; [got-here] of turtles-here 打印正确的订单,但是我失去了他们的身份
  • 我会扩展我的答案来解决这个问题
  • 感谢您的回复。就目前而言,如果我使用您的“显示列表”如下:if any? turtles-here [if ticks = day-length - 10 [ foreach sort-by &lt; [got-here] of turtles-here with [shape = "default"] [ show ? ]]] 代码再次以正确的顺序给我打勾,但不是代理人的身份/谁。
  • 尝试使用 who 而不是 ?
  • 如果我使用 who 而不是 ?它给出了食物的数量列表,其长度与以它为食的动物数量相同
猜你喜欢
  • 2016-01-06
  • 2014-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-23
相关资源
最近更新 更多