Merge traffic bands in NetLogo simulations

I want to write a NetLogo program to combine car lanes. Vehicles are located in 4 tracks divided by 3.5 meters (each patch is 1 m). The center coordinates of each band are ycor-3.75, -7.25, -10.75 and -14.25.

Vehicles have random values xcorwith values ycorin the center of one of the lanes and are sent to the right. I want the traffic to merge, so that cars moving to the center of the map ( distancexy 0 0 <50) move in the same lane by ycor = -14.25, as shown in the figure. Thus, the car already in this lane continues forward, but cars in other lanes turn 45 degrees to switch lanes, and then turn 45 degrees to the left when they reach pycor = -14.25.

What I want

Cars turn right. However, the conditions that I set to leave the car again when it reaches ycor = -14.25 do not work. Instead, the car continues to move forward, crossing the lane, as in the following figure.

What is really going on

My code is:

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

:

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

, , :

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

ifelse if, , ycor -10.75. ycor -10,75 -14,25? , .

, , :

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

" ycor -10.75, , ycor -14.25, ".

+2

, , ycor -14.25, -14.25. , , -14,5 -14,0 - , -14,25. , , -14.25. - :

ifelse ycor = -14.25
[ fd speed ]
[ if heading = 90 [ rt 45 ]
  fd speed
  if ycor <= -12.5
  [ set heading
    set ycor -14.25
  ]
]
+2
 ifelse ycor = -14.25 [
    fd speed
    ]
    [
    rt 45
    fd speed
    ifelse ycor = -14.25
       [
       lt 45
       fd speed
       ]
       [
       fd speed
       ]
    ]
   ]
0
source

Source: https://habr.com/ru/post/1621301/


All Articles