Last change on this file since 1418:afaa773d0ad0 was 1182:a1abe9452199, checked in by athos, 17 years ago

Added two demo programs: of course they are not considered to be complete or finished in any sense.

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