Re: [pyton] how to use dijkstra's shortest path algorithm
Doug Gregor <[email protected]>
| Newsgroups | gmane.comp.lib.boost.langbinding |
|---|---|
| Message-ID | <[email protected]> |
On Feb 25, 2007, at 1:59 PM, Neeraj Shah wrote:
> Hi everyone,
>
> I am completely new to Boost, and have been playing with it through
> the python bindings, but I'm getting a bit confused.
>
> What I'm trying to do is use dijkstra's shortest path algorithm
> (with predecessor) on a graph I'm reading in from a graphviz file.
> My code is as below:
>
> import boost.graph as bgl
>
> #Create a new graph from the graphviz file
> graph = bgl.Graph.read_graphviz('code/mst.dot')
> #try to get shortest path
> min_paths = bgl.dijkstra_shortest_paths(graph,graph.vertices.next
> (),predecessorMap,distanceMap)
You'll need to initialize predecessorMap and distanceMap to
something, e.g.,
distanceMap = graph.add_vertex_property('distance')
predecessorMap = graph.add_vertex_property('predecessor')
(Assuming you're using the Subversion version of BGL-Python; it's
slightly different for 0.9)
Cheers,
Doug
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV