cityflow-project / CityFlow

A Multi-Agent Reinforcement Learning Environment for Large Scale City Traffic Scenario
https://cityflow-project.github.io
Apache License 2.0
789 stars 173 forks source link

How to retrieve lane length or lane occupation #121

Closed LucasAlegre closed 2 years ago

LucasAlegre commented 3 years ago

I need to compute the lane occupation, and for it, I need to retrieve the maximum number of vehicles that a lane can have at a given time. The roadnet.json files only store the lane width, which is not useful.

Is there a way to get this value using the API?

Thanks!

only-changer commented 3 years ago

You can calculate it by the lane width, vehicle width, and min vehicle gap, which are given in the roadnet.json and flow.json. For now, we don't have such an API, you can modify "src/cityflow.cpp" and re-compile the C++ code to add one.

LucasAlegre commented 3 years ago

I believe I should calculate with lane length, vehicle length and min vehicle gap. However, the lanes only have the width attribute in the roadnet.json files. The workaround seems to be computing the lane length calculating the distance between the two points (x,y) of the road...

Sheagu commented 2 years ago
  1. In Roadnet.json, you can find the point of the intersection and the road, and compute the distance. The actual lane length = this distance - the width of the intersection. For example, the intersection point is (0,0) and the road points are (0,-150) and (0,0), then the distance is 150m. If the intersection width (half of the intersection's edge) is 15m, then the lane length is 135m.
  2. Set the traffic light to red and count the queuing cars 🤣 image