我的 ifelse 语句的结果取决于 true/false 的操作?
目前,我正在为卡车构建一条在我的 netlogo 土地内行驶的路线。 当卡车靠近其应送货的商店区域时,卡车需要改变其动作。
但是,我的 if
或 ifelse
语句似乎响应不佳,答案取决于输出。通过一些测试:
*turtles> ifelse ((patch (first dirx) (first diry)) = one-of neighbors4) [write "11"] [write "22"]
"11"*
*turtles> ifelse ((patch (first dirx) (first diry)) = one-of neighbors4) [write "111"] [write "122"]
"122"*
*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "111"] [write "122"]
"122"*
*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "11"] [write "12"]
"12"*
*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "11"] [write "22"]
"11"*
请注意,在这段时间我没有移动我的卡车,我使用指挥中心来询问这些问题(从海龟卡车的角度)。
我对此很困惑。因为我唯一改变的是行动(写什么)。这不应影响真/假陈述本身。
有人知道这里发生了什么以及为什么 ifelse
的反应很奇怪吗?
Currently I am building a route for a truck to drive inside my netlogo-land.
When the truck is next to the shop-patch where it should deliver, the truck needs to change its actions.
However my if
or ifelse
statement does not seem to respond well and the answer depends on the output. With some tests:
*turtles> ifelse ((patch (first dirx) (first diry)) = one-of neighbors4) [write "11"] [write "22"]
"11"*
*turtles> ifelse ((patch (first dirx) (first diry)) = one-of neighbors4) [write "111"] [write "122"]
"122"*
*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "111"] [write "122"]
"122"*
*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "11"] [write "12"]
"12"*
*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "11"] [write "22"]
"11"*
Please note that during this time I do not move my truck, I use the command center to ask these questions (from turtle truck perspective).
I am very confused about this. As the only thing I change is the action (what to write). This should not impact the true/false statement itself.
Does anybody have any clue what is going on here and why the ifelse
responds strange?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
one-of
随机选择其参数之一并返回该参数。neighbors4 返回一个包含 4 个补丁的主体集(海龟补丁的 N、S、E 和 W)。因此,one-of Neighbors4 将从这 4 个邻居中随机选择,因此每次调用它时它可能会返回不同的值。
It's because the
one-of
randomly chooses one of its arguments and returns that one.neighbors4
returns an agentset with 4 patches (the ones N,S,E, and W of the turtle's patch). Thus,one-of neighbors4
will randomly choose from among these 4, so it might return a different value each time you call it.