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

本秂侑毒 提交于 2019-12-24 19:39:55

问题


I am studying a model where children play with some toys.

The characteristics of the toys are included in attribute1. I had to create a new variable, attribute1_b, as I wanted to have initially the same original value for the neighbours in order to subtract a small quantity m. I would like to plot the new value of attribute1 to study how it changes through time, respect of fun2 (i.e. 1- (attribute1-m)), but unfortunately I have found difficulties in defining fun2 (global, children-own, and/or toys-own).

After plotting

ask children [plotxy [attribute1] of picked_toy fun2]

I have got the following error message:

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

Could you please tell me what the message is referring to and how to fix it? It is important for me to consider the attribute1 related to the picked_toy, as its value can be equal to attribute1 (as in myself) or attribute1 - m (as in ask link-neighbors).

The code that I am using for building the model is the following

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
]

One procedure, to proc1, includes the definition of attribute1 and fun1 as follows:

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
               ]
            ]

Another one,to proc2, should include the definition of 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
]

UPDATE: I am also getting the following error message (because of 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.

I cannot understand where 0 comes from...

All comments and clarification are more than welcome. Thanks


回答1:


First, 'picked_toy' should be a turtle attribute so uncomment it there and delete it from the global variables. A global variable is something that is the same for every agent in your model. Clearly, each child has its own toy, so that needs to be an agent variable. This is what agent variables do - each agent has its own copy (which can be different or the same as those of other agents). You need to get this concept clear if you want to make any progress in NetLogo and I suggest redoing some tutorials.

This line set picked_toy max-one-of turtle-set bag [attribute1] doesn't really make sense. The variable 'bag' is a list. The primitive max-one-of applies to an agentset. I think you have tried to use turtle-set to convert the list to an agentset, but that won't work. The correct way to turn a list of turtles into an agentset is:

turtles with [member? self listname]

Does your code work if you have:

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

As I have mentioned in responses to some of your other questions, unless you have a good reason to use lists (like needing to keep the order, or having multiple copies), it is generally better to use agentsets because they are easier to work with, particularly for beginners.



来源:https://stackoverflow.com/questions/59220098/error-in-plotting-of-expected-input-to-be-a-turtle-agentset-or-turtle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!