src/work/alpar/dijkstra/dijkstra.cc
author jacint
Wed, 05 May 2004 17:23:04 +0000
changeset 534 22ce98f7d0f1
parent 257 7f832b4e5391
permissions -rw-r--r--
primitive random graph generator
alpar@222
     1
#include <iostream>
alpar@222
     2
#include <fstream>
alpar@222
     3
alpar@222
     4
#include <smart_graph.h>
alpar@222
     5
#include <list_graph.h>
alpar@222
     6
#include <dimacs.h>
alpar@222
     7
#include <dijkstra.h>
alpar@222
     8
#include <time_measure.h>
alpar@222
     9
klao@258
    10
#include <bin_heap.h>
alpar@222
    11
#include <fib_heap.h>
alpar@222
    12
alpar@222
    13
using namespace hugo;
alpar@222
    14
alpar@222
    15
int main(int, char **) {
alpar@222
    16
  typedef SmartGraph::Node Node;
alpar@222
    17
  typedef SmartGraph::NodeIt NodeIt;
alpar@222
    18
  typedef SmartGraph::InEdgeIt InEdgeIt; 
alpar@222
    19
alpar@222
    20
  SmartGraph G;
alpar@222
    21
  Node s, t;
alpar@222
    22
  SmartGraph::EdgeMap<int> cap(G);
alpar@222
    23
  Timer tim;
alpar@222
    24
  std::cout << "DIMACS load ..." << std::endl;
alpar@222
    25
  readDimacsMaxFlow(std::cin, G, s, t, cap);
alpar@222
    26
  std::cout << "               " << tim <<std::endl;
alpar@222
    27
alpar@222
    28
  std::cout << "dijkstra demo ..." << std::endl;
alpar@222
    29
  
alpar@222
    30
  //double pre_time=currTime();
alpar@222
    31
  tim.reset();
alpar@247
    32
//   Dijkstra <SmartGraph,
alpar@247
    33
//     SmartGraph::EdgeMap<int>,
alpar@247
    34
//     FibHeap<SmartGraph::Node, int, SmartGraph::NodeMap<int> >
alpar@247
    35
//     > dijkstra_test(G, cap); 
alpar@247
    36
  
alpar@247
    37
  Dijkstra <SmartGraph, SmartGraph::EdgeMap<int>, FibHeap >
alpar@247
    38
    dijkstra_test(G, cap); 
alpar@222
    39
  
alpar@222
    40
  dijkstra_test.run(s);
alpar@222
    41
  //double post_time=currTime();
alpar@222
    42
  
alpar@222
    43
  std::cout << "running time with fib_heap: " 
alpar@222
    44
    // << post_time-pre_time << " sec"
alpar@222
    45
	    << tim
alpar@222
    46
	    << std::endl; 
alpar@222
    47
 
alpar@222
    48
  //pre_time=currTime();
alpar@222
    49
  tim.reset();
alpar@247
    50
//   Dijkstra < SmartGraph,
alpar@247
    51
//     SmartGraph::EdgeMap<int>,
alpar@247
    52
//     BinHeap<SmartGraph::Node, int, SmartGraph::NodeMap<int> > > 
alpar@247
    53
//     dijkstra_test2(G, cap);
alpar@247
    54
  
alpar@247
    55
  Dijkstra <SmartGraph, SmartGraph::EdgeMap<int>, BinHeap >
alpar@247
    56
    dijkstra_test2(G, cap); 
alpar@222
    57
  
alpar@222
    58
  dijkstra_test2.run(s);
alpar@222
    59
  //post_time=currTime();
alpar@222
    60
  
alpar@222
    61
  std::cout << "running time with bin_heap: " 
alpar@222
    62
    //    << post_time-pre_time << " sec"
alpar@222
    63
	    << tim
alpar@222
    64
	    << std::endl; 
alpar@222
    65
  
alpar@222
    66
alpar@222
    67
  int hiba_fib=0;
alpar@222
    68
  int hiba_bin=0;
alpar@222
    69
  NodeIt u;
alpar@222
    70
  for ( G.first(u) ; G.valid(u); G.next(u) ) {
alpar@222
    71
    InEdgeIt e;
alpar@222
    72
    for ( G.first(e,u); G.valid(e); G.next(e) ) {
alpar@222
    73
      Node v=G.tail(e);
alpar@222
    74
      if ( dijkstra_test.dist(u) - dijkstra_test.dist(v) > cap[e] )
alpar@222
    75
	{
alpar@222
    76
	  std::cout<<"Hibas el a fibonaccis Dijkstraban: " 
alpar@222
    77
		   << dijkstra_test.dist(u) - dijkstra_test.dist(v) - 
alpar@222
    78
	    cap[e]<<std::endl;
alpar@222
    79
	  ++hiba_fib;
alpar@222
    80
	}
alpar@222
    81
      if ( dijkstra_test2.dist(u) - dijkstra_test2.dist(v) > cap[e] )
alpar@222
    82
	{
alpar@222
    83
	  std::cout<<"Hibas el a binarisos Dijkstraban: " 
alpar@222
    84
		   << dijkstra_test2.dist(u) - dijkstra_test2.dist(v) - 
alpar@222
    85
	    cap[e]<<std::endl;
alpar@222
    86
	  ++hiba_bin;
alpar@222
    87
	}
alpar@222
    88
      if ( e==dijkstra_test.pred(u) && 
alpar@222
    89
	   dijkstra_test.dist(u) - dijkstra_test.dist(v) != cap[e] )
alpar@222
    90
	{
alpar@222
    91
	  std::cout<<"Hibas fael a fibonaccis Dijkstraban: "<<
alpar@222
    92
	    dijkstra_test.dist(u) - dijkstra_test.dist(v)- cap[e]<<std::endl;
alpar@222
    93
	  ++hiba_fib;
alpar@222
    94
	}
alpar@222
    95
      if ( e==dijkstra_test2.pred(u) && 
alpar@222
    96
	   dijkstra_test2.dist(u) - dijkstra_test2.dist(v) != cap[e] )
alpar@222
    97
	{
alpar@222
    98
	  std::cout<<"Hibas fael a binarisos Dijkstraban: "<<
alpar@222
    99
	    dijkstra_test2.dist(u) - dijkstra_test2.dist(v)- cap[e]<<std::endl;
alpar@222
   100
	  ++hiba_bin;
alpar@222
   101
	}
alpar@222
   102
    }
alpar@222
   103
 
alpar@222
   104
    if ( dijkstra_test.dist(u) != dijkstra_test2.dist(u) ) 
alpar@222
   105
      std::cout << "Nem egyezik meg a tavolsag!"<<std::endl;
alpar@222
   106
alpar@222
   107
alpar@222
   108
 }
alpar@222
   109
alpar@222
   110
  std::cout << "Hibas elek szama a fibonaccis Dijkstraban: " 
alpar@222
   111
	    << hiba_fib << " a " << G.edgeNum() <<"-bol."<< std::endl;
alpar@222
   112
  
alpar@222
   113
  std::cout << "Hibas elek szama a binarisos Dijkstraban: " 
alpar@222
   114
	    << hiba_bin << " a " << G.edgeNum() <<"-bol."<< std::endl;
alpar@222
   115
  
alpar@222
   116
  return 0;
alpar@222
   117
}