COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci/leda/bipartite_matching_leda_gen.cc @ 482:dce64ce044d6

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

corrections for leda matching files

File size: 3.5 KB
Line 
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>
10#include <LEDA/graph_gen.h>
11
12#include <leda_graph_wrapper.h>
13#include <list_graph.h>
14//#include <smart_graph.h>
15//#include <dimacs.h>
16#include <time_measure.h>
17#include <for_each_macros.h>
18#include <graph_wrapper.h>
19#include <maps.h>
20#include <max_flow.h>
21
22/**
23 * Inicializalja a veletlenszamgeneratort.
24 * Figyelem, ez nem jo igazi random szamokhoz,
25 * erre ne bizzad a titkaidat!
26 */
27void random_init()
28{
29        unsigned int seed = getpid();
30        seed |= seed << 15;
31        seed ^= time(0);
32
33        srand(seed);
34}
35
36/**
37 * Egy veletlen int-et ad vissza 0 es m-1 kozott.
38 */
39int random(int m)
40{
41  return int( double(m) * rand() / (RAND_MAX + 1.0) );
42}
43
44using namespace hugo;
45
46int main() {
47  //for leda graph
48  leda::graph lg;
49  //lg.make_undirected();
50  typedef LedaGraphWrapper<leda::graph> Graph;
51  Graph g(lg);
52
53  //for UndirListGraph
54  //typedef UndirListGraph Graph;
55  //Graph g;
56
57  typedef Graph::Node Node;
58  typedef Graph::NodeIt NodeIt;
59  typedef Graph::Edge Edge;
60  typedef Graph::EdgeIt EdgeIt;
61  typedef Graph::OutEdgeIt OutEdgeIt;
62
63  std::vector<Graph::Node> s_nodes;
64  std::vector<Graph::Node> t_nodes;
65
66  int a;
67  std::cout << "number of nodes in the first color class=";
68  std::cin >> a;
69  int b;
70  std::cout << "number of nodes in the second color class=";
71  std::cin >> b;
72  int m;
73  std::cout << "number of edges=";
74  std::cin >> m;
75  int k;
76  std::cout << "A bipartite graph is a random group graph if the color classes \nA and B are partitiones to A_0, A_1, ..., A_{k-1} and B_0, B_1, ..., B_{k-1} \nas equally as possible \nand the edges from A_i goes to A_{i-1 mod k} and A_{i+1 mod k}.\n";
77  std::cout << "number of groups in LEDA random group graph=";
78  std::cin >> k;
79  std::cout << std::endl;
80 
81  leda_list<leda_node> lS;
82  leda_list<leda_node> lT;
83  random_bigraph(lg, a, b, m, lS, lT, k);
84
85  Graph::NodeMap<int> ref_map(g, -1);
86  IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
87
88  //generating leda random group graph
89  leda_node ln;
90  forall(ln, lS) bipartite_map.insert(ln, false);
91  forall(ln, lT) bipartite_map.insert(ln, true);
92
93  //making bipartite graph
94  typedef BipartiteGraphWrapper<Graph> BGW;
95  BGW bgw(g, bipartite_map);
96
97
98  //st-wrapper
99  typedef stGraphWrapper<BGW> stGW;
100  stGW stgw(bgw);
101  ConstMap<stGW::Edge, int> const1map(1);
102  stGW::EdgeMap<int> flow(stgw);
103
104  Timer ts;
105
106  ts.reset();
107  FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
108  MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
109    max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow/*, true*/);
110  max_flow_test.run();
111  std::cout << "HUGO max matching algorithm based on preflow." << std::endl
112            << "Size of matching: "
113            << max_flow_test.flowValue() << std::endl;
114  std::cout << "elapsed time: " << ts << std::endl << std::endl;
115
116  ts.reset(); 
117  leda_list<leda_edge> ml=MAX_CARD_BIPARTITE_MATCHING(lg);
118  std::cout << "LEDA max matching algorithm." << std::endl
119            << "Size of matching: "
120            << ml.size() << std::endl;
121  std::cout << "elapsed time: " << ts << std::endl;
122  std::cout << "\n";
123
124  ts.reset();
125  FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
126  typedef ListGraph MutableGraph;
127  while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { }
128  std::cout << "HUGO max matching algorithm based on blocking flow augmentation."
129            << std::endl << "Matching size: "
130            << max_flow_test.flowValue() << std::endl;
131  std::cout << "elapsed time: " << ts << std::endl;
132
133  return 0;
134}
Note: See TracBrowser for help on using the repository browser.