在NetLogo模拟中合并行车线 [英] Merge traffic lanes in NetLogo simulation

查看:148
本文介绍了在NetLogo模拟中合并行车线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个NetLogo程序来合并汽车车道.车辆位于4条车道上,相距3.5米(每个斑块代表1m).每个车道的中心坐标的ycor值分别为-3.75,-7.25,-10.75和-14.25.

I want to write a NetLogo program to merge automobile lanes. Vehicles are in 4 lanes, separated by 3.5 meters (with each patch representing 1m). The center coordinates of each lane are at ycor values of -3.75, -7.25, -10.75 and -14.25.

车辆具有随机的xcor值,其中ycor值位于其中一个车道的中心,并且向右行驶.我希望交通合并,以便朝地图中心(distancexy 0 0 <50)行驶的汽车都以ycor = -14.25移到同一车道,如图所示.因此,已经在该车道中的汽车继续向前行驶,但其他车道中的汽车向右转45度以切换车道,然后在到达pycor = -14.25车道时向左转45度.

Vehicles have random xcor values with ycor values at the center of one of the lanes, and are heading to the right. I want the traffic to merge so that cars driving toward the center of the map (distancexy 0 0 <50) all move to the same lane at ycor = -14.25 as pictured. So the car already in that lane continues forward, but the cars in other lanes turn right 45 degrees to switch lanes and then turn left by 45 degrees when they reach the pycor = -14.25 lane.

汽车向右转.但是,我设定的条件是在达到ycor = -14.25时再次将汽车转左.相反,汽车继续向前行驶,越过车道,如下图所示.

The cars turn right. However, the conditions I have set to turn the car left again when it reaches ycor = -14.25 are not working. Instead, the car continues straight ahead, crossing the lane as in the next figure.

我的代码是:

ifelse ycor = -14.25
[ fd speed ]
[ rt 45
  fd speed
  ifelse ycor = -14.25
  [ lt 45
    fd speed ]
  [ fd speed ]
]
]

推荐答案

您写道:

if ycor = -10.75
[
  rt 45
  fd speed 
  ;;;fd 5.1
  ifelse ycor = -14.25
  [
    lt 45
    fd speed 
  ]
  [
    fd speed 
  ]
]

如果我遗漏了一些无关紧要的东西,那就是

If I leave out some things that don't matter, that's:

if ycor = -10.75
[
  ...
  ifelse ycor = -14.25
  [
    ...

ifelseif内部,因此仅在ycor为-10.75时运行.但是ycor如何等于-10.75,等于-14.25?不能,所以第二个条件永远不会触发.

The ifelse is inside the if, so it only runs if ycor is -10.75. But how can ycor be equal to -10.75, and equal to -14.25? It can't, so the second condition never triggers.

也许您想要的结构是:

ifelse ycor = -10.75
[
  ...
]
[
  ifelse ycor = -14.25
  [
    ...

这是您的表达方式:如果ycor为-10.75,请执行此操作;但如果ycor为-14.25,则请执行此操作".

this is how you express "if ycor is -10.75, do this; but if ycor is -14.25, do that instead".

这篇关于在NetLogo模拟中合并行车线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