COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci/leda/bipartite_matching_leda.cc @ 769:eb61fbc64c16

Last change on this file since 769:eb61fbc64c16 was 769:eb61fbc64c16, checked in by marci, 20 years ago

.

File size: 3.3 KB
RevLine 
[411]1// -*- c++ -*-
2#include <iostream>
3#include <fstream>
4#include <vector>
5#include <cstdlib>
6
7#include <LEDA/graph.h>
8#include <LEDA/mcb_matching.h>
9#include <LEDA/list.h>
[446]10#include <LEDA/graph_gen.h>
[411]11
12#include <leda_graph_wrapper.h>
[648]13#include <sage_graph.h>
[411]14//#include <smart_graph.h>
15//#include <dimacs.h>
[616]16#include <hugo/time_measure.h>
[769]17#include <for_each_macros.h>
[616]18#include <hugo/graph_wrapper.h>
[496]19#include <bipartite_graph_wrapper.h>
[616]20#include <hugo/maps.h>
[769]21#include <hugo/max_flow.h>
[411]22
23/**
24 * Inicializalja a veletlenszamgeneratort.
25 * Figyelem, ez nem jo igazi random szamokhoz,
26 * erre ne bizzad a titkaidat!
27 */
28void random_init()
29{
30        unsigned int seed = getpid();
31        seed |= seed << 15;
32        seed ^= time(0);
33
34        srand(seed);
35}
36
37/**
38 * Egy veletlen int-et ad vissza 0 es m-1 kozott.
39 */
40int random(int m)
41{
42  return int( double(m) * rand() / (RAND_MAX + 1.0) );
43}
44
45using namespace hugo;
46
47int main() {
48  //for leda graph
49  leda::graph lg;
[413]50  //lg.make_undirected();
[411]51  typedef LedaGraphWrapper<leda::graph> Graph;
52  Graph g(lg);
53
[648]54  //for UndirSageGraph
55  //typedef UndirSageGraph Graph;
[411]56  //Graph g;
57
58  typedef Graph::Node Node;
59  typedef Graph::NodeIt NodeIt;
60  typedef Graph::Edge Edge;
61  typedef Graph::EdgeIt EdgeIt;
62  typedef Graph::OutEdgeIt OutEdgeIt;
63
64  std::vector<Graph::Node> s_nodes;
65  std::vector<Graph::Node> t_nodes;
66
67  int a;
68  std::cout << "number of nodes in the first color class=";
69  std::cin >> a;
70  int b;
71  std::cout << "number of nodes in the second color class=";
72  std::cin >> b;
73  int m;
74  std::cout << "number of edges=";
75  std::cin >> m;
76 
77
78  for (int i=0; i<a; ++i) s_nodes.push_back(g.addNode());
79  for (int i=0; i<b; ++i) t_nodes.push_back(g.addNode());
80
81  random_init();
82  for(int i=0; i<m; ++i) {
83    g.addEdge(s_nodes[random(a)], t_nodes[random(b)]);
84  }
85
86  Graph::NodeMap<int> ref_map(g, -1);
87
88  IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
89  for (int i=0; i<a; ++i) bipartite_map.insert(s_nodes[i], false);
90  for (int i=0; i<b; ++i) bipartite_map.insert(t_nodes[i], true);
91
92  typedef BipartiteGraphWrapper<Graph> BGW;
93  BGW bgw(g, bipartite_map);
94
95  BGW::NodeMap<int> dbyj(bgw);
96  BGW::EdgeMap<int> dbyxcj(bgw);
97
[769]98  typedef stBipartiteGraphWrapper<BGW> stGW;
[411]99  stGW stgw(bgw);
100  ConstMap<stGW::Edge, int> const1map(1);
101
102  Timer ts;
[482]103  stGW::EdgeMap<int> flow(stgw);
104  MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
105    max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
106
[411]107  ts.reset();
[482]108  FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
[411]109//  while (max_flow_test.augmentOnShortestPath()) { }
[648]110  typedef SageGraph MutableGraph;
[411]111//  while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
[769]112//   while (max_flow_test.augmentOnBlockingFlow2()) {
113//    std::cout << max_flow_test.flowValue() << std::endl;
114//   }
115  max_flow_test.run();
[411]116  std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl;
117  std::cout << "elapsed time: " << ts << std::endl;
118
119  ts.reset();
[482]120  FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
121  max_flow_test.run();
[411]122  std::cout << "pre flow value: " << max_flow_test.flowValue() << std::endl;
123  std::cout << "elapsed time: " << ts << std::endl;
124
125  ts.reset(); 
[413]126  leda_list<leda_edge> ml=MAX_CARD_BIPARTITE_MATCHING(lg);
127  std::cout << "leda matching value: " << ml.size() << std::endl;
[411]128  std::cout << "elapsed time: " << ts << std::endl;
129
130  return 0;
131}
Note: See TracBrowser for help on using the repository browser.