What do political campaigning and a famous math problem have in common? Plenty — if you’re deciding where to send your party leader out campaigning.

Between now and May 7, the political parties running in this year’s British general election will have to decide where to send their party campaign buses and their party leaders. The BBC has been tracking where they’ve gone so far — but where, ideally, should their battle buses go next?

Because Britain is fairly small compared to the U.S. (“slightly smaller than Oregon,” as the CIA puts it), traveling by bus is a reasonable way to get around the country. Trains and planes are fine too — but occasionally risky.

But a campaign bus — even one with tasteful accoutrements — is only useful if you know where to send it.

That’s where math comes in. If party leaders have to visit, say, 40 constituencies, how do they know the best order in which to visit them? The total number of possible orderings of constituencies is vast — not numbers of atoms in the universe vast, but large enough to make it awkward to figure out which order will produce the shortest itinerary

Thankfully, given that this problem — also called the traveling salesman problem — is fairly well known, there are a number of helpful algorithms for finding the optimal route, or a route that’s as close to optimal as makes no difference.

Armed with these algorithms — and some handy code from Randal Olson for calculating travel times using Google — we worked out the best route for each party through 40 seats that could tip the balance — 20 just below our forecast seat total for each party, and 20 just above.

Along these routes, the parties will have to fight different opponents: for David Cameron’s Conservative party, that might be Labour in some seats but the Liberal Democrats in others.

In practice, party leaders won’t follow our routes. David Cameron, Ed Miliband and Nick Clegg all have media engagements that require them to head back to London from time to time. Party strategists will also realize that some trips to marginal but remote constituencies (Hello, Caithness!) simply take up too much time. But these routes are a good indication of how geographically spread out parties’ campaigning efforts need to be this year.

Conservatives

David Cameron’s journey starts in the border area of Scotland, where the Conservatives could pick up two seats and take the edge off their unpopularity in Scotland. From there, it’s down south to circle around Manchester and Liverpool. The party then heads southwest into the Midlands before taking two large detours northeast (to Cleethorpes) and east (Norwich North). After heading through London and taking in some of the towns along the coast, the Conservative campaign makes a brief detour into Wales before ending its trip in the South West with a visit to Land’s End (St Ives). A list of the constituencies to visit and the time it takes to travel between them is in the footnotes.

Total time in transit: 1 day, 16 hours, 22 minutes.

Labour

Ed Miliband starts in Wales, in seats he and the Labour party hope to keep from Plaid Cymru. After moving down into South Wales, the Labour campaign moves on to some Midlands seats before getting its London visit in early. It’s then on to Brighton, to fight both the Greens and the Conservatives, before moving up the coast to Norwich North and Cleethorpes — two seats that also featured in the Conservatives’ list. Labour then heads through Sheffield and Manchester before crossing over into Scotland and working its way along the central belt and up the coast, finishing in Aberdeen.

Total time in transit: 1 day, 14 hours, 22 minutes

Liberal Democrats

Nick Clegg and the Liberal Democrats begin their journey on to the windswept North Norfolk coast before heading into London. With a brief detour to Cheltenham, they trace the outline of the coast, heading to St Ives before following the Severn Estuary up into Wales. The party then zigzags through the North of England before getting to a number of Scottish seats it must defend — even at the cost of long and tiring journeys through the Highlands.

Total time in transit: 1 day, 23 hours, 55 minutes.

The Liberal Democrats have the longest total time in transit — meaning that if the prospect of losing more than half their seats weren’t enough, they’ll also have to put up with fighting in geographically dispersed locations.

This long tour reflects the Liberal Democrats’ awkward position within the party system: They fight Conservatives in some rural parts of the country and Labour in some urban areas. That means their target seats are widely dispersed. Better hope those campaign buses have toilets on them.

What’s the benefit?

In their campaign activities, parties face really complex optimisation problems. What’s the marginal return on an extra campaign stop versus more time spent with local journalists? Is it better to leave local campaigners in rural constituencies to their own devices? But getting the right answers to these questions matters. Research has shown that visits by popular leaders can boost a party’s vote share by a percentage point. In an election this close, that’s too many votes to leave on the table.

Check out our 2015 general election predictions and full U.K. election coverage.