Actions

Similarly to observations, several types of actions can be used in every environment. They are defined in the action module. Each environment comes with a default action type, which can be changed or customised using environment configurations. For instance,

import gym
import highway_env

env = gym.make('highway-v0')
env.configure({
    "action": {
        "type": "ContinuousAction"
    }
})
env.reset()

Continuous Actions

The ContinuousAction type allows the agent to directly set the low-level controls of the vehicle kinematics, namely the throttle \(a\) and steering angle \(\delta\).

Note

The control of throttle and steering can be enabled or disabled through the longitudinal and lateral configurations, respectively. Thus, the action space can be either 1D or 2D.

Discrete Meta-Actions

The DiscreteMetaAction type adds a layer of speed and steering controllers on top of the continuous low-level control, so that the ego-vehicle can automatically follow the road at a desired velocity. Then, the available meta-actions consist in changing the target lane and speed that are used as setpoints for the low-level controllers.

The full corresponding action space is defined in ACTIONS_ALL

ACTIONS_ALL = {
        0: 'LANE_LEFT',
        1: 'IDLE',
        2: 'LANE_RIGHT',
        3: 'FASTER',
        4: 'SLOWER'
    }

Some of these actions might not be always available (lane changes at the edges of the roads, or accelerating/decelrating beyond the maximum/minimum velocity), and the list of available actions can be accessed with get_available_actions() method. Taking an unavailable action is equivalent to taking the IDLE action.

Similarly to continuous actions, the longitudinal (speed changes) and lateral (lane changes) actions can be disabled separately through the longitudinal and lateral parameters. For instance, in the default configuration of the intersection environment, only the speed is controlled by the agent, while the lateral control of the vehicle is automatically performed by a steering controller to track a desired lane.

Manual control

The environments can be used as a simulation:

env = gym.make("highway-v0")
env.configure({
    "manual_control": True
})
env.reset()
done = False
while not done:
    env.step(env.action_space.sample())  # with manual control, these actions are ignored

The ego-vehicle is controlled by directional arrows keys, as defined in EventHandler

API

class highway_env.envs.common.action.ActionType[source]

A type of action specifies its definition space, and how actions are executed in the environment

space() → gym.spaces.space.Space[source]

The action space.

property vehicle_class

The class of a vehicle able to execute the action.

Must return a subclass of highway_env.vehicle.kinematics.Vehicle.

act(action: Union[int, numpy.ndarray]) → None[source]

Execute the action on the ego-vehicle.

Most of the action mechanics are actually implemented in vehicle.act(action), where vehicle is an instance of the specified highway_env.envs.common.action.ActionType.vehicle_class. Must some pre-processing can be applied to the action based on the ActionType configurations.

Parameters

action – the action to execute

__dict__ = mappingproxy({'__module__': 'highway_env.envs.common.action', '__doc__': 'A type of action specifies its definition space, and how actions are executed in the environment', 'space': <function ActionType.space>, 'vehicle_class': <property object>, 'act': <function ActionType.act>, '__dict__': <attribute '__dict__' of 'ActionType' objects>, '__weakref__': <attribute '__weakref__' of 'ActionType' objects>})
__module__ = 'highway_env.envs.common.action'
__weakref__

list of weak references to the object (if defined)

class highway_env.envs.common.action.ContinuousAction(env: AbstractEnv, acceleration_range: Optional[Tuple[float, float]] = None, steering_range: Optional[Tuple[float, float]] = None, longitudinal: bool = True, lateral: bool = True, dynamical: bool = False, clip: bool = True, **kwargs)[source]

An continuous action space for throttle and/or steering angle.

If both throttle and steering are enabled, they are set in this order: [throttle, steering]

The space intervals are always [-1, 1], but are mapped to throttle/steering intervals through configurations.

ACCELERATION_RANGE = (-5, 5.0)

Acceleration range: [-x, x], in m/s².

STEERING_RANGE = (-0.7853981633974483, 0.7853981633974483)

Steering angle range: [-x, x], in rad.

__init__(env: AbstractEnv, acceleration_range: Optional[Tuple[float, float]] = None, steering_range: Optional[Tuple[float, float]] = None, longitudinal: bool = True, lateral: bool = True, dynamical: bool = False, clip: bool = True, **kwargs) → None[source]

Create a continuous action space.

Parameters
  • env – the environment

  • acceleration_range – the range of acceleration values [m/s²]

  • steering_range – the range of steering values [rad]

  • longitudinal – enable throttle control

  • lateral – enable steering control

  • dynamical – whether to simulate dynamics (i.e. friction) rather than kinematics

  • clip – clip action to the defined range

space() → gym.spaces.box.Box[source]

The action space.

property vehicle_class

The class of a vehicle able to execute the action.

Must return a subclass of highway_env.vehicle.kinematics.Vehicle.

act(action: numpy.ndarray) → None[source]

Execute the action on the ego-vehicle.

Most of the action mechanics are actually implemented in vehicle.act(action), where vehicle is an instance of the specified highway_env.envs.common.action.ActionType.vehicle_class. Must some pre-processing can be applied to the action based on the ActionType configurations.

Parameters

action – the action to execute

__module__ = 'highway_env.envs.common.action'
class highway_env.envs.common.action.DiscreteMetaAction(env: AbstractEnv, longitudinal: bool = True, lateral: bool = True, **kwargs)[source]

An discrete action space of meta-actions: lane changes, and cruise control set-point.

ACTIONS_ALL = {0: 'LANE_LEFT', 1: 'IDLE', 2: 'LANE_RIGHT', 3: 'FASTER', 4: 'SLOWER'}

A mapping of action indexes to labels.

ACTIONS_LONGI = {0: 'SLOWER', 1: 'IDLE', 2: 'FASTER'}

A mapping of longitudinal action indexes to labels.

ACTIONS_LAT = {0: 'LANE_LEFT', 1: 'IDLE', 2: 'LANE_RIGHT'}

A mapping of lateral action indexes to labels.

__init__(env: AbstractEnv, longitudinal: bool = True, lateral: bool = True, **kwargs) → None[source]

Create a discrete action space of meta-actions.

Parameters
  • longitudinal – include longitudinal actions

  • lateral – include lateral actions

  • env – the environment

__module__ = 'highway_env.envs.common.action'
space() → gym.spaces.space.Space[source]

The action space.

property vehicle_class

The class of a vehicle able to execute the action.

Must return a subclass of highway_env.vehicle.kinematics.Vehicle.

act(action: int) → None[source]

Execute the action on the ego-vehicle.

Most of the action mechanics are actually implemented in vehicle.act(action), where vehicle is an instance of the specified highway_env.envs.common.action.ActionType.vehicle_class. Must some pre-processing can be applied to the action based on the ActionType configurations.

Parameters

action – the action to execute

highway_env.envs.common.action.action_factory(env: AbstractEnv, config: dict) → highway_env.envs.common.action.ActionType[source]