Skip to main content

Custom Gym/Gymnasium environments for operations research problems

Project description

Traffic Control Environment

Description

The TrafficControlEnv is a custom OpenAI Gymnasium-compatible environment for simulating traffic signal control at a four-way intersection. The environment models cars arriving from four directions (North, East, South, West), their movement through the intersection, and the effect of traffic signals on their waiting and travel times. This environment is designed for research and educational purposes in operations research, reinforcement learning, and traffic management.

Actions

The environment uses a discrete action space with three possible actions at each time step:

  • Action 0: No change — The traffic signal remains in its current state. No transition is triggered.

  • Action 1: Switch to North/South Green

    • If the current signal is red for all directions (RR) or already green for North/South (GR), this action sets or keeps the signal as green for North/South and red for East/West (GR).
    • If the current signal is green for East/West (RG), this action initiates a yellow light phase for East/West (RY), after which the signal will switch to green for North/South (GR).
  • Action 2: Switch to East/West Green

    • If the current signal is red for all directions (RR) or already green for East/West (RG), this action sets or keeps the signal as green for East/West and red for North/South (RG).
    • If the current signal is green for North/South (GR), this action initiates a yellow light phase for North/South (YR), after which the signal will switch to green for East/West (RG).

Yellow Light Logic: When a transition between green signals is requested (e.g., from North/South green to East/West green), the environment enforces a yellow light phase (YR or RY) for safety. During the yellow phase, new actions are ignored until the yellow duration elapses, after which the signal switches to the target green state.

Installation

You can install the package directly from PyPI using pip:

pip install kaist-or-gym

Usage Example

Below is a minimal example of how to use the TrafficControlEnv environment for a fixed number of time steps:

import gymnasium as gym
import kaist_or_gym

# Create the environment
env = gym.make("kaist-or/TrafficControlEnv-v0", render_mode="human")

observation, info = env.reset()

for _ in range(100):  # Run for 100 time steps
    action = env.action_space.sample()  # Replace with your policy
    observation, reward, terminated, truncated, info = env.step(action)
    env.render()
    if terminated or truncated:
        break

env.close()

This example demonstrates how to create the environment, take random actions, render the intersection, and run for a fixed number of steps.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kaist_or_gym-0.1.4.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kaist_or_gym-0.1.4-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file kaist_or_gym-0.1.4.tar.gz.

File metadata

  • Download URL: kaist_or_gym-0.1.4.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for kaist_or_gym-0.1.4.tar.gz
Algorithm Hash digest
SHA256 bc7de9d07655db340d6eb2b0b47c2920eed7882d05cb196c8a202d56de63c9bc
MD5 87e52fd88203ad78b500eacbe9115d69
BLAKE2b-256 3be1c190b6f4e5788fd4c6fed0cb11dff840f2765d8f9a22ec8ff324b8432f24

See more details on using hashes here.

File details

Details for the file kaist_or_gym-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: kaist_or_gym-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for kaist_or_gym-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1dc1aad5d997bd3bafe94b15aa2b7638fb1fc466176f700019050de9565e0b0d
MD5 02ca5295418452038dad1001c0210ecd
BLAKE2b-256 5e1a1ebe5fff5c137399997a1ec0db75bf0716a69ed5a8119c99cdc50529ba39

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page