1 #include <iostream> |
1 #include <iostream> |
2 #include <fstream> |
2 #include <fstream> |
3 |
3 |
4 #include <list_graph.hh> |
4 #include <smart_graph.h> |
5 #include <dimacs.hh> |
5 #include <list_graph.h> |
|
6 #include <dimacs.h> |
6 #include <dijkstra.h> |
7 #include <dijkstra.h> |
7 #include <time_measure.h> |
8 #include <time_measure.h> |
8 |
9 |
9 #include <bin_heap.hh> |
10 #include <bin_heap.hh> |
10 #include <fib_heap.h> |
11 #include <fib_heap.h> |
11 |
12 |
12 using namespace hugo; |
13 using namespace hugo; |
13 |
14 |
14 int main(int, char **) { |
15 int main(int, char **) { |
15 typedef ListGraph::NodeIt NodeIt; |
16 typedef SmartGraph::Node Node; |
16 typedef ListGraph::EachNodeIt EachNodeIt; |
17 typedef SmartGraph::NodeIt NodeIt; |
17 typedef ListGraph::InEdgeIt InEdgeIt; |
18 typedef SmartGraph::InEdgeIt InEdgeIt; |
18 |
19 |
19 ListGraph G; |
20 SmartGraph G; |
20 NodeIt s, t; |
21 Node s, t; |
21 ListGraph::EdgeMap<int> cap(G); |
22 SmartGraph::EdgeMap<int> cap(G); |
22 readDimacsMaxFlow(std::cin, G, s, t, cap); |
23 readDimacsMaxFlow(std::cin, G, s, t, cap); |
23 |
24 |
24 std::cout << "dijkstra demo ..." << std::endl; |
25 std::cout << "dijkstra demo ..." << std::endl; |
25 |
26 |
26 double pre_time=currTime(); |
27 double pre_time=currTime(); |
27 Dijkstra<ListGraph, int, FibHeap<ListGraph::NodeIt, int, |
28 Dijkstra<SmartGraph, int, FibHeap<SmartGraph::Node, int, |
28 ListGraph::NodeMap<int> > > dijkstra_test(G, s, cap); |
29 SmartGraph::NodeMap<int> > > dijkstra_test(G, cap); |
29 dijkstra_test.run(); |
30 dijkstra_test.run(s); |
30 double post_time=currTime(); |
31 double post_time=currTime(); |
31 |
32 |
32 std::cout << "running time with fib_heap: " |
33 std::cout << "running time with fib_heap: " |
33 << post_time-pre_time << " sec"<< std::endl; |
34 << post_time-pre_time << " sec"<< std::endl; |
34 |
35 |
35 pre_time=currTime(); |
36 pre_time=currTime(); |
36 Dijkstra<ListGraph, int, BinHeap<ListGraph::NodeIt, int, |
37 Dijkstra<SmartGraph, int, BinHeap<SmartGraph::Node, int, |
37 ListGraph::NodeMap<int> > > dijkstra_test2(G, s, cap); |
38 SmartGraph::NodeMap<int> > > dijkstra_test2(G, cap); |
38 dijkstra_test2.run(); |
39 dijkstra_test2.run(s); |
39 post_time=currTime(); |
40 post_time=currTime(); |
40 |
41 |
41 std::cout << "running time with bin_heap: " |
42 std::cout << "running time with bin_heap: " |
42 << post_time-pre_time << " sec"<< std::endl; |
43 << post_time-pre_time << " sec"<< std::endl; |
43 |
44 |
44 |
45 |
45 int hiba_fib=0; |
46 int hiba_fib=0; |
46 int hiba_bin=0; |
47 int hiba_bin=0; |
47 EachNodeIt u; |
48 NodeIt u; |
48 for ( G.getFirst(u) ; G.valid(u); G.next(u) ) { |
49 for ( G.first(u) ; G.valid(u); G.next(u) ) { |
49 InEdgeIt e; |
50 InEdgeIt e; |
50 for ( G.getFirst(e,u); G.valid(e); G.next(e) ) { |
51 for ( G.first(e,u); G.valid(e); G.next(e) ) { |
51 NodeIt v=G.tail(e); |
52 Node v=G.tail(e); |
52 if ( dijkstra_test.dist(u) - dijkstra_test.dist(v) > cap.get(e) ) |
53 if ( dijkstra_test.dist(u) - dijkstra_test.dist(v) > cap.get(e) ) |
53 { |
54 { |
54 std::cout<<"Hibas el a fibonaccis Dijkstraban: " |
55 std::cout<<"Hibas el a fibonaccis Dijkstraban: " |
55 << dijkstra_test.dist(u) - dijkstra_test.dist(v) - |
56 << dijkstra_test.dist(u) - dijkstra_test.dist(v) - |
56 cap.get(e)<<std::endl; |
57 cap.get(e)<<std::endl; |