In Ulysses, James Joyce mused that "a good puzzle would be to cross Dublin without passing a pub". No-one's really sure if it was possible, and Dubliners have always felt proud that it was not straight forward. The traditional Irish way to 'solve' this puzzle is to walk across Dublin, and call into every pub in the way and have a pint. This way you never actually pass a pub!
However with computers and open data from OpenStreetMap it's possible to answer this question! And yes! it is possible to cross Dublin without passing a pub.
How? Here's the route:
Can't see anything? Try downloading this overview image of the route. This image is Creative Commons licenced. Please include "ⓒ OSM Contributors CC-BY-SA" if you're reuse it.
Spot a mistake?
The name and location of all the pubs is from OpenStreetMap, and is not complete, however it's very good. If you find a mistake, find a pub that's not on there, just leave a comment.
Updates so far:
- The first version had it going past 2 pubs around museum, which I worked around.
- To make this watertight, I've avoided 2 hotels, Radison on Golden Lane, and St. Stephen's Green Hotel on St. Stephen's Greens. They aren't pubs (since they're hotels), however they have pubs inside.
Google Earth/Street View download
Thanks to the awesome IrlJidel, a fellow OpenStreetMap Ireland member, here's a a KML suitable for Google Street View/Google Earth to check this route.
Problem in detail
How do you 'cross Dublin'? I took about 30 points around the canals (15 northside, 15 southside), this is basically the route of the Dublin Outer Orbital Route. I decided that you had to go from northside to southside, i.e. you had to cross the city, and aswell as going north-south, you should go east-west.
I figured if you could go from one of them to another without passing a pub, then that would class as "crossing Dublin".
i.e. I tried to find how to walk one of these ways without passing a pub.
Note however, that 'Dublin' would have been much smaller when Ulysses was published.
See a birds eye map of all the pubs in Dublin to see the pubs that we must avoid.
'Passing a Pub'
What's a pub?
Anything in the OpenStreetMap database tagged
amenity=pub, is treated as a pub. There are loads of pubs in OSM, it's one of the most popular 'point of interest' to tag (after you've done the roads). You could possibly claim that a restaurant or hotel might count as a 'pub' since they might serve alcohol. But not all do, and some that do would have separate objects in OSM for the pub.
Many restaurants can sell you alcohol. However the experience of having a glass of wine over a meal is different from going down for a pint at your local, that I don't think including restaurants as 'pubs' is fair, and not within the spirit of the puzzle. So for this puzzle, you're allowed walk past a restaurant.
Some hotels have pubs inside them. Some hotels own an adjacent pub that is physically connected to the same building but has its own door. Some hotel pubs are usually filled with hotel guests, some hotel pubs are usually filled with more of the general population.
I think a pub that's inside a hotel, that's mostly filled with hotel clients shouldn't count. However a bar that's used as a normal bar should count. Luckily most of those bars are represented as a separate object, and hence would be excluded normally.
Walking past a pub
On the ground it's obvious if you have walked past a pub. However in OSM you mostly can't tell if a pub (represented as a node, a single point, rather than a building outline) is adjacent to a road (represented as a way). Instead I used a shortcut of saying that you can't pass within 35 metres of a pub. That should ensure that you don't pass by it.
35 m might sound like a lot, but the 'road' in OSM is just a thin line down the middle of where the road is in real life, and the 'pub' is just the centre of the pub, so you could be 10m away from the 'pub' and yet be across a 2 lane road from in front of the pub.
In Joyce's day, there were problably much more pubs, making this problem harder.
How it was solved (technical details)
For those interested in the technical details of how to do this, read on!
I used OpenStreetMap data, and wrote a simple python script that would parse the data and look for routes. I will write up detailed posts about individual parts later.
The OpenStreetMap data within the bbox (bounding box)
top = 53.3635 bottom = 53.3269 left = -6.3161 right = -6.2115 was downloaded from the OSM API server, and parsed with
xml.etree.ElementTree. At each run of the programme, it parsed the data anew. There was very little speed benefit to doing something more 'advanced'.
While reading all the nodes it stored a dictionary of nodes with the positions (and tags) of the nodes. While parsing the ways, it checked if the way was tagged with a
highway value one of
path, and the
access (if provided) is either
yes. This stops it trying to route us through private roads. If the way is tagged like that then it stored the 'connection' that you can go from
node2 (and vice versa).
If the way was tagged
area=yes, i.e. it's an area (like a large pedestrian square), then it also adds in all the possible routes from one node on the edge to another, this enables it to let you walk across a pedestrian square.
Removing routes that pass a pub
For all of the 'connections' and all the pubs, it find the distance between that connection and the pub, using the 'point-line distance' formula. As a simplification, I ignored the curvature of the earth. That would have only added a few cm to any distances.
After I had a graph of all the ways you could walk, I iterated over all these segments, and pubs. Every segment that was too close to a pub was discarded, and deleted. Thus we would not be able to walk down that part.
I just brute forced the routing. That was the simpilest thing to do at the first. Once I'd programmed in the simplest way, it was quite quick to run, so I didn't bother optimising it to make it faster. The algorithm starts at the start nodes, and finds all the places it can go from there. It iteratively expands out the search until it reaches the target. This is a breadth first type search. To prevent the memory usage getting out of hand, it only kept the top 1,000 (or so) partial routes based on how close they get to the target. On each iteration, it starts with the routes that have gotten the closest to the target aswell. This speeds up searching, otherwise a brute force search would take a very long time to run, since it's searching down every blind alley.
The excellent Project Gutenberg has Ulysses available to read for free, (or get it on Amazon) if you are feeling literary.
For more information/follow up, you can email me: firstname.lastname@example.org
There are comments.