如何在Netlogo的特定方向上找到最近的代理?
在模型库中包含的基本流量模型中,添加了以下行:
ask turtles with [color = red]
[set car-ahead min-one-of other turtles in-cone 50 0 [distance myself]]
将把汽车视为可能在红色汽车后面的汽车。我该如何强迫最小距离朝着旅行方向 - 在前方找到最近的汽车?
In the basic traffic model included in the models library, adding the following line:
ask turtles with [color = red]
[set car-ahead min-one-of other turtles in-cone 50 0 [distance myself]]
will set the car-ahead to be a car that may be behind the red car. How could I force the minimum distance to be in the direction of travel - to find the nearest car in front?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有几个选择。
我的第一个选择是减少乌龟外观的领先地位。只有在汽车前面最多落后世界一半的汽车才被认为是前进的。哦,这可能意味着并不总是可以将汽车视为前面最接近的汽车,因此,根据您的确切需要,这可能是不够的。
下一个版本相反,确保焦点车的前面总是有汽车。我删除了此特定示例的内部侧面,因为在基本的流量模型中,您指定的圆锥体中的所有其他乌龟。首先,我使用
(Xcor- [Xcor]我自己)
互相检查乌龟在焦点乌龟前的距离。这给您带来了一些世界包装问题。这就是为什么我添加了第二部分(xcor- [xcor]我自己)mod(max -pxcor -min -pxcor)
。总长度的模量可确保,如果的结果(xcor- [xcor]我自己)
是一个负数,则从世界长度上提取,结果为正数。There are several options here.
The first option I had was to reduce how far ahead the turtle looks. Only the cars that fall at most half of the world length ahead of the car are considered to be ahead. Oh course this might mean there is not always a car that can be considered the closest car in front, so it might not be sufficient depending on what exactly you need.
The next version instead insures that there is always a car infront of the focal car. I removed the in-cone for this specific example because in the basic traffic model, every single other turtle is in the cone that you specified. First of, I use
(xcor - [xcor] of myself)
checks for each other turtle how far in front of the focal turtle thay are. This gives you some problems with world wrapping. That is why I added the second part(xcor - [xcor] of myself) mod (max-pxcor - min-pxcor)
. The modulus of the total world length ensures that if the result of(xcor - [xcor] of myself)
is a negative number, it is substracted from the world length with a positive number as result.这就是“内部50 0”中的零。见词典。
That's what the zero in "in-cone 50 0" accomplishes. See the dictionary.