.
6 #include <sage_graph.h>
7 //#include <smart_graph.h>
9 #include <hugo/time_measure.h>
10 #include <for_each_macros.h>
12 #include <bipartite_graph_wrapper.h>
13 #include <hugo/maps.h>
14 #include <hugo/max_flow.h>
15 #include <graph_gen.h>
16 #include <max_bipartite_matching.h>
24 //typedef UndirListGraph Graph;
25 typedef BipartiteGraph<SageGraph> Graph;
27 typedef Graph::Node Node;
28 typedef Graph::NodeIt NodeIt;
29 typedef Graph::Edge Edge;
30 typedef Graph::EdgeIt EdgeIt;
31 typedef Graph::OutEdgeIt OutEdgeIt;
36 cout << "number of nodes in the first color class=";
39 cout << "number of nodes in the second color class=";
42 cout << "number of edges=";
45 cout << "Generatig a random bipartite graph..." << endl;
47 randomBipartiteGraph(g, a, b, m);
49 // cout << "Edges of the bipartite graph:" << endl;
50 // FOR_EACH_LOC(EdgeIt, e, g) cout << e << " ";
53 // cout << "Nodes:" << endl;
54 // FOR_EACH_LOC(Graph::NodeIt, v, g) cout << v << " ";
56 // cout << "Nodes in T:" << endl;
57 // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " ";
59 // cout << "Nodes in S:" << endl;
60 // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " ";
63 // cout << "Erasing the first node..." << endl;
67 // cout << "Nodes of the bipartite graph:" << endl;
68 // FOR_EACH_GLOB(n, g) cout << n << " ";
71 // cout << "Nodes in T:" << endl;
72 // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " ";
74 // cout << "Nodes in S:" << endl;
75 // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " ";
78 typedef stBipartiteGraphWrapper<Graph> stGW;
80 ConstMap<stGW::Edge, int> const1map(1);
83 cout << "max bipartite matching with stGraphWrapper..." << endl;
85 stGW::EdgeMap<int> flow(stgw);
86 MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
87 max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
89 // while (max_flow_test.augmentOnShortestPath()) { }
90 // typedef ListGraph MutableGraph;
91 // while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
92 // while (max_flow_test.augmentOnBlockingFlow2()) {
93 // cout << max_flow_test.flowValue() << endl;
95 cout << "matching value: " << max_flow_test.flowValue() << endl;
96 cout << "elapsed time: " << ts << endl;
97 // FOR_EACH_LOC(stGW::EdgeIt, e, stgw) {
98 // if (flow[e]) cout << e << endl;
102 typedef ConstMap<Graph::Edge, int> EdgeCap;
104 typedef ConstMap<Graph::Node, int> NodeCap;
106 typedef Graph::EdgeMap<int> EdgeFlow;
108 typedef Graph::NodeMap<int> NodeFlow;
111 typedef stGW::EdgeMapWrapper<EdgeCap, NodeCap> CapMap;
112 typedef stGW::EdgeMapWrapper<EdgeFlow, NodeFlow> FlowMap;
114 FlowMap fm(gef, gnf);
117 cout << "max bipartite matching with stGraphWrapper..." << endl;
119 //stGW::EdgeMap<int> flow(stgw);
120 MaxFlow<stGW, int, CapMap, FlowMap>
121 max_flow_test1(stgw, stgw.S_NODE, stgw.T_NODE, cm, fm);
122 max_flow_test1.run();
123 // while (max_flow_test.augmentOnShortestPath()) { }
124 // typedef ListGraph MutableGraph;
125 // while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
126 // while (max_flow_test.augmentOnBlockingFlow2()) {
127 // cout << max_flow_test.flowValue() << endl;
129 cout << "matching value: " << max_flow_test1.flowValue() << endl;
130 cout << "elapsed time: " << ts << endl;
131 // FOR_EACH_LOC(Graph::EdgeIt, e, g) {
132 // if (gef[e]) cout << e << endl;
136 cout << "max bipartite matching with stGraphWrapper..." << endl;
138 FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0);
139 FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0);
140 MaxBipartiteMatching<Graph, ConstMap<Graph::Edge, int>, ConstMap<Graph::Node, int>,
141 Graph::EdgeMap<int>, Graph::NodeMap<int> >
142 matching_test(g, ge1, gn1, gef, gnf);
145 cout << "matching value: " << matching_test.matchingValue() << endl;
146 cout << "elapsed time: " << ts << endl;
147 // FOR_EACH_LOC(Graph::EdgeIt, e, g) {
148 // if (gef[e]) cout << e << endl;
152 cout << "max bipartite matching with MaxBipartiteMatching..." << endl;
154 FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0);
155 //FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0);
156 typedef MaxBipartiteMatching<Graph, ConstMap<Graph::Edge, int>,
157 ConstMap<Graph::Node, int>,
158 Graph::EdgeMap<int>, Graph::NodeMap<int> > MaxBipartiteMatching;
159 MaxBipartiteMatching matching_test_1(g, ge1, gn1, gef/*, gnf*/);
160 matching_test_1.run();
162 cout << "matching value: " << matching_test_1.matchingValue() << endl;
163 cout << "elapsed time: " << ts << endl;
164 // FOR_EACH_LOC(Graph::EdgeIt, e, g) {
165 // if (gef[e]) cout << e << endl;
169 cout << "testing optimality with MaxBipartiteMatching..." << endl;
171 matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING);
172 cout << "matching value: " << matching_test_1.matchingValue() << endl;
173 cout << "elapsed time: " << ts << endl;
175 cout << "testing optimality with MaxBipartiteMatching..." << endl;
177 matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING_WITH_GOOD_NODE_FLOW);
178 cout << "matching value: " << matching_test_1.matchingValue() << endl;
179 cout << "elapsed time: " << ts << endl;