1.1 --- a/src/work/marci/leda/bipartite_matching_leda.cc Sun Apr 17 18:57:22 2005 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,131 +0,0 @@
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/mcb_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 <sage_graph.h>
1.17 -//#include <smart_graph.h>
1.18 -//#include <dimacs.h>
1.19 -#include <lemon/time_measure.h>
1.20 -#include <for_each_macros.h>
1.21 -#include <lemon/graph_wrapper.h>
1.22 -#include <bipartite_graph_wrapper.h>
1.23 -#include <lemon/maps.h>
1.24 -#include <lemon/max_flow.h>
1.25 -
1.26 -/**
1.27 - * Inicializalja a veletlenszamgeneratort.
1.28 - * Figyelem, ez nem jo igazi random szamokhoz,
1.29 - * erre ne bizzad a titkaidat!
1.30 - */
1.31 -void random_init()
1.32 -{
1.33 - unsigned int seed = getpid();
1.34 - seed |= seed << 15;
1.35 - seed ^= time(0);
1.36 -
1.37 - srand(seed);
1.38 -}
1.39 -
1.40 -/**
1.41 - * Egy veletlen int-et ad vissza 0 es m-1 kozott.
1.42 - */
1.43 -int random(int m)
1.44 -{
1.45 - return int( double(m) * rand() / (RAND_MAX + 1.0) );
1.46 -}
1.47 -
1.48 -using namespace lemon;
1.49 -
1.50 -int main() {
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 UndirSageGraph
1.58 - //typedef UndirSageGraph 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 a;
1.71 - std::cout << "number of nodes in the first color class=";
1.72 - std::cin >> a;
1.73 - int b;
1.74 - std::cout << "number of nodes in the second color class=";
1.75 - std::cin >> b;
1.76 - int m;
1.77 - std::cout << "number of edges=";
1.78 - std::cin >> m;
1.79 -
1.80 -
1.81 - for (int i=0; i<a; ++i) s_nodes.push_back(g.addNode());
1.82 - for (int i=0; i<b; ++i) t_nodes.push_back(g.addNode());
1.83 -
1.84 - random_init();
1.85 - for(int i=0; i<m; ++i) {
1.86 - g.addEdge(s_nodes[random(a)], t_nodes[random(b)]);
1.87 - }
1.88 -
1.89 - Graph::NodeMap<int> ref_map(g, -1);
1.90 -
1.91 - IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
1.92 - for (int i=0; i<a; ++i) bipartite_map.insert(s_nodes[i], false);
1.93 - for (int i=0; i<b; ++i) bipartite_map.insert(t_nodes[i], true);
1.94 -
1.95 - typedef BipartiteGraphWrapper<Graph> BGW;
1.96 - BGW bgw(g, bipartite_map);
1.97 -
1.98 - BGW::NodeMap<int> dbyj(bgw);
1.99 - BGW::EdgeMap<int> dbyxcj(bgw);
1.100 -
1.101 - typedef stBipartiteGraphWrapper<BGW> stGW;
1.102 - stGW stgw(bgw);
1.103 - ConstMap<stGW::Edge, int> const1map(1);
1.104 -
1.105 - Timer ts;
1.106 - stGW::EdgeMap<int> flow(stgw);
1.107 - MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
1.108 - max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
1.109 -
1.110 - ts.reset();
1.111 - FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
1.112 -// while (max_flow_test.augmentOnShortestPath()) { }
1.113 - typedef SageGraph MutableGraph;
1.114 -// while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
1.115 -// while (max_flow_test.augmentOnBlockingFlow2()) {
1.116 -// std::cout << max_flow_test.flowValue() << std::endl;
1.117 -// }
1.118 - max_flow_test.run();
1.119 - std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl;
1.120 - std::cout << "elapsed time: " << ts << std::endl;
1.121 -
1.122 - ts.reset();
1.123 - FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
1.124 - max_flow_test.run();
1.125 - std::cout << "pre flow value: " << max_flow_test.flowValue() << std::endl;
1.126 - std::cout << "elapsed time: " << ts << std::endl;
1.127 -
1.128 - ts.reset();
1.129 - leda_list<leda_edge> ml=MAX_CARD_BIPARTITE_MATCHING(lg);
1.130 - std::cout << "leda matching value: " << ml.size() << std::endl;
1.131 - std::cout << "elapsed time: " << ts << std::endl;
1.132 -
1.133 - return 0;
1.134 -}