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

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


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
> http://lemon.cs.elte.hu/mailman/listinfo/lemon-user

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


More information about the Lemon-user mailing list