List 基于对自身变量的操作创建列表
我有3只海龟,每只都有一个大小变量。我想创建一个维度3的列表,它基本上是每个海龟的支持大小占总大小的%。列表应该如下所示List 基于对自身变量的操作创建列表,list,netlogo,List,Netlogo,我有3只海龟,每只都有一个大小变量。我想创建一个维度3的列表,它基本上是每个海龟的支持大小占总大小的%。列表应该如下所示 [turtle1-size / sum[size] of all turtles turtle2-size / sum[size] of all turtles turtle3-size / sum[size] of all turtle] 我知道有海龟自己的和补丁自己的列表,但那只会包含海龟/补丁名称本身的列表,对吗 谢谢,谢谢你的帮助 关于这里有一个解决方案: to-r
[turtle1-size / sum[size] of all turtles
turtle2-size / sum[size] of all turtles
turtle3-size / sum[size] of all turtle]
我知道有海龟自己的和补丁自己的列表,但那只会包含海龟/补丁名称本身的列表,对吗
谢谢,谢谢你的帮助
关于这里有一个解决方案:
to-report proportions
let total-size sum [size] of turtles
report (list [size / total-size] of turtle 0
[size / total-size] of turtle 1
[size / total-size] of turtle 2)
end
让我们试试看:
observer> clear-all
observer> create-turtles 3 [ set size who ]
observer> show proportions
observer: [0 0.3333333333333333 0.6666666666666666]
我觉得不错。这里有一个解决方案:
to-report proportions
let total-size sum [size] of turtles
report (list [size / total-size] of turtle 0
[size / total-size] of turtle 1
[size / total-size] of turtle 2)
end
让我们试试看:
observer> clear-all
observer> create-turtles 3 [ set size who ]
observer> show proportions
observer: [0 0.3333333333333333 0.6666666666666666]
我觉得不错