Sorry, the name chosen was a mistake.
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>
25 //typedef UndirListGraph Graph;
26 typedef BipartiteGraph<SageGraph> Graph;
28 typedef Graph::Node Node;
29 typedef Graph::NodeIt NodeIt;
30 typedef Graph::Edge Edge;
31 typedef Graph::EdgeIt EdgeIt;
32 typedef Graph::OutEdgeIt OutEdgeIt;
37 cout << "number of nodes in the first color class=";
40 cout << "number of nodes in the second color class=";
43 cout << "number of edges=";
46 cout << "Generatig a random bipartite graph..." << endl;
48 randomBipartiteGraph(g, a, b, m);
50 // cout << "Edges of the bipartite graph:" << endl;
51 // FOR_EACH_LOC(EdgeIt, e, g) cout << e << " ";
54 // cout << "Nodes:" << endl;
55 // FOR_EACH_LOC(Graph::NodeIt, v, g) cout << v << " ";
57 // cout << "Nodes in T:" << endl;
58 // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " ";
60 // cout << "Nodes in S:" << endl;
61 // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " ";
64 // cout << "Erasing the first node..." << endl;
68 // cout << "Nodes of the bipartite graph:" << endl;
69 // FOR_EACH_GLOB(n, g) cout << n << " ";
72 // cout << "Nodes in T:" << endl;
73 // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " ";
75 // cout << "Nodes in S:" << endl;
76 // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " ";
79 typedef stBipartiteGraphWrapper<Graph> stGW;
81 ConstMap<stGW::Edge, int> const1map(1);
84 cout << "max bipartite matching with stGraphWrapper..." << endl;
86 stGW::EdgeMap<int> flow(stgw);
87 MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
88 max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
90 // while (max_flow_test.augmentOnShortestPath()) { }
91 // typedef ListGraph MutableGraph;
92 // while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
93 // while (max_flow_test.augmentOnBlockingFlow2()) {
94 // cout << max_flow_test.flowValue() << endl;
96 cout << "matching value: " << max_flow_test.flowValue() << endl;
97 cout << "elapsed time: " << ts << endl;
98 // FOR_EACH_LOC(stGW::EdgeIt, e, stgw) {
99 // if (flow[e]) cout << e << endl;
103 typedef ConstMap<Graph::Edge, int> EdgeCap;
105 typedef ConstMap<Graph::Node, int> NodeCap;
107 typedef Graph::EdgeMap<int> EdgeFlow;
109 typedef Graph::NodeMap<int> NodeFlow;
112 typedef stGW::EdgeMapWrapper<EdgeCap, NodeCap> CapMap;
113 typedef stGW::EdgeMapWrapper<EdgeFlow, NodeFlow> FlowMap;
115 FlowMap fm(gef, gnf);
118 cout << "max bipartite matching with stGraphWrapper..." << endl;
120 //stGW::EdgeMap<int> flow(stgw);
121 MaxFlow<stGW, int, CapMap, FlowMap>
122 max_flow_test1(stgw, stgw.S_NODE, stgw.T_NODE, cm, fm);
123 max_flow_test1.run();
124 // while (max_flow_test.augmentOnShortestPath()) { }
125 // typedef ListGraph MutableGraph;
126 // while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
127 // while (max_flow_test.augmentOnBlockingFlow2()) {
128 // cout << max_flow_test.flowValue() << endl;
130 cout << "matching value: " << max_flow_test1.flowValue() << endl;
131 cout << "elapsed time: " << ts << endl;
132 // FOR_EACH_LOC(Graph::EdgeIt, e, g) {
133 // if (gef[e]) cout << e << endl;
137 cout << "max bipartite matching with stGraphWrapper..." << endl;
139 FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0);
140 FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0);
141 MaxBipartiteMatching<Graph, ConstMap<Graph::Edge, int>, ConstMap<Graph::Node, int>,
142 Graph::EdgeMap<int>, Graph::NodeMap<int> >
143 matching_test(g, ge1, gn1, gef, gnf);
146 cout << "matching value: " << matching_test.matchingValue() << endl;
147 cout << "elapsed time: " << ts << endl;
148 // FOR_EACH_LOC(Graph::EdgeIt, e, g) {
149 // if (gef[e]) cout << e << endl;
153 cout << "max bipartite matching with MaxBipartiteMatching..." << endl;
155 FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0);
156 //FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0);
157 typedef MaxBipartiteMatching<Graph, ConstMap<Graph::Edge, int>,
158 ConstMap<Graph::Node, int>,
159 Graph::EdgeMap<int>, Graph::NodeMap<int> > MaxBipartiteMatching;
160 MaxBipartiteMatching matching_test_1(g, ge1, gn1, gef/*, gnf*/);
161 matching_test_1.run();
163 cout << "matching value: " << matching_test_1.matchingValue() << endl;
164 cout << "elapsed time: " << ts << endl;
165 // FOR_EACH_LOC(Graph::EdgeIt, e, g) {
166 // if (gef[e]) cout << e << endl;
170 cout << "testing optimality with MaxBipartiteMatching..." << endl;
172 matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING);
173 cout << "matching value: " << matching_test_1.matchingValue() << endl;
174 cout << "elapsed time: " << ts << endl;
176 cout << "testing optimality with MaxBipartiteMatching..." << endl;
178 matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING_WITH_GOOD_NODE_FLOW);
179 cout << "matching value: " << matching_test_1.matchingValue() << endl;
180 cout << "elapsed time: " << ts << endl;