Farama-Foundation / HighwayEnv

A minimalist environment for decision-making in autonomous driving
https://highway-env.farama.org/
MIT License
2.65k stars 757 forks source link

ID of vehicles that appear in current observation. #212

Closed yotamitai closed 3 years ago

yotamitai commented 3 years ago

Hi! Is there a way to obtain the ID of the IDM vehicles that are present in the current observation? What I'd really like is to know how many cars are in each lane in the current observed state. If I knew which cars (by ID) appear in the observation i could simply extract their lane index. I can obtain this info from the observations themselves but was wondering if there isn't some simple method that exists for this.

Thanks

eleurent commented 3 years ago

Hi yotamitai, I think that there are several ways this could be implemented.

  1. Modify the KinematicsObservation to include an additional id field. This must be filled in the Vehicle.to_dict() method, and added to the observation configuration. Instead of vehicle id, you could also directly put the lane index information.
  2. Add your own observation type, which does additional computations like counting how many cars are in each lane, and returns the result. This precludes the need for any post-processing steps.
  3. Bypass the observations system and get the information directly, by accessing env.road.vehicles
yotamitai commented 3 years ago

I was hoping there would be some indication of which vehicles are shown on the screen at a given moment, i.e. as a feature of the state/observation. But I guess I can simply prune all cars from the observation that have a relative x distance from the agent that is greater than the width of the screen.

Thank you.