// -*- c++ -*- #include #include #include #include //#include //#include #include #include #include #include #include #include #include #include using namespace hugo; int main() { //typedef UndirListGraph Graph; typedef BipartiteGraph Graph; typedef Graph::Node Node; typedef Graph::NodeIt NodeIt; typedef Graph::Edge Edge; typedef Graph::EdgeIt EdgeIt; typedef Graph::OutEdgeIt OutEdgeIt; Graph g; int a; std::cout << "number of nodes in the first color class="; std::cin >> a; int b; std::cout << "number of nodes in the second color class="; std::cin >> b; int m; std::cout << "number of edges="; std::cin >> m; std::cout << "Generatig a random bipartite graph..." << std::endl; random_init(); randomBipartiteGraph(g, a, b, m); // std::cout << "Edges of the bipartite graph:" << std::endl; // FOR_EACH_LOC(EdgeIt, e, g) std::cout << e << " "; // std::cout << std::endl; // std::cout << "Nodes:" << std::endl; // FOR_EACH_LOC(Graph::NodeIt, v, g) std::cout << v << " "; // std::cout << std::endl; // std::cout << "Nodes in T:" << std::endl; // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " "; // std::cout << std::endl; // std::cout << "Nodes in S:" << std::endl; // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " "; // std::cout << std::endl; // std::cout << "Erasing the first node..." << std::endl; // NodeIt n; // g.first(n); // g.erase(n); // std::cout << "Nodes of the bipartite graph:" << std::endl; // FOR_EACH_GLOB(n, g) std::cout << n << " "; // std::cout << std::endl; // std::cout << "Nodes in T:" << std::endl; // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " "; // std::cout << std::endl; // std::cout << "Nodes in S:" << std::endl; // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " "; // std::cout << std::endl; typedef stGraphWrapper stGW; stGW stgw(g); ConstMap const1map(1); Timer ts; ts.reset(); stGW::EdgeMap flow(stgw); MaxFlow, stGW::EdgeMap > max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow); max_flow_test.run(); // while (max_flow_test.augmentOnShortestPath()) { } // typedef ListGraph MutableGraph; // while (max_flow_test.augmentOnBlockingFlow1()) { // while (max_flow_test.augmentOnBlockingFlow2()) { // std::cout << max_flow_test.flowValue() << std::endl; // } std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl; std::cout << "elapsed time: " << ts << std::endl; // FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { // if (flow[e]) std::cout << e << std::endl; // } std::cout << std::endl; typedef ConstMap EdgeCap; EdgeCap ge1(1); typedef ConstMap NodeCap; NodeCap gn1(1); typedef Graph::EdgeMap EdgeFlow; EdgeFlow gef(g); //0 typedef Graph::NodeMap NodeFlow; NodeFlow gnf(g); //0 typedef stGraphWrapper::EdgeMapWrapper CapMap; typedef stGraphWrapper::EdgeMapWrapper FlowMap; CapMap cm(ge1, gn1); FlowMap fm(gef, gnf); //Timer ts; ts.reset(); //stGW::EdgeMap flow(stgw); MaxFlow max_flow_test1(stgw, stgw.S_NODE, stgw.T_NODE, cm, fm); max_flow_test1.run(); // while (max_flow_test.augmentOnShortestPath()) { } // typedef ListGraph MutableGraph; // while (max_flow_test.augmentOnBlockingFlow1()) { // while (max_flow_test.augmentOnBlockingFlow2()) { // std::cout << max_flow_test.flowValue() << std::endl; // } std::cout << "max flow value: " << max_flow_test1.flowValue() << std::endl; std::cout << "elapsed time: " << ts << std::endl; // FOR_EACH_LOC(Graph::EdgeIt, e, g) { // if (gef[e]) std::cout << e << std::endl; // } std::cout << std::endl; ts.reset(); FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0); FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0); MaxBipartiteMatching, ConstMap, Graph::EdgeMap, Graph::NodeMap > matching_test(g, ge1, gn1, gef, gnf); matching_test.run(); std::cout << "max flow value: " << matching_test.matchingValue() << std::endl; std::cout << "elapsed time: " << ts << std::endl; // FOR_EACH_LOC(Graph::EdgeIt, e, g) { // if (gef[e]) std::cout << e << std::endl; // } std::cout << std::endl; ts.reset(); FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0); //FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0); MaxBipartiteMatching, ConstMap, Graph::EdgeMap, Graph::NodeMap > matching_test_1(g, ge1, gn1, gef/*, gnf*/); matching_test_1.run(); std::cout << "max flow value: " << matching_test_1.matchingValue() << std::endl; std::cout << "elapsed time: " << ts << std::endl; // FOR_EACH_LOC(Graph::EdgeIt, e, g) { // if (gef[e]) std::cout << e << std::endl; // } std::cout << std::endl; return 0; }