Здравствуйте, я новичок в netlogo, ваша помощь будет оценена по достоинству.Я моделирую автомобили на перекрестке / перекрестке. Автомобили этой модели используют левую сторону дороги для движения.У меня 2 вопроса.
Назначение вероятностей для автомобилей, прибывающих из другого перекрестка, для поворота влево или вправо или без поворота.
например, когда заголовок 90 автомобиля X достигает патча pxcor = 137 и pycor = 155, чтобы иметь 0,3 вероятности сделать левый поворот или 0,7 вероятности движения прямо.Как только Car X достигнет pxcor = 138 и pycor = 155, вероятность поворота направо составит 0,4, а вероятность выпрямления - 0,6.
та же логика будет применяться к автомобилю Y, курс 270 - у этого автомобиля 0,6 вероятности сделать первый левый поворот или 0,4 вероятности продолжения движения при достижении заплатами pxcor = 138 и pycor = 154,Как только автомобиль Y достигает pxcor = 137 и Pycor = 155, вероятность поворота вправо составляет 0,2, а вероятность не повернуть (0,8) - 0,8
Как мнесделать так, чтобы автомобили не использовались в мире, как только они покинут дорожную развязку.Что происходит в моей модели, так это то, что когда автомобиль x поворачивает налево, он снова появляется как Автомобиль XY на дороге pxcor = 137 и (pycor> 21 и pycor <154) и означает! = "Перекресток" </p>
Можете сослаться на мой код и прикрепленное изображение Спасибо.
breed[cars car]
breed[lightsR lightR]
breed[lightsL lightL]
breed[lightsU lightU]
breed[lightsD lightD]
breed[crossings crossing]
cars-own[
speed
maxSpeed
]
globals[
redV
greenV
redH
greenH
speedLimit
]
patches-own[
meaning
will-cross?
]
to setup
ca
set speedLimit speed-limit
draw-roads
place-cars
place-lights
draw-crossings
reset-ticks
tick
end
to go
move-cars
control-traffic-lights
tick
end
to control-traffic-lights
if ticks mod (50 * lights-interval * greenH + 65 * lights-interval * redH ) = 0 [change-color lightsR "H" change-color lightsL "H"]
if ticks mod (50 * lights-interval * greenV + 65 * lights-interval * redV ) = 0 [change-color lightsU "V" change-color lightsD "V"]
end
to change-color [lights D]
ask lights [
ifelse color = red [
ifelse D = "H" [
set greenH greenH + 1
][
set greenV greenV + 1]
]
[
ifelse D = "H" [
set redH redH + 1][
set redV redV + 1]
]
]
ask lights [
ifelse color = red [set color green] [set color red]
]
end
to draw-roads
;create crossroads
ask patches with [(pxcor = 137 and pycor = 154 ) or (pxcor = 137 and pycor = 155 ) or ( pxcor = 138 and pycor = 155 )
or ( pxcor = 138 and pycor = 154 ) ] [
set pcolor white
set meaning "crossroad"
]
;roads-up
ask patches with [pxcor = 137 and (pycor > 155 and pycor < 320) and meaning != "crossroad"] [
set pcolor grey
sprout 1 [
set shape "road2"
set color grey
die
]
set meaning "A-47-2-In"]
ask patches with [pxcor = 137 and (pycor > 21 and pycor < 154) and meaning != "crossroad"] [
set pcolor grey
sprout 1 [
set shape "road2"
set color grey
set heading 270
die
]
set meaning "A-15-Exit"]
ask patches with [pxcor = 138 and (pycor > 155 and pycor < 320) and meaning != "crossroad" ] [
set pcolor grey
sprout 1 [
set shape "road2"
set color grey
set heading 90
stamp die
]
set meaning "A-47-2-Exit"]
ask patches with [ pxcor = 138 and (pycor > 21 and pycor < 154) and meaning != "crossroad"] [
set pcolor grey
sprout 1 [
set shape "road2"
set color grey
set heading 90
stamp die
]
set meaning "A-15-In"]
ask patches with [ ( pycor = 155 and ( pycor > min-pycor and pycor < 157) ) and meaning != "crossroad" ] [
set pcolor grey
sprout 1[
set shape "road2"
set heading 360
set color grey
stamp die
]
set meaning "M1-Left"
]
;roads-right
ask patches with [ (pycor = 154) and ( pycor > min-pycor and pycor < 157 ) and meaning != "crossroad" ] [
set pcolor grey
sprout 1[
set shape "road2"
set color grey
die
]
set meaning "M1-Right"]
end
to draw-crossings
ask patches with [(meaning = "A-47-2-Exit" or meaning = "A-47-2-In" or meaning = "A-15-In" or meaning = "A-15-Exit" )
and (pxcor = 137 or pxcor = 138 ) and ( pycor = 162 or pycor = 163 or pycor = 146 or pycor = 147) ][
sprout-crossings 1 [
set shape "crossing"
set color white
set heading 0
set size 1
]
]
ask patches with [(meaning = "M1-Left" or meaning = "M1-Right") and (pxcor = 121 or pxcor = 122 or pxcor = 214 or pxcor = 215) and
(pycor = 154 or pycor = 155 )][
sprout-crossings 1 [
set shape "crossing"
set heading 90
set color white
set size 1
]
]
ask crossings [
set will-cross? false
set meaning "crossing"
stamp
die
]
ask patches with [meaning = "crossing"] [
ask neighbors4 [
]
]
end
to place-cars
ask n-of (num-of-cars / 2) patches with [pxcor = 138 and (pycor > 155 and pycor < 320) and count turtles-on neighbors = 0]
[
sprout-cars 1 [
set size 2
set shape "car top"
set heading 180
let s random 10
if s < 7 [set maxSpeed speed-limit - 15 + random 16]
if s = 7 [set maxSpeed speed-limit - 20 + random 6]
if s > 7 [set maxSpeed speed-limit + random 16]
set speed maxSpeed - random 20
]
]
ask n-of (num-of-cars / 3 ) patches with [ (pycor = 155) and pxcor < 156 ] [
sprout-cars 1 [
set size 2
set shape "car top"
set heading 90
let s random 10
if s < 7 [set maxSpeed speed-limit - 15 + random 16]
if s = 7 [set maxSpeed speed-limit - 20 + random 6]
if s > 7 [set maxSpeed speed-limit + random 16]
set speed maxSpeed - random 20
]
]
ask n-of (num-of-cars / 5) patches with [pycor = 154 and (pxcor > 243 )] [
sprout-cars 1 [
set size 2
set shape "car top"
set heading 270
let s random 10
if s < 7 [set maxSpeed speed-limit - 15 + random 16]
if s = 7 [set maxSpeed speed-limit - 20 + random 6]
if s > 7 [set maxSpeed speed-limit + random 16]
set speed maxSpeed - random 20
]
]
end
to place-lights
ask patches with [ pxcor = 138 and pycor = 156 ] [
sprout-lightsD 1 [
set color green
set shape "lights"
]
]
ask patches with [pxcor = 136 and pycor = 155 ] [
sprout-lightsD 1 [
set color red
set shape "lights"
]
]
ask patches with [pxcor = 139 and pycor = 154] [
sprout-lightsD 1 [
set color red
set shape "lights"
]
]
ask patches with [pxcor = 137 and pycor = 153] [
sprout-lightsD 1 [
set color green
set shape "lights"
]
]
set greenH 0
set redH 1
set redV 0
set greenV 1
end
; Car procedures
to control-speed
let car-ahead one-of cars-on patch-ahead 1.5
ifelse car-ahead = nobody [
ifelse speed < maxSpeed [set speed speed + acceleration] [set speed speed - deceleration]
]
[
ifelse [speed] of car-ahead = 0 [set speed 0] [
ifelse [speed] of car-ahead >= maxSpeed [
set speed maxSpeed
set speed speed - deceleration
] [
set speed [speed] of car-ahead
set speed speed - deceleration]
]
]
end
to move-cars
ask cars [
control-speed
check-crossing
;whether traffic lights show red or green
ifelse not any? (lightsR-on patch-ahead 1.5) with [color = red] and not any? (lightsL-on patch-ahead 1.5) with [color = red]
and not any? (lightsD-on patch-ahead 1.5) with [color = red] and not any? (lightsU-on patch-ahead 1.5) with [color = red] [fd speed / 200 ] [set speed 0]
]
end
;Probabilitities of cars making a left or right turn or going straight
to check-crossing
ask cars with [(pxcor = 138 and pycor = 154) and meaning = "crossroad" and heading = 180 ] [
if random 100 < 50 [ set heading 270 move-to patch-ahead 0 ]
]
ask cars with [(pxcor = 137 and pycor = 155) and meaning = "crossroad" and heading = 90 ] [
if random 100 < 60 [ set heading 0 move-to patch-ahead 0 ]
]
end
Junction Picture