Showing posts with label strategy. Show all posts
Showing posts with label strategy. Show all posts

Saturday, July 9, 2011

Tyre Strategy: First Guess at a Strategy Model

Following on from a comment to How do you calcluate and optimal tyre stategy by Malcolm33, I had a go a putting together a Python script to identify the relative penalties accruing from different strategies compared to completing the race using an ideal, non-degrading tyre.

# Strategy Calculator
# Inspired by comment by Malcolm33 to 
# http://f1datajunkie.blogspot.com/2011/06/how-do-you-calculate-optimal-pit-stop.html?showComment=1309963019997#c2438489699153529837

tyredegradation={}
#Use a really crude tyre model for now: tyre degrades at additive rate 'phase 1 degradation' per lap
# until start of phase 2, then at incremental phase 2 degradation per lap
#The bias term rate base lap time of each tyre relative to best performing tyre
#tyremodel: bias, phase1 degradation, start of phase2, phase2 degradation
tyredegradation['H']=(1,0.05,99,0.05)
tyredegradation['S']=(0,0.1,15,0.5)
pitloss=12
pitstop=4
laps=52

pitTime=pitloss+pitstop

#If I'm right in remembering sum of i from 1 to N is 0.5*N(N+1)...
def stintTime(lapstodo,tyremodel):
 bias,ph1d,ph2s,ph2d=tyremodel
 if lapstodo < ph2s:
  t=bias*lapstodo+0.5*lapstodo*(lapstodo+1)*ph1d
 else:
  xlap1=ph2s-1
  xlap2=lapstodo-ph2s+1
  t=bias*lapstodo+ph1d*0.5*xlap1*(xlap1+1)+ph2d*0.5*xlap2*(xlap2+1)
 return t

#The strategy calculations sum the total "lost time" compared to completing race on best tyre
# with no pitstops, bias or degradation
#Strategies are calculated for each tyre combination and each possible stop combination
 
#One stop
strategies=[('H','S'),('S','H')]

for strategy in strategies:
 min=999
 t=0
 print "Strategy",strategy
 tph1,tph2=strategy
 for lap in range(1,laps-1):
  tp1=stintTime(lap,tyredegradation[tph1])
  tp2=stintTime(laps-lap,tyredegradation[tph2])
  t=tp1+pitTime+tp2
  #print 'One stop: stop on lap',lap,'timeloss:',t,'from phase 1',tp1,', phase 2',tp2
  if t < min:
   opt=(lap,t)
   min=t
 print 'Optimal 1-stop on',strategy,opt


#Two stop
strategies=[['H','S','S'],['H','S','H'],['H','H','S'],['S','S','H'],['S','H','S'],['S','H','H']]

for strategy in strategies:
 min=999
 t=0
 print "Strategy",strategy
 tph1,tph2,tph3=strategy
 for endstint1 in range(1,laps-1):
  for endstint2 in range(endstint1+1,laps):
   tp1=stintTime(endstint1,tyredegradation[tph1])
   tp2=stintTime(endstint2-endstint1,tyredegradation[tph2])
   tp3=stintTime(laps-endstint2,tyredegradation[tph3])
   
   t=tp1+pitTime+tp2+pitTime+tp3
   #print 'One stop: stop on lap',lap,'timeloss:',t,'from phase 1',tp1,', phase 2',tp2
   if t < min:
    opt=(endstint1,endstint2,t)
    min=t
 print 'Optimal 2-stop on',strategy,opt

#Three stop
strategies=[['H','S','S','S'],['H','S','S','H'],['H','S','H','S'],['H','S','H','H'],['H','H','H','S'],['H','H','S','H'],['H','H','S','S'],['S','H','H','H'],['S','H','H','S'],['S','H','S','H'],['S','H','S','S'],['S','S','S','H'],['S','S','H','S'],['S','S','H','H']]

