A comprehensive Formula 1 car setup optimization platform that combines machine learning, physics simulation, and advanced optimization algorithms to find optimal car configurations for different tracks and racing conditions.
This project serves as a complete Formula 1 engineering workbench that addresses the complex challenge of car setup optimization through multiple AI-driven approaches.
Formula 1 car setup involves balancing numerous conflicting parameters (aerodynamics, suspension, braking) to achieve optimal lap times while considering:
- Track-specific characteristics (Monaco vs Monza require completely different approaches)
- Multi-objective tradeoffs (lap time vs tire wear vs stability)
- Dynamic conditions (weather, fuel load, track temperature)
- Strategic considerations (qualifying vs race setup, grid position impact)
The platform implements three distinct optimization strategies:
- Bayesian Optimization – Efficient single-objective optimization using Gaussian processes
- Multi-Objective Optimization (NSGA-II) – Pareto frontier analysis for competing objectives
- Reinforcement Learning – PPO agent that learns optimal setups through environmental interaction
- Real-time parameter adjustment: Front/Rear Wing angles, Ride Height, Suspension stiffness, Brake Bias
- Live performance visualization: Radar charts for Top Speed, Cornering, Stability, and Tire Life balance
- Physics-based telemetry simulation: Speed, brake, and throttle profiles over track distance
- Setup health monitoring: Anomaly detection for unsafe or suboptimal configurations
- Bayesian Optimization: Uses scikit-optimize for efficient parameter space exploration
- Pareto Front Analysis: Multi-objective optimization revealing lap time vs tire wear tradeoffs
- Reinforcement Learning Agent: Pre-trained PPO models adapt to track conditions and grid position
- Predictive Analytics: ML models for lap time prediction, anomaly detection, and maintenance risk assessment
- SHAP-based feature analysis: Understand which setup parameters impact performance most
- Setup comparison tools: Side-by-side analysis of different configurations
- Optimization history tracking: Evolution of setup improvements over time
- Professional reporting: Export detailed analysis reports in multiple formats
- 20+ real F1 circuits with detailed characteristics
- Track-specific base times and difficulty ratings
- Optimal strategy recommendations for each circuit
- Environmental condition modeling (temperature, weather, humidity)
- Grid position impact analysis for strategic setup decisions
| Component | Technology Stack |
|---|---|
| Frontend | Streamlit + Plotly for interactive visualizations |
| Machine Learning | scikit-learn, scikit-optimize, RandomForest, Isolation Forest |
| Multi-Objective Optimization | pymoo (NSGA-II algorithm) |
| Reinforcement Learning | Stable Baselines3 (PPO), Custom Gymnasium environment |
| Physics Simulation | Custom physics engine with aerodynamics and tire models |
| Data Processing | NumPy, Pandas for numerical computation and data handling |
| Explainability | SHAP for model interpretability |
| Export & Reporting | JSON, CSV, PDF report generation |
- Python 3.10+ (Required for Stable Baselines3 compatibility)
- pip package manager
- Git for cloning the repository
1. Clone the repository
git clone https://github.com/rembertdesigns/F1-car-setup-optimizer.git
cd F1-car-setup-optimizer2. Set up Python virtual environment
python -m venv venv
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate3. Install dependencies
pip install --upgrade pip
pip install -r requirements.txt4. Create necessary directories
mkdir -p data models/rl logs1. Generate synthetic training data
python src/simulate_physics_model.py2. Train core prediction models
# Main lap time predictor (REQUIRED)
python src/train_model.py
# Anomaly detection model
python src/train_anomaly_model.py
# Maintenance risk predictor
python src/train_maintenance_model.py3. Train reinforcement learning agent (Optional but recommended)
python src/train_rl_agent.pyNote: RL training takes 10-15 minutes depending on your hardware
4. Launch the application
streamlit run src/app.pyThe app should open in your browser at http://localhost:8501. You should see:
✅ No "Model not found" errors
✅ All optimization modes working (Bayesian, NSGA-II, RL)
✅ Performance predictions updating when you adjust parameters
F1-car-setup-optimizer/
│
├── 📂 data/ # Training data and logs
│ ├── synthetic_car_setup_v2.csv # Generated training dataset
│ └── setup_log.csv # User-generated setup logs
│
├── 📂 logs/ # Training logs and tensorboard data
│ └── rl/ # RL training logs
│
├── 📂 models/ # Trained ML models
│ ├── 📂 rl/ # Reinforcement learning models
│ │ ├── ppo_car_setup_agent_*.zip # Training checkpoints
│ │ └── ppo_car_setup_final.zip # Final trained RL agent
│ ├── lap_time_predictor_v2.pkl # Main prediction model
│ ├── setup_anomaly_detector.pkl # Anomaly detection
│ ├── maintenance_risk_predictor.pkl # Predictive maintenance
│ └── *.json # Feature configurations
│
├── 📂 src/ # Source code
│ ├── 📂 envs/ # RL environment
│ │ └── setup_env.py # Custom Gymnasium environment
│ ├── app.py # Main Streamlit application
│ ├── optimizer.py # Optimization algorithms
│ ├── physics_model.py # Physics simulation engine
│ ├── simulate_physics_model.py # Data generation
│ ├── train_model.py # ML model training
│ ├── train_rl_agent.py # RL agent training
│ ├── train_anomaly_model.py # Anomaly detection training
│ └── train_maintenance_model.py # Maintenance model training
│
├── requirements.txt # Python dependencies
├── LICENSE # MIT License
└── README.md # This documentation
- Choose from 20+ real F1 circuits in the sidebar
- Each track has unique characteristics and optimal strategies
- Set environmental conditions (temperature, weather, fuel load)
- Adjust aerodynamic parameters (front/rear wing angles)
- Configure suspension settings (ride height, stiffness)
- Set brake bias for optimal braking balance
- Observe real-time performance radar chart updates
- Single Objective: Focus purely on lap time optimization
- Multi-Objective: Explore lap time vs tire wear tradeoffs
- Reinforcement Learning: Let the AI agent suggest track-specific setups
- Save setups to Slots A & B for side-by-side comparison
- View detailed telemetry simulations
- Export comprehensive reports for further analysis
- SHAP Analysis: Understand which parameters impact performance most
- Anomaly Detection: Get warnings about unsafe setup combinations
- Pareto Front Visualization: See optimal tradeoff curves
- Setup Evolution: Track optimization history over time
"Model not found" errors:
# Make sure you've run all training scripts:
python src/simulate_physics_model.py # Generate data first
python src/train_model.py # Train main model
python src/train_anomaly_model.py # Train anomaly detector
python src/train_maintenance_model.py # Train maintenance modelRL optimization not working:
# Train the RL agent:
python src/train_rl_agent.py
# This creates models/rl/ppo_car_setup_final.zipImport errors:
# Ensure you're in the virtual environment and have installed requirements:
pip install -r requirements.txtPerformance issues:
- RL training is CPU-intensive; expect 10-15 minutes on average hardware
- The app loads faster after initial model training is complete
- Use lighter optimization modes (Bayesian) for faster response
- Real telemetry integration using FastF1 API for actual F1 data
- Enhanced physics simulation with tire degradation models
- Weather impact modeling for dynamic condition changes
- Setup templates for different driving styles
- Full race weekend simulation (Practice → Qualifying → Race)
- Driver feedback integration for setup preference learning
- Team strategy optimization considering pit stop windows
- 3D visualization of aerodynamic flow and setup impact
- Model ensemble methods for improved prediction accuracy
- Active learning for continuous model improvement
- Cloud deployment options for team collaboration
- API endpoints for integration with external tools
This project is licensed under the MIT License – see the LICENSE file for details.
Contributions are welcome! Areas where help is particularly valuable:
- Physics model refinement (aerodynamics, tire models)
- Additional optimization algorithms (genetic algorithms, simulated annealing)
- Real F1 data integration and validation
- Performance optimization and code refactoring
- Documentation and tutorial creation
- Formula 1 for inspiration and the fascinating technical challenge
- Streamlit team for the excellent web app framework
- scikit-optimize and pymoo for optimization algorithms
- Stable Baselines3 for reinforcement learning capabilities
- F1 engineering community for insights into car setup principles
