[159] | 1 | #include <iostream> |
---|
[160] | 2 | #include <fstream> |
---|
[159] | 3 | |
---|
| 4 | #include <list_graph.hh> |
---|
[160] | 5 | #include <dimacs.hh> |
---|
[159] | 6 | #include <dijkstra.h> |
---|
[160] | 7 | #include <time_measure.h> |
---|
[159] | 8 | |
---|
[170] | 9 | #include <bin_heap.hh> |
---|
| 10 | #include <fib_heap.h> |
---|
| 11 | |
---|
[159] | 12 | using namespace hugo; |
---|
| 13 | |
---|
[160] | 14 | int main(int, char **) { |
---|
[159] | 15 | typedef ListGraph::NodeIt NodeIt; |
---|
[170] | 16 | typedef ListGraph::EachNodeIt EachNodeIt; |
---|
| 17 | typedef ListGraph::InEdgeIt InEdgeIt; |
---|
[160] | 18 | |
---|
| 19 | ListGraph G; |
---|
| 20 | NodeIt s, t; |
---|
| 21 | ListGraph::EdgeMap<int> cap(G); |
---|
| 22 | readDimacsMaxFlow(std::cin, G, s, t, cap); |
---|
| 23 | |
---|
| 24 | std::cout << "dijkstra demo ..." << std::endl; |
---|
[159] | 25 | |
---|
[160] | 26 | double pre_time=currTime(); |
---|
[170] | 27 | Dijkstra<ListGraph, int, FibHeap<ListGraph::NodeIt, int, |
---|
| 28 | ListGraph::NodeMap<int> > > dijkstra_test(G, s, cap); |
---|
[167] | 29 | dijkstra_test.run(); |
---|
[160] | 30 | double post_time=currTime(); |
---|
| 31 | |
---|
[170] | 32 | std::cout << "running time with fib_heap: " |
---|
| 33 | << post_time-pre_time << " sec"<< std::endl; |
---|
[159] | 34 | |
---|
[170] | 35 | pre_time=currTime(); |
---|
| 36 | Dijkstra<ListGraph, int, BinHeap<ListGraph::NodeIt, int, |
---|
| 37 | ListGraph::NodeMap<int> > > dijkstra_test2(G, s, cap); |
---|
| 38 | dijkstra_test2.run(); |
---|
| 39 | post_time=currTime(); |
---|
| 40 | |
---|
| 41 | std::cout << "running time with bin_heap: " |
---|
| 42 | << post_time-pre_time << " sec"<< std::endl; |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | int hiba_fib=0; |
---|
| 46 | int hiba_bin=0; |
---|
| 47 | EachNodeIt u; |
---|
| 48 | for ( G.getFirst(u) ; G.valid(u); G.next(u) ) { |
---|
| 49 | InEdgeIt e; |
---|
| 50 | for ( G.getFirst(e,u); G.valid(e); G.next(e) ) { |
---|
| 51 | NodeIt v=G.tail(e); |
---|
| 52 | if ( dijkstra_test.dist(u) - dijkstra_test.dist(v) > cap.get(e) ) |
---|
| 53 | { |
---|
| 54 | std::cout<<"Hibas el a fibonaccis Dijkstraban: " |
---|
| 55 | << dijkstra_test.dist(u) - dijkstra_test.dist(v) - |
---|
| 56 | cap.get(e)<<std::endl; |
---|
| 57 | ++hiba_fib; |
---|
| 58 | } |
---|
| 59 | if ( dijkstra_test2.dist(u) - dijkstra_test2.dist(v) > cap.get(e) ) |
---|
| 60 | { |
---|
| 61 | std::cout<<"Hibas el a binarisos Dijkstraban: " |
---|
| 62 | << dijkstra_test2.dist(u) - dijkstra_test2.dist(v) - |
---|
| 63 | cap.get(e)<<std::endl; |
---|
| 64 | ++hiba_bin; |
---|
| 65 | } |
---|
| 66 | if ( e==dijkstra_test.pred(u) && |
---|
| 67 | dijkstra_test.dist(u) - dijkstra_test.dist(v) != cap.get(e) ) |
---|
| 68 | { |
---|
[173] | 69 | std::cout<<"Hibas fael a fibonaccis Dijkstraban: "<< |
---|
| 70 | dijkstra_test.dist(u) - dijkstra_test.dist(v)- cap.get(e)<<std::endl; |
---|
[170] | 71 | ++hiba_fib; |
---|
| 72 | } |
---|
| 73 | if ( e==dijkstra_test2.pred(u) && |
---|
| 74 | dijkstra_test2.dist(u) - dijkstra_test2.dist(v) != cap.get(e) ) |
---|
| 75 | { |
---|
[173] | 76 | std::cout<<"Hibas fael a binarisos Dijkstraban: "<< |
---|
| 77 | dijkstra_test2.dist(u) - dijkstra_test2.dist(v)- cap.get(e)<<std::endl; |
---|
[170] | 78 | ++hiba_bin; |
---|
| 79 | } |
---|
[167] | 80 | } |
---|
[173] | 81 | |
---|
| 82 | if ( dijkstra_test.dist(u) != dijkstra_test2.dist(u) ) |
---|
| 83 | std::cout << "Nem egyezik meg a tavolsag!"<<std::endl; |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | } |
---|
[159] | 87 | |
---|
[170] | 88 | std::cout << "Hibas elek szama a fibonaccis Dijkstraban: " |
---|
| 89 | << hiba_fib << " a " << G.edgeNum() <<"-bol."<< std::endl; |
---|
| 90 | |
---|
| 91 | std::cout << "Hibas elek szama a binarisos Dijkstraban: " |
---|
| 92 | << hiba_bin << " a " << G.edgeNum() <<"-bol."<< std::endl; |
---|
[167] | 93 | |
---|
[173] | 94 | |
---|
| 95 | |
---|
| 96 | |
---|
[159] | 97 | return 0; |
---|
| 98 | } |
---|