COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci/leda/bipartite_matching_leda_gen.cc @ 647:19dd325da0e8

Last change on this file since 647:19dd325da0e8 was 616:31879aac4dc3, checked in by marci, 20 years ago

include -> hugo mods in leda files

File size: 3.6 KB
RevLine 
[446]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>
[616]16#include <hugo/time_measure.h>
[446]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>
[482]21#include <max_flow.h>
[446]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;
50  //lg.make_undirected();
51  typedef LedaGraphWrapper<leda::graph> Graph;
52  Graph g(lg);
53
54  //for UndirListGraph
55  //typedef UndirListGraph Graph;
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  int k;
[447]77  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";
[446]78  std::cout << "number of groups in LEDA random group graph=";
79  std::cin >> k;
[482]80  std::cout << std::endl;
81 
[446]82  leda_list<leda_node> lS;
83  leda_list<leda_node> lT;
84  random_bigraph(lg, a, b, m, lS, lT, k);
85
[482]86  Graph::NodeMap<int> ref_map(g, -1);
87  IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
[446]88
[482]89  //generating leda random group graph
[446]90  leda_node ln;
91  forall(ln, lS) bipartite_map.insert(ln, false);
92  forall(ln, lT) bipartite_map.insert(ln, true);
93
[482]94  //making bipartite graph
[446]95  typedef BipartiteGraphWrapper<Graph> BGW;
96  BGW bgw(g, bipartite_map);
97
98
[482]99  //st-wrapper
[446]100  typedef stGraphWrapper<BGW> stGW;
101  stGW stgw(bgw);
102  ConstMap<stGW::Edge, int> const1map(1);
103  stGW::EdgeMap<int> flow(stgw);
104
105  Timer ts;
[482]106
107  ts.reset();
[446]108  FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
[482]109  MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
110    max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow/*, true*/);
111  max_flow_test.run();
112  std::cout << "HUGO max matching algorithm based on preflow." << std::endl
113            << "Size of matching: "
114            << max_flow_test.flowValue() << std::endl;
115  std::cout << "elapsed time: " << ts << std::endl << std::endl;
[446]116
117  ts.reset(); 
118  leda_list<leda_edge> ml=MAX_CARD_BIPARTITE_MATCHING(lg);
[482]119  std::cout << "LEDA max matching algorithm." << std::endl
120            << "Size of matching: "
121            << ml.size() << std::endl;
[446]122  std::cout << "elapsed time: " << ts << std::endl;
123  std::cout << "\n";
124
[482]125  ts.reset();
[446]126  FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
127  typedef ListGraph MutableGraph;
[482]128  while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { }
129  std::cout << "HUGO max matching algorithm based on blocking flow augmentation."
130            << std::endl << "Matching size: "
131            << max_flow_test.flowValue() << std::endl;
[446]132  std::cout << "elapsed time: " << ts << std::endl;
133
134  return 0;
135}
Note: See TracBrowser for help on using the repository browser.