Last change on this file since 1553:434f9add42cd was 1530:d99c3c84f797, checked in by athos, 19 years ago

Doc.

File size: 1.7 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 << "This program is a simple demo of the LEMON Dijkstra class."<<std::endl;
48    std::cout << "We calculate the shortest path from node s to node t in a graph."<<std::endl;
49    std::cout <<std::endl;
50
51
52    std::cout << "The id of s is " << g.id(s)<< ", the id of t is " << g.id(t)<<"."<<std::endl;
53
54    std::cout << "Dijkstra algorithm test..." << std::endl;
55
56
57    Dijkstra<Graph, LengthMap> dijkstra_test(g,len);
58
59    dijkstra_test.run(s);
60
61
62    std::cout << "The distance of node t from node s: " << dijkstra_test.dist(t)<<std::endl;
63
64    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;
65
66    for (Node v=t;v != s; v=dijkstra_test.predNode(v)){
67        std::cout << g.id(v) << "<-";
68    }
69    std::cout << g.id(s) << std::endl;
70
71
72    return 0;
73}
74
75
76
77
78
79
80
81
82
Note: See TracBrowser for help on using the repository browser.