for strategy in strategies:
 min=999
 t=0
 print "Strategy",strategy
 tph1,tph2,tph3,tph4=strategy
 for endstint1 in range(1,laps-2):
  for endstint2 in range(endstint1+1,laps-1):
   for endstint3 in range(endstint2+1,laps):
   
    tp1=stintTime(endstint1,tyredegradation[tph1])
    tp2=stintTime(endstint2-endstint1,tyredegradation[tph2])
    tp3=stintTime(endstint3-endstint2,tyredegradation[tph3])
    tp4=stintTime(laps-endstint3,tyredegradation[tph4])
    
    t=tp1+pitTime+tp2+pitTime+tp3+pitTime+tp4
    #print 'One stop: stop on lap',lap,'timeloss:',t,'from phase 1',tp1,', phase 2',tp2
    if t < min:
     opt=(endstint1,endstint2,endstint3,t)
     min=t
 print 'Optimal 3-stop on',strategy,opt

Here's what I get for a 52 lap race using the crude, guesstimated tyre model parameters shown above:
Optimal 1-stop on ('H', 'S') (33, 95.05)
Optimal 1-stop on ('S', 'H') (19, 95.05)
Optimal 2-stop on ['H', 'S', 'S'] (18, 35, 85.55)
Optimal 2-stop on ['H', 'S', 'H'] (18, 35, 96.69999999999999)
Optimal 2-stop on ['H', 'H', 'S'] (18, 35, 96.69999999999999)
Optimal 2-stop on ['S', 'S', 'H'] (17, 34, 85.55)
Optimal 2-stop on ['S', 'H', 'S'] (17, 35, 85.55)
Optimal 2-stop on ['S', 'H', 'H'] (17, 35, 96.69999999999999)
Optimal 3-stop on ['H', 'S', 'S', 'S'] (4, 20, 36, 88.5)
Optimal 3-stop on ['H', 'S', 'S', 'H'] (9, 25, 42, 97.5)
Optimal 3-stop on ['H', 'S', 'H', 'S'] (9, 25, 35, 97.5)
Optimal 3-stop on ['H', 'S', 'H', 'H'] (12, 29, 41, 107.6)
Optimal 3-stop on ['H', 'H', 'H', 'S'] (12, 24, 35, 107.6)
Optimal 3-stop on ['H', 'H', 'S', 'H'] (12, 24, 41, 107.6)
Optimal 3-stop on ['H', 'H', 'S', 'S'] (9, 18, 35, 97.5)
Optimal 3-stop on ['S', 'H', 'H', 'H'] (17, 29, 41, 107.6)
Optimal 3-stop on ['S', 'H', 'H', 'S'] (16, 25, 35, 97.5)
Optimal 3-stop on ['S', 'H', 'S', 'H'] (16, 25, 42, 97.5)
Optimal 3-stop on ['S', 'H', 'S', 'S'] (16, 20, 36, 88.5)
Optimal 3-stop on ['S', 'S', 'S', 'H'] (16, 32, 48, 88.5)
Optimal 3-stop on ['S', 'S', 'H', 'S'] (16, 32, 36, 88.5)
Optimal 3-stop on ['S', 'S', 'H', 'H'] (16, 32, 42, 97.5)

If you think I've messed this model up, please post a critical analysis of it in the comments:-)

A major issue is the simplicity of the tyre model. Even within the tyre model I've used, there may be "issues" with the parameters (incremental degradation rates, bias and phase boundary. Ideally, I'd be able to use practice timing data to tune these values (or even in race timing data), so suggestions for how to go about this would be appreciated. (You can get a link to the timing data as a spreadsheet from the Data page.)

Wednesday, June 29, 2011

F1 Practice Session Experiments - What's Going On?

You may or may not know that this week is National Motorsport Week in the UK (I wonder why they didn't mention it at the Isle of Wight Speedway last night???), Over on GoMotorsport the UK-based F1 teams have been taking it in turns to run a daily competition, and I think I may have picked up one of the spots on the Virgin Racing factory tour (not sure if I replied to the email invite quickly enough)...:-)

SAM_1383

Anyway, on the off chance that I do have a place on the tour, I thought I'd do a bit of prepping around some questions I might ask... The obvious thing that comes to mind relates to the role of High Performance Computing and the use of CFD in the design of the Virgin car, as well some of the reasons why CFD might not be able to deliver all that wind tunnel testing does...

The visit is a factory tour, though, so I guess something about materials and maybe the use of 3D printing in prototyping may be appropriate?

The extent to which on-track captured telemetry data is used to replay stresses and strains on various bits of the car in various test rigs is something else I'd like to ask about (I assume this does go on...), as well as the role of the strategist over the race weekend...

But something else that's been niggling at me lately, and that I may get a chance to ask about (if I've got the place, and if the opportunity arises), is this: what goes on during practice, how is that information used to plan out race strategy, and is there anything in the publicly available practice timing data that the armchair strategist can draw on to tryi to figure out what might happen during the race itself?

