File size: 7,747 Bytes
5516cba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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   # flat numpy array for RL frameworks
  # Layout: [N, S, E, W queues | N, S, E, W waits | N, S, E, W EV flags | phase, step]

# ─────────────────────────────────────────────────────────────────────
# Reward design (multi-component, clipped to [-1, +1])
# ─────────────────────────────────────────────────────────────────────
reward:
  range: [-1.0, 1.0]
  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_priority:
      sign: "+/-"
      description: "Combo of golden-window bonus and delay penalty for EVs"

# ─────────────────────────────────────────────────────────────────────
# Difficulty modes
# ─────────────────────────────────────────────────────────────────────
difficulty_modes:
  easy:
    arrival_rate: [0, 1]
    discharge_rate: [4, 5]
    max_queue: 15
    max_steps: 50
    emergency_prob: 0.01
    burst_prob: 0.0
    description: "Stable, balanced traffic. Minimal emergencies. Ideal for learning."

  medium:
    arrival_rate: [1, 3]
    discharge_rate: [3, 5]
    max_queue: 25
    max_steps: 100
    emergency_prob: 0.05
    burst_prob: 0.10
    description: "Random traffic bursts, moderate congestion, occasional emergencies."

  hard:
    arrival_rate: [2, 5]
    discharge_rate: [2, 4]
    max_queue: 40
    max_steps: 200
    emergency_prob: 0.15
    burst_prob: 0.20
    description: "High-intensity traffic, frequent emergencies, strict fairness constraints."

# ─────────────────────────────────────────────────────────────────────
# 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.0, 1.0]
    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.0, 1.0]
    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

# ─────────────────────────────────────────────────────────────────────
# Project files
# ─────────────────────────────────────────────────────────────────────
project_structure:
  - env.py:            "Core TrafficEnv class"
  - tasks.py:          "Easy / Medium / Hard configuration dicts"
  - baseline_agent.py: "Rule-based baseline agent"
  - test_env.py:       "Simulation runner and correctness checks"
  - openenv.yaml:      "This file — environment specification"
  - README.md:         "Full documentation"