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