7 #include <LEDA/graph.h>
8 #include <LEDA/mcb_matching.h>
10 #include <LEDA/graph_gen.h>
12 #include <leda_graph_wrapper.h>
13 #include <sage_graph.h>
14 //#include <smart_graph.h>
16 #include <lemon/time_measure.h>
17 #include <for_each_macros.h>
18 #include <lemon/graph_wrapper.h>
19 #include <bipartite_graph_wrapper.h>
20 #include <lemon/maps.h>
21 #include <lemon/max_flow.h>
24 * Inicializalja a veletlenszamgeneratort.
25 * Figyelem, ez nem jo igazi random szamokhoz,
26 * erre ne bizzad a titkaidat!
30 unsigned int seed = getpid();
38 * Egy veletlen int-et ad vissza 0 es m-1 kozott.
42 return int( double(m) * rand() / (RAND_MAX + 1.0) );
45 using namespace lemon;
50 //lg.make_undirected();
51 typedef LedaGraphWrapper<leda::graph> Graph;
55 //typedef UndirSageGraph Graph;
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;
64 std::vector<Graph::Node> s_nodes;
65 std::vector<Graph::Node> t_nodes;
68 std::cout << "number of nodes in the first color class=";
71 std::cout << "number of nodes in the second color class=";
74 std::cout << "number of edges=";
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());
82 for(int i=0; i<m; ++i) {
83 g.addEdge(s_nodes[random(a)], t_nodes[random(b)]);
86 Graph::NodeMap<int> ref_map(g, -1);
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);
92 typedef BipartiteGraphWrapper<Graph> BGW;
93 BGW bgw(g, bipartite_map);
95 BGW::NodeMap<int> dbyj(bgw);
96 BGW::EdgeMap<int> dbyxcj(bgw);
98 typedef stBipartiteGraphWrapper<BGW> stGW;
100 ConstMap<stGW::Edge, int> const1map(1);
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);
108 FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
109 // while (max_flow_test.augmentOnShortestPath()) { }
110 typedef SageGraph MutableGraph;
111 // while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
112 // while (max_flow_test.augmentOnBlockingFlow2()) {
113 // std::cout << max_flow_test.flowValue() << std::endl;
116 std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl;
117 std::cout << "elapsed time: " << ts << std::endl;
120 FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
122 std::cout << "pre flow value: " << max_flow_test.flowValue() << std::endl;
123 std::cout << "elapsed time: " << ts << std::endl;
126 leda_list<leda_edge> ml=MAX_CARD_BIPARTITE_MATCHING(lg);
127 std::cout << "leda matching value: " << ml.size() << std::endl;
128 std::cout << "elapsed time: " << ts << std::endl;