HighwayEnv icon indicating copy to clipboard operation
HighwayEnv copied to clipboard

Surrounding vehicles' IDs

Open jayabrata97 opened this issue 2 years ago • 3 comments

https://github.com/eleurent/highway-env/issues/212#issuecomment-886631339. @eleurent, can you please share the code for adding id field in KinematicObservation as referred in option1.

jayabrata97 avatar May 31 '22 11:05 jayabrata97

Sure, you could just edit this method:

https://github.com/eleurent/highway-env/blob/ea79a9557e09c4f0f867a76da4926ed1d8aac22c/highway_env/vehicle/kinematics.py#L201

and add

'id': id(self)

And then simply add this 'id' key to the observation features, as explained in the docs.

Of course, this will return the python id of the vehicle object, which is a long integer. Alternatively, you also increment an id counter and assign it to each vehicle when they are created.

eleurent avatar May 31 '22 14:05 eleurent

Can you please share how to add id to each vehicle when they are created.

jayabrata97 avatar Jun 01 '22 07:06 jayabrata97

You can edit Vehicle.__init__ in kinematics.py as follows:

    max_id : int = 0

    def __init__(self,
                 road: Road,
                 position: Vector,
                 heading: float = 0,
                 speed: float = 0,
                 predition_type: str = 'constant_steering'):
        super().__init__(road, position, heading, speed)
        self.prediction_type = predition_type
        self.action = {'steering': 0, 'acceleration': 0}
        self.crashed = False
        self.impact = None
        self.log = []
        self.history = deque(maxlen=self.HISTORY_SIZE)

        self.id = Vehicle.max_id
        Vehicle.max_id += 1

eleurent avatar Jun 13 '22 19:06 eleurent