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