File size: 9,256 Bytes
4bbf0fc 36c3c58 4bbf0fc 36c3c58 4bbf0fc 36c3c58 4bbf0fc 36c3c58 4bbf0fc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | version: "1.0"
name: "TrafficSignalOptimization-v1"
description: >
AI-driven Traffic Signal Optimization for a 4-way urban intersection.
A reinforcement-learning environment that challenges agents to minimise
congestion, reduce average waiting time, respond to emergency vehicles,
and maintain signal stability across three difficulty tiers.
author: "OpenEnv Submission"
tags:
- Reinforcement Learning
- Traffic Control
- Smart Cities
- Safety-Critical
- Emergency Vehicle Priority
licence: MIT
# ─────────────────────────────────────────────────────────────────────
# Environment specification
# ─────────────────────────────────────────────────────────────────────
environment:
class: "env.TrafficEnv"
entry_point: "env:TrafficEnv"
state_space:
type: Dict
keys:
north_cars:
type: Discrete
description: "Queued vehicles in the North lane"
range: [0, max_queue]
south_cars:
type: Discrete
description: "Queued vehicles in the South lane"
range: [0, max_queue]
east_cars:
type: Discrete
description: "Queued vehicles in the East lane"
range: [0, max_queue]
west_cars:
type: Discrete
description: "Queued vehicles in the West lane"
range: [0, max_queue]
waiting_times:
type: "Dict[str, float]"
description: "Cumulative waiting-time pressure per lane (north/south/east/west)"
phase:
type: Discrete
values: [0, 1]
description: "Current green signal: 0 = NS green, 1 = EW green"
emergency_flags:
type: "Dict[str, bool]"
description: "True if an emergency vehicle is present in that lane"
step_count:
type: Discrete
description: "Current step within the episode"
range: [0, max_steps]
action_space:
type: Discrete
n: 2
actions:
0: "Keep current signal phase"
1: "Switch signal phase (NS ↔ EW)"
observation_vector_dim: 14
# Layout: [N, S, E, W queues | N, S, E, W waits | N, S, E, W EV flags | phase, step]
# ─────────────────────────────────────────────────────────────────────
# Tasks (3 required — validator enumerates and scores each one)
# ─────────────────────────────────────────────────────────────────────
tasks:
- id: easy
description: "Stable, balanced traffic. Minimal emergencies. Ideal for learning."
config_key: easy
max_steps: 50
score_range: [0.001, 0.999]
params:
arrival_rate: [0, 1]
discharge_rate: [4, 5]
max_queue: 15
emergency_prob: 0.01
burst_prob: 0.0
- id: medium
description: "Random traffic bursts, moderate congestion, occasional emergencies."
config_key: medium
max_steps: 100
score_range: [0.001, 0.999]
params:
arrival_rate: [1, 3]
discharge_rate: [3, 5]
max_queue: 25
emergency_prob: 0.05
burst_prob: 0.10
- id: hard
description: "High-intensity traffic, frequent emergencies, strict fairness constraints."
config_key: hard
max_steps: 200
score_range: [0.001, 0.999]
params:
arrival_rate: [2, 5]
discharge_rate: [2, 4]
max_queue: 40
emergency_prob: 0.15
burst_prob: 0.20
# ─────────────────────────────────────────────────────────────────────
# Reward design (multi-component, clipped to (-0.999, +0.999))
# Score = (reward + 1) / 2, always in open interval (0, 1)
# ─────────────────────────────────────────────────────────────────────
reward:
range: [-0.999, 0.999]
score_normalisation: "(reward + 1) / 2, clamped to [0.001, 0.999]"
components:
efficiency:
sign: "+"
description: "Vehicles cleared this step (throughput reward)"
congestion:
sign: "-"
description: "Normalised total queue density"
max_queue_penalty:
sign: "-"
description: "Penalty for extreme bottlenecks in any single lane"
switch_penalty:
sign: "-"
description: "Stability constraint to prevent oscillatory signal toggling"
improvement_bonus:
sign: "+"
description: "Bonus for active decongestion progress"
fairness_bonus:
sign: "+"
description: "Reward for maintaining balanced waiting times across all lanes"
starvation_penalty:
sign: "-"
description: "Penalty for phase-duration exceeding starvation limit"
emergency_golden_window:
sign: "+"
description: "Full bonus for clearing EV within golden window steps"
emergency_delay:
sign: "-"
description: "Exponential penalty for delaying life-saving vehicles"
# ─────────────────────────────────────────────────────────────────────
# Evaluation metrics (returned in info dict on every step)
# ─────────────────────────────────────────────────────────────────────
metrics:
total_cleared:
type: int
description: "Total vehicles discharged from the intersection (episode)"
avg_waiting_time:
type: float
description: "Cumulative wait pressure divided by vehicles cleared"
max_queue_length:
type: int
description: "Peak queue length observed in any lane (episode)"
signal_switch_count:
type: int
description: "Total signal changes (lower = more stable)"
congestion_score:
type: float
range: [0.001, 0.999]
description: "Current normalised total queue depth"
avg_ev_clear_time:
type: float
description: "Average steps taken to clear an emergency vehicle"
fairness_score:
type: float
range: [0.001, 0.999]
description: "Index representing lane-level service balance"
# ─────────────────────────────────────────────────────────────────────
# Baseline agent
# ─────────────────────────────────────────────────────────────────────
baseline:
class: "baseline_agent.RuleBasedAgent"
description: >
Deterministic rule-based agent. Switches based on queue imbalance,
minimum green time, starvation guard, and emergency preemption.
parameters:
min_green_time: 5
imbalance_threshold: 5
max_green_time: 15
emergency_min_green: 2
# ─────────────────────────────────────────────────────────────────────
# HTTP API (OpenEnv spec: reset / step / state)
# ─────────────────────────────────────────────────────────────────────
api:
reset: {method: POST, path: /reset, description: "Start a new episode"}
step: {method: POST, path: /step, description: "Advance one step"}
state: {method: GET, path: /state, description: "Get current state"}
tasks: {method: GET, path: /tasks, description: "List all tasks"}
grader: {method: POST, path: /grader, description: "Run baseline grader"}
health: {method: GET, path: /health, description: "Liveness probe"}
# ─────────────────────────────────────────────────────────────────────
# Project files
# ─────────────────────────────────────────────────────────────────────
project_structure:
- env.py: "Core TrafficEnv class"
- tasks.py: "Easy / Medium / Hard configuration dicts"
- baseline_agent.py: "Rule-based baseline agent"
- inference.py: "FastAPI server + LLM agent + CLI validator script"
- test_env.py: "Simulation runner and correctness checks"
- openenv.yaml: "This file — environment specification"
- README.md: "Full documentation"
|