leda-hugo matching alg osszehasonlito
authorjacint
Fri, 07 May 2004 21:16:26 +0000
changeset 58126e1cd224bdc
parent 580 a00f9f1cfab8
child 582 04cd483c2dbc
leda-hugo matching alg osszehasonlito
src/work/jacint/ledacomp.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/jacint/ledacomp.cc	Fri May 07 21:16:26 2004 +0000
     1.3 @@ -0,0 +1,117 @@
     1.4 +// -*- c++ -*-
     1.5 +#include <iostream>
     1.6 +#include <fstream>
     1.7 +#include <vector>
     1.8 +#include <cstdlib>
     1.9 +
    1.10 +#include <LEDA/graph.h>
    1.11 +#include <LEDA/mc_matching.h>
    1.12 +#include <LEDA/list.h>
    1.13 +#include <LEDA/graph_gen.h>
    1.14 +
    1.15 +#include <leda_graph_wrapper.h>
    1.16 +#include <list_graph.h>
    1.17 +#include <dimacs.h>
    1.18 +#include <time_measure.h>
    1.19 +#include <for_each_macros.h>
    1.20 +#include <graph_wrapper.h>
    1.21 +#include <bipartite_graph_wrapper.h>
    1.22 +#include <maps.h>
    1.23 +#include <max_matching.h>
    1.24 +
    1.25 +// /**
    1.26 +//  * Inicializalja a veletlenszamgeneratort.
    1.27 +//  * Figyelem, ez nem jo igazi random szamokhoz,
    1.28 +//  * erre ne bizzad a titkaidat!
    1.29 +//  */
    1.30 +// void random_init()
    1.31 +// {
    1.32 +// 	unsigned int seed = getpid();
    1.33 +// 	seed |= seed << 15;
    1.34 +// 	seed ^= time(0);
    1.35 +
    1.36 +// 	srand(seed);
    1.37 +// }
    1.38 +
    1.39 +// /**
    1.40 +//  * Egy veletlen int-et ad vissza 0 es m-1 kozott.
    1.41 +//  */
    1.42 +// int random(int m)
    1.43 +// {
    1.44 +//   return int( double(m) * rand() / (RAND_MAX + 1.0) );
    1.45 +// }
    1.46 +
    1.47 +using namespace hugo;
    1.48 +
    1.49 +int main() {
    1.50 +
    1.51 +  //for leda graph
    1.52 +  leda::graph lg;
    1.53 +  //lg.make_undirected();
    1.54 +  typedef LedaGraphWrapper<leda::graph> Graph;
    1.55 +  Graph g(lg);
    1.56 +
    1.57 +  //for UndirListGraph
    1.58 +  //typedef UndirListGraph Graph; 
    1.59 +  //Graph g;
    1.60 +
    1.61 +  typedef Graph::Node Node;
    1.62 +  typedef Graph::NodeIt NodeIt;
    1.63 +  typedef Graph::Edge Edge;
    1.64 +  typedef Graph::EdgeIt EdgeIt;
    1.65 +  typedef Graph::OutEdgeIt OutEdgeIt;
    1.66 +
    1.67 +  std::vector<Graph::Node> s_nodes;
    1.68 +  std::vector<Graph::Node> t_nodes;
    1.69 +
    1.70 +  int n;
    1.71 +  std::cout << "Number of nodes=";
    1.72 +  std::cin >> n; 
    1.73 +  int m;
    1.74 +  std::cout << "number of edges=";
    1.75 +  std::cin >> m; 
    1.76 +  std::cout << std::endl;
    1.77 +  
    1.78 +  random_graph(lg, n, m);
    1.79 +
    1.80 +  Timer ts;
    1.81 +
    1.82 +  //  writeDimacs(std::cout, g); //for check
    1.83 +
    1.84 +  MaxMatching<Graph> max_matching(g);
    1.85 +  std::cout << 
    1.86 +    "Running the edmonds algorithm run()... " 
    1.87 +	    <<std::endl;
    1.88 +  ts.reset();  
    1.89 +  max_matching.run();
    1.90 +  std::cout<<"Elapsed time: "<<ts<<std::endl;
    1.91 +  int s=0;
    1.92 +  Graph::NodeMap<Node> mate(g,INVALID);
    1.93 +  max_matching.writeNMapNode(mate);
    1.94 +  NodeIt v;
    1.95 +  for(g.first(v); g.valid(v); g.next(v) ) {
    1.96 +    if ( g.valid(mate[v]) ) {
    1.97 +      ++s;
    1.98 +    }
    1.99 +  }
   1.100 +  int size=(int)s/2;  //size will be used as the size of a maxmatching
   1.101 +  std::cout << size << " is the size of the matching found by run(),"<<std::endl;
   1.102 +  if ( size == max_matching.size() ) {
   1.103 +    std::cout<< "which equals to the size of the actual matching reported by size().\n"<< std::endl;
   1.104 +  } else {  
   1.105 +    std::cout<< "which does not equal to the size of the actual matching reported by size()!\n"<< std::endl;
   1.106 +  }
   1.107 +
   1.108 +
   1.109 +
   1.110 +
   1.111 +  ts.reset();  
   1.112 +  leda_list<leda_edge> ml=MAX_CARD_MATCHING(lg);
   1.113 +  std::cout << "LEDA max matching algorithm." << std::endl 
   1.114 +	    << "Size of matching: " 
   1.115 +	    << ml.size() << std::endl;
   1.116 +  std::cout << "elapsed time: " << ts << std::endl;
   1.117 +  std::cout << "\n";
   1.118 +
   1.119 +  return 0;
   1.120 +}