Netlogo:变量有时列表有时数字,导致错误
Netlogo: variable sometimes list sometimes number, results in error
我有一个记者,当我 运行 它时它工作正常,但当我向它添加条件时错误地工作。
我所有的海龟都有两个三维向量,称为 var_a
和 var_b
。当我 运行 这对我的整个世界来说都没有问题:
to-report turtle-bounds [p]
let p-lower (([item 0 var_a] of p) - ([item 0 var_b] of p))
let p-upper (([item 0 var_a] of p) + ([item 0 var_b] of p))
let bounds list p-lower p-upper
report bounds
end
但是当我运行它有一个条件时,
to condition
let p1 turtles with-max [item 0 var_a]
turtle-bounds p1
end
我得到以下信息:
- expected input to be a number but got the list [0.9967359117803329] instead.
它引用了 var_a 的值,这意味着我的限制以某种方式使 [item 0 var_a] of p
给出了一个列表而不是一个数字。
有什么想法吗?
turtle-bounds
被编写为以单个代理作为其参数,但 with-max
returns 是一个代理集。在将 p1 提供给 turtle-bounds
之前,您可以使用 one-of
原语将代理集变成代理。
to condition
let p1 turtles with-max [item 0 var_a]
turtle-bounds one-of p1
end
或者,您可以检查 turtle-bounds
中的 p
以查看它是否是代理集
if is-agentset? p [set p one-of p]
并在那里进行转换,尤其是在 turtle-bounds
可能被提供给代理集而不是代理的其他情况下。
我有一个记者,当我 运行 它时它工作正常,但当我向它添加条件时错误地工作。
我所有的海龟都有两个三维向量,称为 var_a
和 var_b
。当我 运行 这对我的整个世界来说都没有问题:
to-report turtle-bounds [p]
let p-lower (([item 0 var_a] of p) - ([item 0 var_b] of p))
let p-upper (([item 0 var_a] of p) + ([item 0 var_b] of p))
let bounds list p-lower p-upper
report bounds
end
但是当我运行它有一个条件时,
to condition
let p1 turtles with-max [item 0 var_a]
turtle-bounds p1
end
我得到以下信息:
- expected input to be a number but got the list [0.9967359117803329] instead.
它引用了 var_a 的值,这意味着我的限制以某种方式使 [item 0 var_a] of p
给出了一个列表而不是一个数字。
有什么想法吗?
turtle-bounds
被编写为以单个代理作为其参数,但 with-max
returns 是一个代理集。在将 p1 提供给 turtle-bounds
之前,您可以使用 one-of
原语将代理集变成代理。
to condition
let p1 turtles with-max [item 0 var_a]
turtle-bounds one-of p1
end
或者,您可以检查 turtle-bounds
中的 p
以查看它是否是代理集
if is-agentset? p [set p one-of p]
并在那里进行转换,尤其是在 turtle-bounds
可能被提供给代理集而不是代理的其他情况下。