Files
SD/STEP2_SUMMARY.md

3.0 KiB
Raw Permalink Blame History

🏁 Single-Process Prototype — Implementation Summary

Status: Complete Date: October 22, 2025 Branch: 8-single-process-prototype


Overview

The single-process prototype implements a discrete event simulation (DES) of a 3×3 urban grid with five intersections, realistic vehicle behavior, and fully synchronized traffic lights. Everything runs under one process, laying the groundwork for the distributed architecture in Phase 3.


Core Architecture

SimulationEngine

Drives the DES loop with a priority queue of timestamped events — vehicles, lights, crossings, and periodic stats updates. Handles five intersections (Cr1Cr5) and six event types.

Main loop:

while (events && time < duration):
    event = nextEvent()
    time = event.timestamp
    handle(event)

VehicleGenerator

Spawns vehicles via:

  • Poisson arrivals (λ = 0.5 veh/s) or fixed intervals
  • Probabilistic routes from E1E3
  • Type distribution: 20% BIKE, 60% LIGHT, 20% HEAVY

StatisticsCollector

Tracks system-wide and per-type metrics: throughput, avg. wait, queue sizes, light cycles — updated every 10 s and at simulation end.


Model Highlights

  • Vehicle type, route, timings, lifecycle.
  • Intersection routing tables, traffic lights, queues.
  • TrafficLight red/green cycles with FIFO queues.
  • Event timestamped, comparable; 6 types for all DES actions.

Configuration (simulation.properties)

simulation.duration=60.0
simulation.arrival.model=POISSON
simulation.arrival.rate=0.5

vehicle.bike.crossingTime=1.5
vehicle.light.crossingTime=2.0
vehicle.heavy.crossingTime=4.0

statistics.update.interval=10.0

Speed logic: t_bike = 0.5×t_car, t_heavy = 2×t_car.


Topology

E1→Cr1→Cr4→Cr5→S
E2→Cr2→Cr5→S
E3→Cr3→S
Bi-dir: Cr1↔Cr2, Cr2↔Cr3

Results

Unit Tests: 7/7 60-Second Simulation:

  • Generated: 22 vehicles
  • Completed: 5 (22.7%)
  • Avg system time: 15.47 s
  • Throughput: 0.08 veh/s
  • All lights & intersections operational

Performance: ~0.03 s real-time run (≈2000× speed-up), < 50 MB RAM.


Code Structure

sd/
├── engine/SimulationEngine.java
├── model/{Vehicle,Intersection,TrafficLight,Event}.java
├── util/{VehicleGenerator,StatisticsCollector}.java
└── config/SimulationConfig.java

Key Flow

  1. Initialize intersections, lights, first events.
  2. Process events chronologically.
  3. Vehicles follow routes → queue → cross → exit.
  4. Lights toggle, queues drain, stats update.
  5. Print summary and performance metrics.

Next Steps — Phase 3

  • Split intersections into independent processes.
  • Add socket-based communication.
  • Run traffic lights as threads.
  • Enable distributed synchronization and fault handling.

TL;DR

Solid single-process DES Everythings working — traffic lights, routing, vehicles, stats. Ready to go distributed next.