[Lemon-user] Question about using dijkstra's algorithm

Angyal Gábor angyalgabor at t-online.hu
Tue Jan 4 20:57:23 CET 2011


I'm not sure if you can get the path back directly (wait for the answer 
of a more competent person), but you can build your path by an 
iteration, using an ArcMap set by the predMap function. After running 
the algorithm every key Arc in this map will have its predecessor as value.
In your case the predMap function must get a parameter of thit type: 
SmartDigraph::ArcMap<SmartDigraph::Arc>.

On 01/04/2011 08:17 PM, Yongjia Song wrote:
> Thanks for the quick reply!
>
> What if I would like to get the path value? How to declare a path in 
> the first place so that I can get the path by
>
> path = dijkstra.path(t)
>
> Thanks,
>
> On Tue, Jan 4, 2011 at 1:09 PM, Angyal Gábor <angyalgabor at t-online.hu 
> <mailto:angyalgabor at t-online.hu>> wrote:
>
>     Hi,
>
>     Assuming that the other variables are declared correctly, your
>     code should work. e.g:
>
>     #include <lemon/smart_graph.h>
>     #include <lemon/dijkstra.h>
>     #include <stdio.h>
>
>     using namespace lemon;
>
>     int main()
>     {
>       SmartDigraph g;
>       SmartDigraph::ArcMap<int> length(g);
>       SmartDigraph::NodeMap<int> dist(g);
>       SmartDigraph::Node s = g.addNode();
>       SmartDigraph::Node t = g.addNode();
>       SmartDigraph::Arc a = g.addArc(s,t);
>       length[a] = 1;
>       Dijkstra<SmartDigraph> dijkstra(g, length);
>       dijkstra.distMap(dist);
>       dijkstra.init();
>
>       dijkstra.addSource(s);
>       dijkstra.start();
>       printf("%i\n", dist[t]);
>       return 0;
>     }
>
>     Note, that the "dijkstra" in the first example is different from
>     the "dijkstra" in the second, because the first is a function, and
>     the second is an instance of the Dijkstra class.
>
>     More information:
>     http://lemon.cs.elte.hu/pub/doc/1.1.1/a00437.html#ga6aa57523fe00e2b8fe2f5cd17dd15cea
>     http://lemon.cs.elte.hu/pub/doc/1.1.1/a00087.html
>
>     regards,
>     Gábor
>
>
>     On 01/04/2011 07:37 PM, Yongjia Song wrote:
>>     Hi all,
>>
>>     I am a new user of lemon, and I could not figure out a way to use
>>     dijkstra's algorithm appropriately.
>>
>>     Is there any example file for that? I can see that the
>>     documentation part of dijkstra's algorithm on the website could
>>     not work.
>>
>>     Basically, I use
>>
>>     SmartDigraph g;
>>     SmartDigraph::ArcMap<int> cap(g)
>>     Dijkstra<SmartDigraph> dijkstra(g,cap)
>>
>>     then I could not run either
>>       dijkstra  <http://lemon.cs.elte.hu/pub/doc/1.1.1/a00437.html#ga6aa57523fe00e2b8fe2f5cd17dd15cea>(g, cap).distMap(dist).run(s,t);
>>
>>
>>     or
>>
>>     dijkstra  <http://lemon.cs.elte.hu/pub/doc/1.1.1/a00437.html#ga6aa57523fe00e2b8fe2f5cd17dd15cea>.distMap(dist);
>>     dijsktra.init();
>>     dijkstra  <http://lemon.cs.elte.hu/pub/doc/1.1.1/a00437.html#ga6aa57523fe00e2b8fe2f5cd17dd15cea>.addSource(s);
>>
>>     dijkstra  <http://lemon.cs.elte.hu/pub/doc/1.1.1/a00437.html#ga6aa57523fe00e2b8fe2f5cd17dd15cea>.start();
>>
>>     Thanks,
>>
>>     -- 
>>     Sincerely:
>>     Song Yongjia(宋永佳)
>>
>>     Department of Industrial and Systems Engineering
>>     College of Engineering, University of Wisconsin-Madison
>>     3241 Mechanical Engineering Building
>>     1513 University Avenue, Madison, WI 53706
>>
>>
>>     _______________________________________________
>>     Lemon-user mailing list
>>     Lemon-user at lemon.cs.elte.hu  <mailto:Lemon-user at lemon.cs.elte.hu>
>>     http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
>
>
>     _______________________________________________
>     Lemon-user mailing list
>     Lemon-user at lemon.cs.elte.hu <mailto:Lemon-user at lemon.cs.elte.hu>
>     http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
>
>
>
>
> -- 
> Sincerely:
> Song Yongjia(宋永佳)
>
> Department of Industrial and Systems Engineering
> College of Engineering, University of Wisconsin-Madison
> 3241 Mechanical Engineering Building
> 1513 University Avenue, Madison, WI 53706

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lemon.cs.elte.hu/pipermail/lemon-user/attachments/20110104/cc84f317/attachment.html>


More information about the Lemon-user mailing list