Solve conflict.
7 #include <LEDA/graph.h>
8 #include <LEDA/mcb_matching.h>
11 #include <leda_graph_wrapper.h>
12 #include <sage_graph.h>
14 #include <time_measure.h>
15 #include <edmonds_karp.h>
18 * Inicializalja a veletlenszamgeneratort.
19 * Figyelem, ez nem jo igazi random szamokhoz,
20 * erre ne bizzad a titkaidat!
24 unsigned int seed = getpid();
32 * Egy veletlen int-et ad vissza 0 es m-1 kozott.
36 return int( double(m) * rand() / (RAND_MAX + 1.0) );
39 using namespace lemon;
47 typedef LedaGraphWrapper<leda::graph> Graph;
49 // typedef ListGraph Graph;
52 typedef Graph::Node Node;
53 typedef Graph::NodeIt NodeIt;
54 typedef Graph::Edge Edge;
55 typedef Graph::EdgeIt EdgeIt;
56 typedef Graph::OutEdgeIt OutEdgeIt;
57 typedef Graph::InEdgeIt InEdgeIt;
60 //Graph::EdgeMap<int> cap(G);
61 //readDimacsMaxFlow(std::cin, G, s, t, cap);
62 std::vector<Node> s_nodes;
63 std::vector<Node> t_nodes;
66 cout << "number of nodes in the first color class=";
69 cout << "number of nodes in the second color class=";
72 cout << "number of edges=";
75 for(int i=0; i<a; ++i) {
76 s_nodes.push_back(G.addNode());
78 for(int i=0; i<a; ++i) {
79 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 // G.addEdge(s_nodes[1], t_nodes[5-4]);
87 // G.addEdge(s_nodes[1], t_nodes[5-4]);
88 // G.addEdge(s_nodes[1], t_nodes[4-4]);
89 // G.addEdge(s_nodes[1], t_nodes[4-4]);
90 // G.addEdge(s_nodes[2], t_nodes[4-4]);
91 // G.addEdge(s_nodes[3], t_nodes[4-4]);
93 leda_list<leda_node> A;
94 leda_list<leda_node> B;
95 Graph::NodeMap<bool> s_map(G); //false
96 Graph::NodeMap<bool> t_map(G); //false
98 for(int i=0; i<a; ++i) { s_map.set(s_nodes[i], true); A+=s_nodes[i]; }
99 for(int i=0; i<b; ++i) { t_map.set(t_nodes[i], true); B+=t_nodes[i]; }
101 // cout << "bfs and dfs iterator demo on the directed graph" << endl;
102 // for(NodeIt n=G.first<NodeIt>(); G.valid(n); G.next(n)) {
103 // cout << G.id(n) << ": ";
104 // cout << "out edges: ";
105 // for(OutEdgeIt e=G.first<OutEdgeIt>(n); G.valid(e); G.next(e))
106 // cout << G.id(G.source(e)) << "->" << G.id(G.target(e)) << " ";
107 // cout << "in edges: ";
108 // for(InEdgeIt e=G.first<InEdgeIt>(n); G.valid(e); G.next(e))
109 // cout << G.id(G.source(e)) << "->" << G.id(G.target(e)) << " ";
115 std::cout << "on-the-fly max bipartite matching (Edmonds-Karp) demo on wrapped leda graph..." << std::endl;
116 Graph::EdgeMap<int> flow(G); //0 flow
117 Graph::EdgeMap<int> cap(G, 1);
122 MaxMatching<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s_map, t_map, flow, cap);
124 while (max_flow_test.augmentOnShortestPath()) {
125 // for(EdgeIt e=G.first<EdgeIt>(); G.valid(e); G.next(e))
126 // std::cout << G.id(G.source(e)) << "-" << flow.get(e) << "->" << G.id(G.target(e)) << " ";
127 // std::cout<<std::endl;
131 // std::cout << "maximum matching: "<< std::endl;
132 // for(EdgeIt e=G.first<EdgeIt>(); G.valid(e); G.next(e))
134 // std::cout << G.id(G.source(e)) << "-" << flow.get(e) << "->" << G.id(G.target(e)) << " ";
135 // std::cout<<std::endl;
136 // std::cout << "edges which are not in this maximum matching: "<< std::endl;
137 // for(EdgeIt e=G.first<EdgeIt>(); G.valid(e); G.next(e))
139 // std::cout << G.id(G.source(e)) << "-" << flow.get(e) << "->" << G.id(G.target(e)) << " ";
140 // std::cout<<std::endl;
142 std::cout << "elapsed time: " << ts << std::endl;
143 std::cout << "number of augmentation phases: " << i << std::endl;
144 std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
148 // std::cout << "on-the-fly max bipartite matching demo (Hopcroft-Karp) on wrapped leda graph..." << std::endl;
149 // Graph::EdgeMap<int> flow(G); //0 flow
150 // Graph::EdgeMap<int> cap(G, 1);
155 // MaxMatching<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s_map, t_map, flow, cap);
157 // while (max_flow_test.augmentOnBlockingFlow2()) {
158 // // for(EdgeIt e=G.first<EdgeIt>(); G.valid(e); G.next(e))
159 // // std::cout << G.id(G.source(e)) << "-" << flow.get(e) << "->" << G.id(G.target(e)) << " ";
160 // // std::cout<<std::endl;
164 // // std::cout << "maximum matching: "<< std::endl;
165 // // for(EdgeIt e=G.first<EdgeIt>(); G.valid(e); G.next(e))
166 // // if (flow.get(e))
167 // // std::cout << G.id(G.source(e)) << "-" << flow.get(e) << "->" << G.id(G.target(e)) << " ";
168 // // std::cout<<std::endl;
169 // // std::cout << "edges which are not in this maximum matching: "<< std::endl;
170 // // for(EdgeIt e=G.first<EdgeIt>(); G.valid(e); G.next(e))
171 // // if (!flow.get(e))
172 // // std::cout << G.id(G.source(e)) << "-" << flow.get(e) << "->" << G.id(G.target(e)) << " ";
173 // // std::cout<<std::endl;
175 // std::cout << "elapsed time: " << ts << std::endl;
176 // std::cout << "number of augmentation phases: " << i << std::endl;
177 // std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
181 std::cout << "max bipartite matching (LEDA)..." << std::endl;
182 //Graph::EdgeMap<int> flow(G); //0 flow
183 //Graph::EdgeMap<int> cap(G, 1);
185 leda_node_array<bool> NC(g);
190 //MaxMatching<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s_map, t_map, flow, cap);
192 //while (max_flow_test.augmentOnShortestPath()) { ++i; }
194 //leda_list<leda_edge> l=MAX_CARD_BIPARTITE_MATCHING_HK(g, A, B, NC, false);
195 leda_list<leda_edge> l=MAX_CARD_BIPARTITE_MATCHING(g);
198 // std::cout << "maximum matching: "<< std::endl;
199 // for(EdgeIt e=G.first<EdgeIt>(); G.valid(e); G.next(e))
201 // std::cout << G.id(G.source(e)) << "-" << flow.get(e) << "->" << G.id(G.target(e)) << " ";
202 // std::cout<<std::endl;
203 // std::cout << "edges which are not in this maximum matching: "<< std::endl;
204 // for(EdgeIt e=G.first<EdgeIt>(); G.valid(e); G.next(e))
206 // std::cout << G.id(G.source(e)) << "-" << flow.get(e) << "->" << G.id(G.target(e)) << " ";
207 // std::cout<<std::endl;
210 std::cout << "elapsed time: " << ts << std::endl;
211 //std::cout << "number of augmentation phases: " << i << std::endl;
212 std::cout << "flow value: "<< l.size() << std::endl;