HighwayEnv
HighwayEnv copied to clipboard
Surrounding vehicles' IDs
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.
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.
Can you please share how to add id
to each vehicle when they are created.
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