Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lane change mode #948

Merged
merged 4 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/exp_configs/non_rl/bay_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
lc_pushy=0.8,
lc_speed_gain=4.0,
model="LC2013",
lane_change_mode="no_lat_collide",
lane_change_mode="no_lc_safe",
# lcKeepRight=0.8
),
num_vehicles=1400)
Expand Down
2 changes: 1 addition & 1 deletion examples/exp_configs/non_rl/bay_bridge_toll.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
model="LC2013",
lcCooperative=0.2,
lcSpeedGain=15,
lane_change_mode="no_lat_collide",
lane_change_mode="no_lc_safe",
),
num_vehicles=50)

Expand Down
2 changes: 1 addition & 1 deletion examples/exp_configs/non_rl/minicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
speed_mode=1,
),
lane_change_params=SumoLaneChangeParams(
lane_change_mode="no_lat_collide",
lane_change_mode="no_lc_safe",
),
initial_speed=0,
num_vehicles=90)
Expand Down
97 changes: 87 additions & 10 deletions flow/core/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,27 @@
"all_checks": 31
}

LC_MODES = {"aggressive": 0, "no_lat_collide": 512, "strategic": 1621}
LC_MODES = {
"no_lc_safe": 512,
"no_lc_aggressive": 0,
"sumo_default": 1621,
"no_strategic_aggressive": 1108,
"no_strategic_safe": 1620,
"only_strategic_aggressive": 1,
"only_strategic_safe": 513,
"no_cooperative_aggressive": 1105,
"no_cooperative_safe": 1617,
"only_cooperative_aggressive": 4,
"only_cooperative_safe": 516,
"no_speed_gain_aggressive": 1093,
"no_speed_gain_safe": 1605,
"only_speed_gain_aggressive": 16,
"only_speed_gain_safe": 528,
"no_right_drive_aggressive": 1045,
"no_right_drive_safe": 1557,
"only_right_drive_aggressive": 64,
"only_right_drive_safe": 576
}

# Traffic light defaults
PROGRAM_ID = 1
Expand Down Expand Up @@ -897,14 +917,71 @@ class SumoLaneChangeParams:
----------
lane_change_mode : str or int, optional
may be one of the following:
* "no_lc_safe" (default): Disable all SUMO lane changing but still
handle safety checks (collision avoidance and safety-gap enforcement)
in the simulation. Binary is [001000000000]
* "no_lc_aggressive": SUMO lane changes are not executed, collision
avoidance and safety-gap enforcement are off.
Binary is [000000000000]

* "sumo_default": Execute all changes requested by a custom controller
unless in conflict with TraCI. Binary is [011001010101].

* "no_strategic_aggressive": Execute all changes except strategic
(routing) lane changes unless in conflict with TraCI. Collision
avoidance and safety-gap enforcement are off. Binary is [010001010100]
* "no_strategic_safe": Execute all changes except strategic
(routing) lane changes unless in conflict with TraCI. Collision
avoidance and safety-gap enforcement are on. Binary is [011001010100]
* "only_strategic_aggressive": Execute only strategic (routing) lane
changes unless in conflict with TraCI. Collision avoidance and
safety-gap enforcement are off. Binary is [000000000001]
* "only_strategic_safe": Execute only strategic (routing) lane
changes unless in conflict with TraCI. Collision avoidance and
safety-gap enforcement are on. Binary is [001000000001]

* "no_cooperative_aggressive": Execute all changes except cooperative
(change in order to allow others to change) lane changes unless in
conflict with TraCI. Collision avoidance and safety-gap enforcement
are off. Binary is [010001010001]
* "no_cooperative_safe": Execute all changes except cooperative
lane changes unless in conflict with TraCI. Collision avoidance and
safety-gap enforcement are on. Binary is [011001010001]
* "only_cooperative_aggressive": Execute only cooperative lane changes
unless in conflict with TraCI. Collision avoidance and safety-gap
enforcement are off. Binary is [000000000100]
* "only_cooperative_safe": Execute only cooperative lane changes
unless in conflict with TraCI. Collision avoidance and safety-gap
enforcement are on. Binary is [001000000100]

