source:lemon-0.x/demo/dijkstra_demo.cc@1528:1aa71600000c

Last change on this file since 1528:1aa71600000c was 1528:1aa71600000c, checked in by athos, 18 years ago

Graph input-output demo, some documentation.

File size: 1.5 KB
Line
1#include <iostream>
2
3#include <lemon/list_graph.h>
4#include <lemon/dijkstra.h>
5//#include <lemon/graph_writer.h>
6
7using namespace lemon;
8
9
10int main (int, char*[])
11{
12
13    typedef ListGraph Graph;
14    typedef Graph::Node Node;
15    typedef Graph::Edge Edge;
16    typedef Graph::EdgeMap<int> LengthMap;
17
18    Graph g;
19
20    //An example from Ahuja's book
21
28
36
37    LengthMap len(g);
38
39    len.set(s_v2, 10);
40    len.set(s_v3, 10);
41    len.set(v2_v4, 5);
42    len.set(v2_v5, 8);
43    len.set(v3_v5, 5);
44    len.set(v4_t, 8);
45    len.set(v5_t, 8);
46
47    std::cout << "The id of s is " << g.id(s)<< ", the id of t is " << g.id(t)<<"."<<std::endl;
48
49    std::cout << "Dijkstra algorithm test..." << std::endl;
50
51
52    Dijkstra<Graph, LengthMap> dijkstra_test(g,len);
53
54    dijkstra_test.run(s);
55
56
57    std::cout << "The distance of node t from node s: " << dijkstra_test.dist(t)<<std::endl;
58
59    std::cout << "The shortest path from s to t goes through the following nodes (the first one is t, the last one is s): "<<std::endl;
60
61    for (Node v=t;v != s; v=dijkstra_test.predNode(v)){
62        std::cout << g.id(v) << "<-";
63    }
64    std::cout << g.id(s) << std::endl;
65
66
67    return 0;
68}
69
70
71
72
73
74
75
76
77
Note: See TracBrowser for help on using the repository browser.