超车情景我怎么能让一辆车超过另一辆?

时间:2018-04-06 16:38:03

标签: netlogo

在道路上有两条车道的情况下,在现实生活中,你只能通过从外面的车道移动到内侧车道,然后一旦车辆通过返回到外面的车道,在净徽标i的情况下让它知道汽车会检查前面和左边的补丁,看看是否还有另一辆车,如本段编码中所示,如果车内没有车,车仍然在行驶,如果有的话是汽车减速的另一辆车,或者如果前面的车停了,那么汽车就会停下来。

我的问题是我定义了一个要检查的补丁集,称为“左上”我希望汽车在前面只要左侧补丁集中没有汽车时移动到另一条车道,如果汽车在内侧车道上,并且没有车辆在左边但是在右边的类似补丁中,车辆可以移回到外侧车道。

我尝试过这种编码,但出于某种原因,汽车没有超车,偶尔会占用相同的空间,我不确定我是否使用ifelse声明错误,我怎么能让一辆车超过拿另一个?

to control-speed01
let in-lane (patch-set patch-ahead 2 patch-ahead 1 )
let car01-ahead one-of cars01-on in-lane
let on-left (patch-set patch-left-and-ahead 90 1 patch-left-and-ahead 45 1.5 patch-left-and-ahead 135 1.5)
let on-right (patch-set patch-right-and-ahead 90 1 patch-right-and-ahead 45 1.5 patch-right-and-ahead 135 1.5)

ifelse car01-ahead = nobody  [
ifelse speed < maxSpeed [set speed speed + acceleration] [set speed speed - deceleration]
]
[

ifelse [speed] of car01-ahead = 0 [ifelse turtles-on on-left = nobody  [move-to patch-left-and-ahead 90 1][set speed 0]][
  ifelse [speed] of car01-ahead >= maxSpeed [
    set speed maxSpeed
    set speed speed - deceleration
   ][
 set speed speed
   ]]

  ifelse [speed] of car01-ahead = 0 [ifelse turtles-on on-right = nobody  [move-to patch-right-and-ahead 90 1][set speed 0]][
  ifelse [speed] of car01-ahead >= maxSpeed [
      set speed maxSpeed
    set speed speed - deceleration
  ] [
set speed speed
]]]

end

0 个答案:

没有答案