huawei-noah / SMARTS

Scalable Multi-Agent RL Training School for Autonomous Driving
MIT License
909 stars 184 forks source link

[Help Request] Wanna to know about traffic model #2119

Closed Frzgunr1 closed 5 months ago

Frzgunr1 commented 7 months ago

High Level Description

  The control model of traffic in smarts is not clear, it is controlled by sumo or smarts and can be customized with some parameters. It appears to be unresponsive to the behavior of surrounding vehicles. 
   However, in `scenarios/sumo/loop`, traffic slows down when it catches up with the car in front of it and continues to run for 20 minutes without collision. But in my own program ego_vehicle is a laner class agent and traffic will collide with ego_vehicle.
   Or perhaps it is due to insufficient training of my model. But I really want to know what the underlying model of the traffic class is. If it is IDM, please let me know. And is it possible to customize the traffic control model? (Compared to social agents, this does not require returning information, so the speed will be faster when the scale is large.)

Problems

 The existing model looks like IDM, but I'm not sure.  I need to customize HDV for a smarter operational model (at least IDM) 
 What modifications need to be made to customize the model for traffic if possible? 
 Thank u very much, looking forward to ur reply!

Version

1.4.0

Operating System

ubuntu 20.04

Gamenot commented 7 months ago

Hello @Frzgunr1, I am not quite certain of your intention here so I am going to try to describe what I think I am hearing.

Actions

Changing existing models in scenario studio

The traffic model can be configured in the scenario

SUMO traffic can be selected in the scenario this way:

# loop/scenario.py

Traffic(
   engine="SUMO", # "SMARTS" for SMARTS implementation
   ...
)

SUMO

My understanding is that if you are using SUMO traffic the model is a modified Krauss as is noted on this page They mention it is a combination of Krauss and safety metrics.

Selecting "SMARTS" causes the simulation to use the following traffic implementation: https://github.com/huawei-noah/SMARTS/blob/b9aceac155cbd187fcb848a1e8448f9d326d2c54/smarts/core/sumo_traffic_simulation.py#L55

This forwards to the selected SUMO traffic model ( MSCFModel_{MODEL_NAME}.cpp ) which is currently "Krauss":

https://github.com/eclipse-sumo/sumo/tree/ed266e08eb300919edfa334391b0185ae9edaba0/src/microsim/cfmodels

The options for each model are given here:

The current "Krauss" parameters can be configured through the traffic actor: https://github.com/huawei-noah/SMARTS/blob/b9aceac155cbd187fcb848a1e8448f9d326d2c54/smarts/sstudio/types/actor/traffic_actor.py#L34-L65

and used like this: https://github.com/huawei-noah/SMARTS/blob/b9aceac155cbd187fcb848a1e8448f9d326d2c54/scenarios/sumo/intersections/2lane/scenario.py#L16-L23

If you need a different model then "Krauss" I can add that in fairly quickly.

SMARTS

If you are using SMARTS traffic it is a bit less clear, it is mostly similar to the SUMO Krauss implementation but the lane changing model is a bit coupled.

Selecting "SMARTS" causes the simulation to use the following traffic implementation: https://github.com/huawei-noah/SMARTS/blob/b9aceac155cbd187fcb848a1e8448f9d326d2c54/smarts/core/local_traffic_provider.py#L67

The current parameters supported are:

# traffic model
minGap
accel
decel
emergencyDecel
sigma
tau

# vehicle
speedFactor
speedDev

# lc model
lcHoldPeriod
lcAssertive
lcCutinProb
lcDogmatic
lcSlowdownAfter
lcMultiLaneCutin

# junction model
jmYieldToAgents
jmWaitToRestart

They can be used specified similarly to here: https://github.com/huawei-noah/SMARTS/blob/b9aceac155cbd187fcb848a1e8448f9d326d2c54/scenarios/sumo/straight/cutin_2lane_agents_1/scenario.py#L20-L28

Injected

Another possibility is that you can implement your own TrafficProvider if necessary as described here:

https://github.com/huawei-noah/SMARTS/issues/1870#issuecomment-1480381436

Frzgunr1 commented 7 months ago

Thank you @Gamenot very much for your suggestion! I checked SMARTS/smarts/core/sumo_traffic_simulation.pys source code and SUMO's docs, and as I understand it, smarts is created by the _ create_vehicle() method to generate the vehicle flow. So, just add self._traci_conn.vehicle.add(vehicle_id, carFollowModel="IDM") at the end of the method _create_vehicle() to realize that the car flow becomes an IDM model.The other sumo heel chi models are also similar. I'm not sure if my understanding and modification is correct, could you please confirm this for me, thank you very much!