绘图错误:OF 预期输入是海龟代理集或海龟

Error in plotting: OF expected input to be a turtle agentset or turtle

我正在研究 children 玩一些玩具的模型。

玩具的特性包含在attribute1中。我必须创建一个新变量 attribute1_b,因为我希望邻居的初始值相同,以便减去少量 m。我想绘制 attribute1 的新值来研究它如何随时间变化,尊重 fun2(即 1- (attribute1-m)),但不幸的是我在定义 [=18= 时遇到了困难] (global, children-own, and/or toys-own).

绘图后

ask children [plotxy [attribute1] of picked_toy fun2]

我收到以下错误消息:

Runtime Error: OF expected input to be a turtle agentset or turtle but good the number 0 instead

您能告诉我消息指的是什么以及如何解决吗? 考虑与 picked_toy 相关的属性 1 对我来说很重要,因为它的值可以等于 attribute1(如 myself)或 attribute1 - m(如 ask link-neighbors).

我用于构建模型的代码如下

globals [
      this-toy
      attribute1_b
    ]

breed [children child]
breed [toys toy]

children-own [
  bag

  fun1
  fun2
  attribute1
  picked_toy
]

toys-own[
  fun1
  attribute1
  m_children
]

一个过程,to proc1,包括 attribute1 和 fun1 的定义如下:

if breed = children[
          set selected children

          hatch-toys 1 [
            set m_children selected
            set attribute1 random-float 1
            set attribute1_b attribute1
            set fun1 (1 - attribute1)

            set this-toy self

            ask myself [
              set bag fput this-toy bag
            ]
         ]
                ask link-neighbors [
                   let m random-float 0.01
                   set attribute1 attribute1_b - m

                   set bag fput this-toy bag
               ]
            ]

另一个,to proc2,应该包括 fun2 的定义:

if breed = children [
        set picked_toy max-one-of turtle-set bag [attribute1]
        set fun2 (1 - [attribute1] of picked_toy)
        set bag fput picked_toy bag
]

更新:我也收到以下错误消息(因为 max-one-of turtle-set):

List inputs to TURTLE-SET must only contain turtle or turtle agentset elements. The list [(toy 20) 0] contained 0 which is NOT a turtle or turtle agentset.

我无法理解 0 的来源...

非常欢迎所有评论和澄清。谢谢

首先,'picked_toy' 应该是海龟属性,所以取消注释并将其从全局变量中删除。全局变量对于模型中的每个代理都是相同的。显然,每个 child 都有自己的玩具,因此它需要是一个代理变量。这就是代理变量的作用——每个代理都有自己的副本(可以与其他代理的副本不同或相同)。如果你想在 NetLogo 中取得任何进展,你需要弄清楚这个概念,我建议重做一些教程。

这一行 set picked_toy max-one-of turtle-set bag [attribute1] 真的没有意义。变量 'bag' 是一个列表。原语 max-one-of 适用于代理集。我认为您已尝试使用 turtle-set 将列表转换为代理集,但这行不通。将海龟列表转换为代理集的正确方法是:

turtles with [member? self listname]

如果您的代码有效:

set picked_toy max-one-of (children with [member? self bag]) [attribute1]

正如我在回答您的其他一些问题时提到的那样,除非您有充分的理由使用列表(例如需要保持顺序,或拥有多个副本),否则通常最好使用代理集,因为它们更容易使用,特别是对于初学者。