marci@446: // -*- c++ -*- marci@446: #include <iostream> marci@446: #include <fstream> marci@446: #include <vector> marci@446: #include <cstdlib> marci@446: marci@446: #include <LEDA/graph.h> marci@446: #include <LEDA/mcb_matching.h> marci@446: #include <LEDA/list.h> marci@446: #include <LEDA/graph_gen.h> marci@446: marci@446: #include <leda_graph_wrapper.h> marci@446: #include <list_graph.h> marci@446: //#include <smart_graph.h> marci@446: //#include <dimacs.h> marci@446: #include <time_measure.h> marci@446: #include <for_each_macros.h> marci@446: //#include <bfs_iterator.h> marci@446: #include <graph_wrapper.h> marci@446: #include <maps.h> marci@446: #include <edmonds_karp.h> marci@446: #include <preflow.h> marci@446: marci@446: /** marci@446: * Inicializalja a veletlenszamgeneratort. marci@446: * Figyelem, ez nem jo igazi random szamokhoz, marci@446: * erre ne bizzad a titkaidat! marci@446: */ marci@446: void random_init() marci@446: { marci@446: unsigned int seed = getpid(); marci@446: seed |= seed << 15; marci@446: seed ^= time(0); marci@446: marci@446: srand(seed); marci@446: } marci@446: marci@446: /** marci@446: * Egy veletlen int-et ad vissza 0 es m-1 kozott. marci@446: */ marci@446: int random(int m) marci@446: { marci@446: return int( double(m) * rand() / (RAND_MAX + 1.0) ); marci@446: } marci@446: marci@446: using namespace hugo; marci@446: marci@446: int main() { marci@446: //for leda graph marci@446: leda::graph lg; marci@446: //lg.make_undirected(); marci@446: typedef LedaGraphWrapper<leda::graph> Graph; marci@446: Graph g(lg); marci@446: marci@446: //for UndirListGraph marci@446: //typedef UndirListGraph Graph; marci@446: //Graph g; marci@446: marci@446: typedef Graph::Node Node; marci@446: typedef Graph::NodeIt NodeIt; marci@446: typedef Graph::Edge Edge; marci@446: typedef Graph::EdgeIt EdgeIt; marci@446: typedef Graph::OutEdgeIt OutEdgeIt; marci@446: marci@446: std::vector<Graph::Node> s_nodes; marci@446: std::vector<Graph::Node> t_nodes; marci@446: marci@446: int a; marci@446: std::cout << "number of nodes in the first color class="; marci@446: std::cin >> a; marci@446: int b; marci@446: std::cout << "number of nodes in the second color class="; marci@446: std::cin >> b; marci@446: int m; marci@446: std::cout << "number of edges="; marci@446: std::cin >> m; marci@446: int k; marci@447: std::cout << "A bipartite graph is a random group graph if the color classes \nA and B are partitiones to A_0, A_1, ..., A_{k-1} and B_0, B_1, ..., B_{k-1} \nas equally as possible \nand the edges from A_i goes to A_{i-1 mod k} and A_{i+1 mod k}.\n"; marci@446: std::cout << "number of groups in LEDA random group graph="; marci@446: std::cin >> k; marci@446: marci@446: leda_list<leda_node> lS; marci@446: leda_list<leda_node> lT; marci@446: random_bigraph(lg, a, b, m, lS, lT, k); marci@446: marci@446: // for (int i=0; i<a; ++i) s_nodes.push_back(g.addNode()); marci@446: // for (int i=0; i<b; ++i) t_nodes.push_back(g.addNode()); marci@446: marci@446: // random_init(); marci@446: // for(int i=0; i<m; ++i) { marci@446: // g.addEdge(s_nodes[random(a)], t_nodes[random(b)]); marci@446: // } marci@446: marci@446: Graph::NodeMap<int> ref_map(g, -1); marci@446: marci@446: IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map); marci@446: // for (int i=0; i<a; ++i) bipartite_map.insert(s_nodes[i], false); marci@446: // for (int i=0; i<b; ++i) bipartite_map.insert(t_nodes[i], true); marci@446: leda_node ln; marci@446: forall(ln, lS) bipartite_map.insert(ln, false); marci@446: forall(ln, lT) bipartite_map.insert(ln, true); marci@446: marci@446: typedef BipartiteGraphWrapper<Graph> BGW; marci@446: BGW bgw(g, bipartite_map); marci@446: marci@446: // BGW::NodeMap<int> dbyj(bgw); marci@446: // BGW::EdgeMap<int> dbyxcj(bgw); marci@446: marci@446: typedef stGraphWrapper<BGW> stGW; marci@446: stGW stgw(bgw); marci@446: ConstMap<stGW::Edge, int> const1map(1); marci@446: stGW::EdgeMap<int> flow(stgw); marci@446: marci@446: Timer ts; marci@446: FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0); marci@446: ts.reset(); marci@446: // stGW::EdgeMap<int> pre_flow(stgw); marci@446: Preflow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> > marci@459: pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow/*, true*/); marci@446: pre_flow_test.run(); marci@446: std::cout << "HUGO pre flow value: " << pre_flow_test.flowValue() << std::endl; marci@446: std::cout << "elapsed time: " << ts << std::endl; marci@446: // FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { marci@446: // std::cout << e << ": " << pre_flow[e] << "\n"; marci@446: // } marci@446: std::cout << "\n"; marci@446: marci@446: ts.reset(); marci@446: leda_list<leda_edge> ml=MAX_CARD_BIPARTITE_MATCHING(lg); marci@446: // stGW::EdgeMap<int> pre_flow(stgw); marci@446: //Preflow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> > marci@446: // pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, pre_flow, true); marci@446: //pre_flow_test.run(); marci@446: std::cout << "LEDA matching value: " << ml.size() << std::endl; marci@446: std::cout << "elapsed time: " << ts << std::endl; marci@446: // FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { marci@446: // std::cout << e << ": " << pre_flow[e] << "\n"; marci@446: // } marci@446: std::cout << "\n"; marci@446: marci@446: FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0); marci@446: ts.reset(); marci@446: MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> > marci@446: max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow); marci@446: // while (max_flow_test.augmentOnShortestPath()) { } marci@446: typedef ListGraph MutableGraph; marci@446: // while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { marci@446: while (max_flow_test.augmentOnBlockingFlow2()) { marci@446: std::cout << max_flow_test.flowValue() << std::endl; marci@446: } marci@446: std::cout << "HUGO blocking flow value: " << max_flow_test.flowValue() << std::endl; marci@446: std::cout << "elapsed time: " << ts << std::endl; marci@446: // FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { marci@446: // std::cout << e << ": " << max_flow[e] << "\n"; marci@446: // } marci@446: // std::cout << "\n"; marci@446: marci@446: return 0; marci@446: }