Farama-Foundation / HighwayEnv

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

It is question regarding using IDM and MOBIL for EGO vehicle #528

Open SeasonedLeo opened 10 months ago

SeasonedLeo commented 10 months ago

Hi @eleurent First of all , thanks for making this available for everybody to use , it has been very helpful .

I am trying to use this environment for my offline RL class project. I would like to run EGO vehicle using IDM and MOBIL , I understand in some of the previous posts you mentioned it will make env run like a simulator and this exactly what I want . Could you help me How to process , I have been trying to make it work but totally not getting what all needs to chnage .. Your advise will be extremely helpful .

Thanks

eleurent commented 10 months ago

Maybe the cleanest would be to add a new ActionType to

https://github.com/Farama-Foundation/HighwayEnv/blob/8d9324092064ca955df8c3b27a8f1498e14f8624/highway_env/envs/common/action.py

Something like

class NoAction(ActionType):

    def space(self) -> spaces.Space:
        """One action that does nothing."""
        return spaces.Discrete(1) 

    @property
    def vehicle_class(self) -> Callable:
        """The vehicle is an IDMVehicle, such that it executes IDM/MOBIL actions on its own."""
        return IDMVehicle

    def act(self, action: Action) -> None:
        """Does nothing, the IDMVehicle actions will be followed automatically."""
        pass

Then add it to the action_factory() here:

https://github.com/Farama-Foundation/HighwayEnv/blob/8d9324092064ca955df8c3b27a8f1498e14f8624/highway_env/envs/common/action.py#L310

And configure your env to use it:

gym.makes(env_id, config={'action': {'type': 'NoAction'}})

That should do the trick :)