Overview
The pit stop optimization system manages pit stop timing, tire compound selection, and race strategy during simulations. It includes dynamic strategy adaptation for weather changes, safety car periods, and undercut/overcut opportunities. Source:race_engine.py
Pit Stop Constants
PIT_LOSS
Time penalty for making a pit stop (pit lane time loss). Source:race_engine.py:20
Fixed time cost in seconds for pit stop execution
- Pit lane speed limit penalty
- Deceleration and acceleration time
- Actual stop time (~3-4 seconds)
- Pit entry/exit time loss
Race Strategy Presets
STRATEGIES
Predefined pit stop strategies for dry conditions. Source:race_engine.py:84
Starting tire compound
List of planned pit stop lap numbers
Ordered list of tire compounds to use (includes starting tire)
| Strategy | Type | Starting Tire | Pit Lap(s) | Compounds Used | Best For |
|---|---|---|---|---|---|
| S-M | One-stop | SOFT | 18 | Soft → Medium | Qualifying pace, track position |
| M-H | One-stop | MEDIUM | 26 | Medium → Hard | Balanced approach |
| H-M | One-stop | HARD | 34 | Hard → Medium | Long first stint |
| S-M-H | Two-stop | SOFT | 15, 32 | Soft → Med → Hard | Maximum pace |
| M-M | One-stop | MEDIUM | 28 | Medium → Medium | Consistent pace |
WET_STRATEGY
Strategy preset for wet weather races. Source:race_engine.py:93
Starts on full wet tires
Empty list - no planned stops (until track dries)
Only wet tires used
Strategy Assignment
assign_strategies
Assigns racing strategies to all drivers based on weather and grid position. Source:race_engine.py:168
Starting weather condition: “DRY”, “LIGHT_RAIN”, or “HEAVY_RAIN”
Dictionary mapping driver codes to strategy objects
Pit Stop Decision Logic
Pit Stop Trigger
Pit stops are triggered by strategic planning or opportunistic timing. Source:race_engine.py:272-281
- Planned Stop: Current lap matches next planned pit lap
- Safety Car Window: Within 3 laps of planned stop AND safety car is out
- Weather Change: Automatic tire change if current tire unsuitable
Pit Stop Execution
When a pit stop is executed, the following occurs: Source:race_engine.py:283-298
- Time Penalty: +22 seconds to total race time
- Tire Reset: New compound, tire age reset to 0
- Strategy Update: Next compound from planned sequence
- Weather Adaptation: Automatic compound override if conditions changed
CarState Attributes
Pit-Related Attributes
Source:race_engine.py:97-128
Total number of pit stops completed
Remaining planned pit stop lap numbers (consumed as pits occur)
List of laps on which pit stops were actually taken
Current tire compound on the car
Number of laps completed on current tires
Full list of compounds in the strategy
Index of current compound in the compounds list
Complete Pit Strategy Examples
Race Result Analysis
Pit Stop Statistics
After a race simulation, detailed pit stop data is available in results. Result Fields:Total number of pit stops completed
List of lap numbers when pits occurred
Chronological list of tire compounds used
Dynamic Strategy Adaptation
Weather-Based Adaptation
Strategies automatically adapt when weather changes mid-race. Source:race_engine.py:287-291
| Planned Tire | Weather Change | Actual Tire |
|---|---|---|
| SOFT/MED/HARD | → LIGHT_RAIN | INTER |
| SOFT/MED/HARD | → HEAVY_RAIN | INTER |
| WET | → DRY | MEDIUM |
| INTER | → DRY | Unchanged* |
Strategy Comparison
- One-Stop vs Two-Stop
- Tire Selection
- Safety Car Impact
One-Stop Strategy:
- Single pit stop (~22s penalty)
- Longer stints with more degradation
- Simpler execution, less risky
- Best when tire deg is low
- Two pit stops (~44s penalty)
- Shorter stints, fresher tires
- More complex, traffic risk
- Best when tire deg is high
- One-stop: Base + 22s + high deg
- Two-stop: Base + 44s + low deg
- Breakeven depends on deg rate
Pit Strategy Optimization Tips
Undercut vs Overcut
Undercut (Pit Earlier):- Pit before competitor to gain time on fresh tires
- Requires ~2-3s lap time advantage with fresh tires
- Works best when traffic is low
- Risk: Gives up track position temporarily
- Stay out longer while competitor pits
- Gain time while running in clean air
- Can work if your tires hold up
- Risk: May lose too much time on old tires
Factors to Consider
- Tire Degradation: Higher deg → earlier pit more beneficial
- Traffic: Heavy traffic → overcut more attractive
- Safety Car Probability: High SC chance → delay pit if possible
- Weather Forecast: Rain expected → delay switching to slicks
- Gap to Competitor: Large gap → stick to planned strategy
Notes
- Pit stop timing is one of the most critical strategic decisions in F1
- Real-world pit stops average 2.5-4.0 seconds (not including pit lane time)
- Optimal strategy depends heavily on circuit characteristics and tire degradation severity
- Virtual Safety Car (VSC) also provides ~6s time saving for pitting
- Teams run thousands of race simulations to optimize pit strategy
- Undercuts typically gain 1-2 positions if executed within 3-lap window