How to include more breeds in max-one-of and plot the highest value found and its distribution

≡放荡痞女 提交于 2019-12-25 01:14:08

问题


I am using lists to build a model. I have three breeds, but only two of them have their own lists where to collect items created (and that should create items). I would like to select a random turtle and find the item with highest attribute into its bag. Then I would like to plot the attribute and its distribution as follows:

plotxy attribute1 fun2

where attribute1 is the attribute defined within the ask link-neighbors:

set attribute1 attribute1_b - m

and fun2 should be defined as set fun2 (1 - [attribute1]) where attribute1 should be the attribute of the 'selected' item with highest attribute in the bag.

Since I have three breeds involved in this part of code, children, infants and toy, respectively, but I would like to consider to plot only attributes generated by children and infants, I would like to ask you how to define the toy with highest attribute in the bag, then how to plot it for both children and infants.
From my previous question Error in plotting: OF expected input to be a turtle agentset or turtle I received this answer:

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

but in this current case the maximum could be not only of children, but also of infants. I tried to write:

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

but I got the following error:

AND expected this input to be a TRUE/FALSE, but got an agentset instead

I am a self-taught, I read a lot of material on the websites, but sometimes I cannot find what I would like to look for. I make mistakes, a lot of mistakes, but probably this is also a good way to learn (and to keep in mind to avoid to repeat the same). I hope you can understand and try to help me to figure out with this new issue. Thanks.


回答1:


The problem is that you are combining two agentsets (a subset of children and a subset of infants) with the keyword and, but and is reserved for logical operations. To combine two agentsets, we use the turtle-set primitive as so.

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

The () around turtle-set is required because we are giving it more than one argument. (I haven't looked at the rest of your code, just this line.) Hope it helps.



来源:https://stackoverflow.com/questions/59238995/how-to-include-more-breeds-in-max-one-of-and-plot-the-highest-value-found-and-it

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