Live data from Hacker News

Show HN: Dijkstra’s algorithm in the web browser with OpenStreetMap

christophercliff.com

21–30 of 37 posts

Re: Show HN: Dijkstra’s algorithm in the web browser with OpenStreetMap

#21
post #8

Anyone who's interested in this might want to check out the OSRM project, which uses a much more complex routing algorithm to efficiently find paths through the entire OSM graph, instead of just a tiny subset: http://map.project-osrm.org/ (Also, it's open-source.)

I'm one of the OSRM devs.

To expand on this comment a bit - OSRM still uses Dijkstra, so if you understand that, you already basically understand what OSRM does.

What OSRM does in order to speed things up is optimize the graph structure - we still use Dijkstra, but the search completes in a handful of steps, rather than hundreds of thousands.

There are quite a few techniques like this. OSRM implements an approach called Contraction Hierarchies. We scan over the graph, inserting "shortcuts" that skip over nodes. As long as you follow a few basic rules, you can repeatably insert shortcuts all over the graph. This gives you a routing graph that is equivalent, but a Dijkstra search will typically complete in a handful of iterations.

We hope one day to implement several other speedup techniques - each has advantages/disadvantages, depending on what you want to do. Contraction Hierarchies lead to very fast queries (~5ms for a cross-the-US route), but the pre-processing time is very long (~6hrs on a beefy machine for the OSM planet). Any updates to the graph require complete re-processing (new/removed roads, adjusted road speeds, etc). Other techniques compromise search performance for a bit more flexibility - faster update times, query customization (i.e. "avoid highways").

It's a really fascinating corner of CS theory to work in, I really enjoy it :-)

This paper:

https://arxiv.org/pdf/1504.05140.pdf

"Route Planning in Transportation Networks" gives an excellent overview of current search speedup techniques. It's a bit hefty, but if you're interested in knowing what's the state of the art, this is a good place to start.

Re: Show HN: Dijkstra’s algorithm in the web browser with OpenStreetMap

#23
post #17

Related: A few friends and I built a similar visualization for pathfinding algorithms with OSM data for an AI class: http://www.kevanahlquist.com/osm_pathfinding/ It shows how nodes are explored on the map with different search algorithms and the optimal path once the search is completed.

That is very cool, some of the results are hilarious, i.e. depth first.

Re: Show HN: Dijkstra’s algorithm in the web browser with OpenStreetMap

#24
post #17

Related: A few friends and I built a similar visualization for pathfinding algorithms with OSM data for an AI class: http://www.kevanahlquist.com/osm_pathfinding/ It shows how nodes are explored on the map with different search algorithms and the optimal path once the search is completed.

That is very cool, some of the results are hilarious, i.e. depth first.

DFS is my favorite, but if you let it run long enough it might crash your browser tab.

Re: Show HN: Dijkstra’s algorithm in the web browser with OpenStreetMap

#26
post #21
post #8

Anyone who's interested in this might want to check out the OSRM project, which uses a much more complex routing algorithm to efficiently find paths through the entire OSM graph, instead of just a tiny subset: http://map.project-osrm.org/ (Also, it's open-source.)

I'm one of the OSRM devs. To expand on this comment a bit - OSRM still uses Dijkstra, so if you understand that, you already basically understand what OSRM does. What OSRM does in order to speed things up is optimize the graph structure - we still use Dijkstra, but the search completes in a handful of steps, rather than hundreds of thousands. There are quite a few techniques like this. OSRM implements an approach cal…

> but the pre-processing time is very long

Could you elaborate on why the preprocessing time is long? I didn't study contraction hierarchies, but to me it seems that computing shortcuts in a planar graph is the perfect fit for a divide-and-conquer approach.

Re: Show HN: Dijkstra’s algorithm in the web browser with OpenStreetMap

#28
post #26
post #21

Earlier quoted context omitted.

I'm one of the OSRM devs. To expand on this comment a bit - OSRM still uses Dijkstra, so if you understand that, you already basically understand what OSRM does. What OSRM does in order to speed things up is optimize the graph structure - we still use Dijkstra, but the search completes in a handful of steps, rather than hundreds of thousands. There are quite a few techniques like this. OSRM implements an approach cal…

> but the pre-processing time is very long Could you elaborate on why the preprocessing time is long? I didn't study contraction hierarchies, but to me it seems that computing shortcuts in a planar graph is the perfect fit for a divide-and-conquer approach.

You want the shortcuts to be long, so you can't just recursively divide the graph. The Wikipedia article does a fairly good job of explaining CH: https://en.wikipedia.org/wiki/Contraction_hierarchies

Re: Show HN: Dijkstra’s algorithm in the web browser with OpenStreetMap

#29
post #25

I thought that Dijkstra required rasterization... But here it appears that it works with graph... Is there something I have missed ?

What would you need rasterization for? Dijkstra works fine on arbitrary graphs with non-negative edges!

Re: Show HN: Dijkstra’s algorithm in the web browser with OpenStreetMap

#30
post #9
post #8

Anyone who's interested in this might want to check out the OSRM project, which uses a much more complex routing algorithm to efficiently find paths through the entire OSM graph, instead of just a tiny subset: http://map.project-osrm.org/ (Also, it's open-source.)

Are there any instructions? It took me a long while to figure out how to drop pins (the placeholder text says you have to press Enter, but you actually need to use the mouse), and now I have no idea how to display the route.

I've got the two markers but no route being displayed, is there a third step (firefox and chrome)?
Post reply on HN