To ground the question, here's a snapshot of Car 25's fast laptime data over the practice sessions from the 2011 European Grand Prix weekend:



The symbols denote stint and the colours practice session.

To pick apart the possible experiments I think there are several different sorts of regime that may be worth clarifying in terms of what we might guess is going on.

Here's the second practice session, and in particular the latter two stints:



So my questions would be these:

- does the first of those example stints provide us with a tyre model (for which tyre? Can we identify tyres from the practice timing sheets?
- in the second example stint, is there an experiment going on that accounts for the +0.6s delta in the fourth and seventh laptimes (diamond symbol)?

Looking at data from the (other) Spanish Grand Prix, we see similar signatures:



In the third stint, the crosses show a couple of "but one" tours that are a delta of 1 second or so off the pace - what's going on here? Is it the same sort of test? (Maybe not using KERS or DRS on the lap?)

And for the last couple of stints in this session:



do we again get information here that the armchair strategist can put into a crude tyre model?

As ever, any and all comments appreciated:-)

PS Bah - a gremlin in my config files means the fuel corrected laptimes are off - i was using settings for Monaco:-(

Tuesday, June 28, 2011

How Do You Calculate An Optimal Pit Stop Strategy for a 2011 F1 Race?

In aid of National Motorsport Week (see GoMotorsport for more details), I thought I'd put a couple of questions out there to the F1 teams, and maybe some of the more academic minded F1 fans.

Here's the first question, lifted from a comment I posted earlier today on James Allen's F1 blog.

In response to a quip of the sort JA makes in many of his strategy briefings ("[m]any had planned to do the race on a two-stop strategy, which on paper was eight seconds faster than a three-stop, assuming you had a trouble-free run in traffic"), my question is this:

Is there anywhere that shows the working for this sort of calculation? I'm thinking of something like the refuelling strategy calculation that McLaren published as part of an outreach project a few years ago.

With the case of refuelling, it's easy enough to demonstrate that the optimal strategy when it comes to refuelling, all other things being equal, is not to start the race with a full fuel load, but instead incur a pitstop penalty in lieu of the time penalty incurred by lugging around a dead weight of fuel for much of the duration of the race.

With no refuelling, the time gains that are used to offset the pit stop losses must come from reducing some other time penalty, which can only leave the tyres as the dominant responsible factor (all other things being equal). In particular, there are presumably two tyre models to be taken into account, one for each sort of tyre that has to be used during the race.

Ian Horlock's Bristol University Masters thesis on Prediction of Formula One Results Using Driver Characteristics had something to say about tyre models I think, so I should probably read through that thesis again (and pay more attention this time!)

If you can describe the model that justifies James Allen's claim that the optimal strategy for Valencia was a two stopper, and also show that it was predicted at 8 seconds faster than a three stopper, either in the comments or via a link to worked description elsewhere, I'd be keen to see it...:-)

PS here are some possible relevant references (I haven't had chance to check them out yet, and apologise in advance for them being links to commercial publications (though you'll probably be able to get them free if you're a student or work for a university, and may even be able to get them though a public library; free downloads of the papers may also be available - I'll add links if I find them)

- The 2007 IEEE CEC simulated car racing competition, Julian Togelius, Simon Lucas, Ho Duc Thang, Jonathan M. Garibaldi, Tomoharu Nakashima, Chin Hiong Tan, Itamar Elhanany, Shay Berant, Philip Hingston and Robert M. MacCallum, et al. GENETIC PROGRAMMING AND EVOLVABLE MACHINES Volume 9, Number 4, 295-329, DOI: 10.1007/s10710-008-9063-0
- Planning Formula One race strategies using discrete-event simulation,Bekker, J; Lotz, W. Journal of the Operational Research Society, Volume 60, Number 7, May 2009 , pp. 952-961(10)