如何在Netlogo的特定方向上找到最近的代理?

发布于 2025-02-07 06:51:04 字数 215 浏览 2 评论 0原文

在模型库中包含的基本流量模型中,添加了以下行:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对你而言 2025-02-14 06:51:04

这里有几个选择。

我的第一个选择是减少乌龟外观的领先地位。只有在汽车前面最多落后世界一半的汽车才被认为是前进的。哦,这可能意味着并不总是可以将汽车视为前面最接近的汽车,因此,根据您的确切需要,这可能是不够的。

  ask turtles with [color = red] [
    let half-size (max-pxcor - min-pxcor) / 2
    set car-in-front min-one-of other turtles in-cone half-size 0 [distance myself]
    ask car-in-front [set color yellow]
  ]

下一个版本相反,确保焦点车的前面总是有汽车。我删除了此特定示例的内部侧面,因为在基本的流量模型中,您指定的圆锥体中的所有其他乌龟。首先,我使用(Xcor- [Xcor]我自己)互相检查乌龟在焦点乌龟前的距离。这给您带来了一些世界包装问题。这就是为什么我添加了第二部分(xcor- [xcor]我自己)mod(max -pxcor -min -pxcor)。总长度的模量可确保,如果的结果(xcor- [xcor]我自己)是一个负数,则从世界长度上提取,结果为正数。

  ask turtles with [color = red] [
    set car-in-front min-one-of other turtles [(xcor - [xcor] of myself) mod (max-pxcor - min-pxcor) ]
    ask car-in-front [set color yellow]
  ]

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.

  ask turtles with [color = red] [
    let half-size (max-pxcor - min-pxcor) / 2
    set car-in-front min-one-of other turtles in-cone half-size 0 [distance myself]
    ask car-in-front [set color yellow]
  ]

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.

  ask turtles with [color = red] [
    set car-in-front min-one-of other turtles [(xcor - [xcor] of myself) mod (max-pxcor - min-pxcor) ]
    ask car-in-front [set color yellow]
  ]
囚我心虐我身 2025-02-14 06:51:04

这就是“内部50 0”中的零。见词典。

距离距离角

这个记者让您在面前给乌龟一个“视力锥”
本身
。锥由两个输入(视觉距离)定义
(半径)和视角。观看角可能从0到
360,以乌龟的当前标题为中心。

That's what the zero in "in-cone 50 0" accomplishes. See the dictionary.

in-cone distance angle

This reporter lets you give a turtle a "cone of vision" in front of
itself
. The cone is defined by the two inputs, the vision distance
(radius) and the viewing angle. The viewing angle may range from 0 to
360 and is centered around the turtle's current heading.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文