The Rugby World Cup is well under way here in England. So far, I have been lucky enough to witness Japan beat South Africa at the Community Stadium in Brighton and next on my list is the nail biting encounter between England and Australia at Twickenham in South West London (Update: Even though it was disappointing to see England loose and go out of the tournament, it was a good day out). All this travelling got me thinking, what would be the fastest circular route to visit all the stadia hosting a Rugby World Cup game if one was lucky enough to have tickets?
The naive approach is to go to Google Maps and choose the best order yourself. However, and this is where the Numerical Algorithms Group comes in, algorithms exist to solve this type of problem. In fact, this is quite a famous problem and is commonly referred to as the Travelling Salesman Problem (TSP). A good introduction to the TSP can be found here.
So what can we use instead? The NAG Library contains a routine, H03BB, which can provide an approximate solution to the symmetric TSP. I was drawn to this routine for several reason: it has recently been added to the Library in Mark 25 and it simulates an interesting physical process called annealing.Annealing is the process of heating a metal to a certain temperature and then cooling it slowly. The reason for doing this is to remove any stresses that have developed during the original formation. On the molecular scale, energetic atoms are free to rearrange themselves into the lowest energy state. This reduces impurities in the crystalline structure.
Simulated annealing is inspired by the above physical process and attempts to solve the global optimization problem commonly known as the TSP. At higher ‘temperatures’ the solution space is traversed in large jumps. These help identify regions of low energy. Fundamental to the routine is the ability to jump to ‘higher’ energy states, as this allows a greater search of the solution space. Overall, the algorithm favours moving to a state lower in ‘energy’, rather than moving to a closer state with higher ‘energy’. Finally, as the ‘material’ cools, the jumps reduce in size. More information can be found here.
Before we can use the H03BB algorithm, we need some input data. At this point, I remembered that I had seen a similar problem on Reddit. Dr. Randy Olson used a genetic algorithm to solve the TSP. His blog post can be found here. On his blog, he also provided all the necessary code, in Python, to download a matrix of distances between the points from Google Maps using the Google Maps API. Details on how to get this matrix can be found here. He also produced a HTML file that can be used to display the solution on a webpage. That code can be found here.
So, we have an algorithm to solve the TSP, a method of getting the input data and a way of displaying the results. It’s now time to go ahead and solve the problem. The following stadia are hosting at least one game during the Rugby World Cup:
- Brighton Community Stadium, Brighton
- Elland Road, Leeds
- Kingsholm Stadium, Gloucester
- Leicester City Stadium, Leicester
- Millennium Stadium, Cardiff
- Manchester City Stadium, Manchester
- Stadium MK, Milton Keynes
- Olympic Stadium, London
- Sandy Park, Exeter
- St James’ Park, Newcastle
- Villa Park, Birmingham
- Wembley Stadium, London
- Twickenham Stadium, London
Using Randy’s code, I was able to get a matrix of journey durations between all the different stadia. This is 13 X 13 symmetric matrix with zeros along the diagonal. I then used the NAG4PY wrappers to call the NAG C Library and solve the TSP and obtain an approximation to the quickest route.
Finally, using Randy’s HTML file I was able to produce the route below. For this particular route, I decided that cycling would be my preferred mode of transport. As well as visiting all 13 stadiums, the route passes through three national parks, eleven areas of outstanding natural beauty and through London where it passes: Canary Wharf, Queen Elizabeth Olympic Park, The Royal Courts of Justice, Trafalgar Square, The Mall, Buckingham Palace, Hyde Park and Kew Gardens.