Intersection

An intersection negotiation task with dense traffic.

https://raw.githubusercontent.com/eleurent/highway-env/gh-media/docs/media/intersection-env.gif

Warning

It’s quite hard to come up with good decentralized behaviors for other agents to avoid each other. Of course, this could be achieved by sophisticated centralized schedulers, or traffic lights, but to keep things simple a rudimentary collision prediction was added in the behaviour of other vehicles.

This simple system sometime fails which results in collisions, blocking the way for the ego-vehicle. I figured it was fine for my own purpose, since it did not happen too often and it’s reasonable to expect the ego-vehicle to simply wait the end of episode in these situations. But I agree that it is not ideal, and I welcome any contribution on that matter.

Usage

env = gym.make("intersection-v0")

Default configuration

{
    "observation": {
        "type": "Kinematics",
        "vehicles_count": 15,
        "features": ["presence", "x", "y", "vx", "vy", "cos_h", "sin_h"],
        "features_range": {
            "x": [-100, 100],
            "y": [-100, 100],
            "vx": [-20, 20],
            "vy": [-20, 20],
        },
        "absolute": True,
        "flatten": False,
        "observe_intentions": False
    },
    "action": {
        "type": "DiscreteMetaAction",
        "longitudinal": False,
        "lateral": True
    },
    "duration": 13,  # [s]
    "destination": "o1",
    "initial_vehicle_count": 10,
    "spawn_probability": 0.6,
    "screen_width": 600,
    "screen_height": 600,
    "centering_position": [0.5, 0.6],
    "scaling": 5.5 * 1.3,
    "collision_reward": IntersectionEnv.COLLISION_REWARD,
    "normalize_reward": False
}

More specifically, it is defined in:

classmethod IntersectionEnv.default_config() → dict[source]

Default environment configuration.

Can be overloaded in environment implementations, or by calling configure(). :return: a configuration dict

API

class highway_env.envs.intersection_env.IntersectionEnv(config: dict = None)[source]
COLLISION_REWARD: float = -5
HIGH_SPEED_REWARD: float = 1
ARRIVED_REWARD: float = 1
ACTIONS: Dict[int, str] = {0: 'SLOWER', 1: 'IDLE', 2: 'FASTER'}
ACTIONS_INDEXES = {'FASTER': 2, 'IDLE': 1, 'SLOWER': 0}
classmethod default_config() → dict[source]

Default environment configuration.

Can be overloaded in environment implementations, or by calling configure(). :return: a configuration dict

_reward(action: int) → float[source]

Return the reward associated with performing a given action and ending up in the current state.

Parameters

action – the last action performed

Returns

the reward

_is_terminal() → bool[source]

The episode is over when a collision occurs or when the access ramp has been passed.

reset() → numpy.ndarray[source]

Reset the environment to it’s initial configuration

Returns

the observation of the reset state

step(action: int) → Tuple[numpy.ndarray, float, bool, dict][source]

Perform an action and step the environment dynamics.

The action is executed by the ego-vehicle, and all other vehicles on the road performs their default behaviour for several simulation timesteps until the next decision making step.

Parameters

action – the action performed by the ego-vehicle

Returns

a tuple (observation, reward, terminal, info)

_make_road() → None[source]

Make an 4-way intersection.

The horizontal road has the right of way. More precisely, the levels of priority are:
  • 3 for horizontal straight lanes and right-turns

  • 1 for vertical straight lanes and right-turns

  • 2 for horizontal left-turns

  • 0 for vertical left-turns

The code for nodes in the road network is: (o:outer | i:inner + [r:right, l:left]) + (0:south | 1:west | 2:north | 3:east)

Returns

the intersection road

_make_vehicles(n_vehicles: int = 10) → None[source]

Populate a road with several vehicles on the highway and on the merging lane

Returns

the ego-vehicle

_spawn_vehicle(longitudinal: float = 0, position_deviation: float = 1.0, speed_deviation: float = 1.0, spawn_probability: float = 0.6, go_straight: bool = False) → None[source]
_clear_vehicles() → None[source]
property has_arrived
_cost(action: int) → float[source]

The constraint signal is the occurrence of collisions.

__annotations__ = {'ACTIONS': typing.Dict[int, str], 'ARRIVED_REWARD': <class 'float'>, 'COLLISION_REWARD': <class 'float'>, 'HIGH_SPEED_REWARD': <class 'float'>}
__module__ = 'highway_env.envs.intersection_env'