A neuroevolution-based traffic simulation and prediction engine where autonomous vehicles learn to navigate from one point to another without going off the road while adapting to spatial and temporal traffic dynamics. The vehicles evolve their driving behavior through neuroevolution for path optimization, while a spatially-aware intelligence layer powered by Geographically Weighted Regression (GWR) using gwlearn(https://github.com/pysal/gwlearn) enables them to dynamically adjust speed and movement based on zone type, time of day, and local traffic conditions. By comparing global models with spatially-aware models, the project demonstrates how location-specific intelligence significantly improves autonomous navigation in non-stationary urban environments.
- Python 3.11+
- Git
-
Clone the repository:
git clone https://github.com/yourusername/spatiotemporal-av-navigator.git cd spatiotemporal-av-navigator -
Run the setup script (Windows):
SETUP_AND_RUN.bat
Or manually:
python -m venv venv # Windows: venv\Scripts\activate # Linux/Mac: source venv/bin/activate pip install -r requirements.txt
Launch the full interactive visualization server:
python app.pyOpen your browser to http://localhost:5000. This provides:
- Real-time traffic simulation
- Interactive route planning
- Comparison dashboards between Global and Spatial models
- Heatmap visualizations
Run the standalone examples to see the data science behind the project.
Example 1: Basic Traffic Modeling Generates a synthetic city and proves that spatial models outperform global averages.
python examples/01_basic_traffic_modeling.pyExample 2: Evolving Spatial Intelligence Uses a Genetic Algorithm to evolve the optimal "spatial bandwidth" for a specific city layout.
python examples/02_evolving_spatial_intelligence.pyTraditional traffic prediction often treats an entire city as a single dataset (Global Model), ignoring local nuances. This project demonstrates that a Spatially-Aware Model—which weighs nearby data points more heavily than distant ones—can significantly reduce prediction error.
- Procedural City Generation: Creates realistic road networks with distinct zones (Downtown, Residential, Industrial).
- Temporal Dynamics: Simulates rush hour patterns that vary by zone (e.g., Downtown is congested at 5 PM, Suburbs at 8 AM).
- Spatial vs. Global AI: Benchmarks standard Linear Regression against Geographically Weighted Regression (GWR).
- Neuro-Evolution: Implements genetic algorithms to optimize spatial parameters automatically.
The core of this project relies on Geographically Weighted Regression (GWR), implemented via the gwlearn library (a Scikit-Learn compatible wrapper for libpysal).
-
Data Generation: The system procedurally generates a synthetic city with non-stationary traffic rules. For example:
- Downtown: High base congestion, severe evening rush hour.
- Suburbs: Low congestion, moderate morning rush hour.
- Industrial: Constant heavy truck traffic.
-
Model Training (Global vs. Spatial)
-
Global Model (
sklearn.LinearRegression)
Trains a single linear equation on the entire dataset. It averages out the differences between zones, leading to high error rates in complex areas.y = beta_0 + beta_1 * x_1 + ... + epsilon -
Spatial Model (
gwlearn.GWLinearRegression)
This is wheregwlearnshines. It fits a separate regression model for every single point in space. When predicting traffic at locationu, it weights training samples based on their distance touusing a kernel function (e.g., Bisquare or Gaussian).y(u) = beta_0(u) + beta_1(u) * x_1 + ... + epsilonThis allows the model to "learn" that the correlation between Time of Day and Traffic Speed is negative in the city center (rush hour slows you down) but might be positive in residential areas during the day.
-
Visualizing the "Brain": The web app (
app.py) serves these predictions to a JavaScript frontend.- Red cars follow the Global Model's predictions (often speeding in congested zones).
-
Blue cars follow the
gwlearnSpatial Model's predictions (slowing down appropriately in traffic). - Heatmaps show the local
$R^2$ values, proving that the spatial model accurately captures the unique dynamics of each neighborhood.
-
Neuro-Evolution (Two Layers of AI): This project features two distinct evolutionary systems:
-
Layer 1: Spatial Intelligence (The "Oracle")
Runs in Python (Backend)
Uses a Genetic Algorithm to evolve the optimal Spatial Bandwidth forgwlearn. It learns how to analyze the city's traffic zones (e.g., "how far should I look to judge traffic density?"). -
Layer 2: Navigation Intelligence (The "Driver")
Runs in JavaScript (Frontend)
Each car is controlled by a Neural Network that takes inputs from:- LIDAR Sensors: Raycasts detecting road borders and other cars.
- GPS Vector: The angle to the target destination.
Using Genetic Algorithms, the cars evolve over generations. They start as random crashers but eventually "learn" to:
- Steer smoothly around curves.
- Avoid collisions with other vehicles.
- Navigate towards a target destination efficiently.
-