* "no_speed_gain_aggressive": Execute all changes except speed gain (the
other lane allows for faster driving) lane changes unless in conflict
with TraCI. Collision avoidance and safety-gap enforcement are off.
Binary is [010001000101]
* "no_speed_gain_safe": Execute all changes except speed gain
lane changes unless in conflict with TraCI. Collision avoidance and
safety-gap enforcement are on. Binary is [011001000101]
* "only_speed_gain_aggressive": Execute only speed gain lane changes
unless in conflict with TraCI. Collision avoidance and safety-gap
enforcement are off. Binary is [000000010000]
* "only_speed_gain_safe": Execute only speed gain lane changes
unless in conflict with TraCI. Collision avoidance and safety-gap
enforcement are on. Binary is [001000010000]

* "no_right_drive_aggressive": Execute all changes except right drive
(obligation to drive on the right) lane changes unless in conflict
with TraCI. Collision avoidance and safety-gap enforcement are off.
Binary is [010000010101]
* "no_right_drive_safe": Execute all changes except right drive
lane changes unless in conflict with TraCI. Collision avoidance and
safety-gap enforcement are on. Binary is [011000010101]
* "only_right_drive_aggressive": Execute only right drive lane changes
unless in conflict with TraCI. Collision avoidance and safety-gap
enforcement are off. Binary is [000001000000]
* "only_right_drive_safe": Execute only right drive lane changes
unless in conflict with TraCI. Collision avoidance and safety-gap
enforcement are on. Binary is [001001000000]

* "no_lat_collide" (default): Human cars will not make lane
changes, RL cars can lane change into any space, no matter how
likely it is to crash
* "strategic": Human cars make lane changes in accordance with SUMO
to provide speed boosts
* "aggressive": RL cars are not limited by sumo with regard to
their lane-change actions, and can crash longitudinally
* int values may be used to define custom lane change modes for the
given vehicles, specified at:
http://sumo.dlr.de/wiki/TraCI/Change_Vehicle_State#lane_change_mode_.280xb6.29
Expand Down Expand Up @@ -943,7 +1020,7 @@ class SumoLaneChangeParams:
"""

def __init__(self,
lane_change_mode="no_lat_collide",
lane_change_mode="no_lc_safe",
model="LC2013",
lc_strategic=1.0,
lc_cooperative=1.0,
Expand Down Expand Up @@ -1051,7 +1128,7 @@ def __init__(self,
elif not (isinstance(lane_change_mode, int)
or isinstance(lane_change_mode, float)):
logging.error("Setting lane change mode to default.")
lane_change_mode = LC_MODES["no_lat_collide"]
lane_change_mode = LC_MODES["no_lc_safe"]

self.lane_change_mode = lane_change_mode

Expand Down
6 changes: 3 additions & 3 deletions tests/fast_tests/test_vehicles.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_speed_lane_change_modes(self):
speed_mode='obey_safe_speed',
),
lane_change_params=SumoLaneChangeParams(
lane_change_mode="no_lat_collide",
lane_change_mode="no_lc_safe",
)
)

Expand All @@ -56,7 +56,7 @@ def test_speed_lane_change_modes(self):
self.assertEqual(vehicles.type_parameters["typeB"][
"car_following_params"].speed_mode, 0)
self.assertEqual(vehicles.type_parameters["typeB"][
"lane_change_params"].lane_change_mode, 1621)
"lane_change_params"].lane_change_mode, 512)

vehicles.add(
"typeC",
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_controlled_id_params(self):
speed_mode="obey_safe_speed",
),
lane_change_params=SumoLaneChangeParams(
lane_change_mode="no_lat_collide",
lane_change_mode="no_lc_safe",
))
default_mingap = SumoCarFollowingParams().controller_params["minGap"]
self.assertEqual(vehicles.types[0]["type_params"]["minGap"],
Expand Down