Boost, Python and Dijkstra

Boost “provides free peer-reviewed portable C++ source libraries.” It also provides some very good Graph manipulation functions, one of which is a very fast Dijkstra shortest-path implementation that I wanted to use from within Python.

Bear in mind that for this project I need to host Python in a Windows 2003 Server machine. First thing to do is to get the Python bindings for the Boost Graph Library. Problem is, it isn’t very clear how do you install it… After trying a while, I copied the contents of bgl-python-0.9/python/boost/graph to $python$/lib/site-packages/boost/… it worked :)

Second problem is to understand all this C++ templating world. If you try to invoke a binded function from within Python you can get something really cryptic (try writting boost.dijkstra_shortest_paths() in the interpreter).

After trying to read the documentation, looking at the usage example of BGL, and banging my head into a wall several times, I finally found how to make it work… I leave a simple example here for anyone who’s interested.

Tags: , , , ,

Leave a Reply