// -*- c++ -*- #include #include #include #include #include #include #include #include #include #include #include #include /** * Inicializalja a veletlenszamgeneratort. * Figyelem, ez nem jo igazi random szamokhoz, * erre ne bizzad a titkaidat! */ void random_init() { unsigned int seed = getpid(); seed |= seed << 15; seed ^= time(0); srand(seed); } /** * Egy veletlen int-et ad vissza 0 es m-1 kozott. */ int random(int m) { return int( double(m) * rand() / (RAND_MAX + 1.0) ); } using namespace hugo; using std::cout; using std::cin; using std::endl; int main() { leda::graph g; typedef LedaGraphWrapper Graph; Graph G(g); // typedef ListGraph Graph; // Graph G; typedef Graph::Node Node; typedef Graph::NodeIt NodeIt; typedef Graph::Edge Edge; typedef Graph::EdgeIt EdgeIt; typedef Graph::OutEdgeIt OutEdgeIt; typedef Graph::InEdgeIt InEdgeIt; //Node s, t; //Graph::EdgeMap cap(G); //readDimacsMaxFlow(std::cin, G, s, t, cap); std::vector s_nodes; std::vector t_nodes; int a; cout << "number of nodes in the first color class="; cin >> a; int b; cout << "number of nodes in the second color class="; cin >> b; int m; cout << "number of edges="; cin >> m; for(int i=0; i A; leda_list B; Graph::NodeMap s_map(G); //false Graph::NodeMap t_map(G); //false for(int i=0; i(); G.valid(n); G.next(n)) { // cout << G.id(n) << ": "; // cout << "out edges: "; // for(OutEdgeIt e=G.first(n); G.valid(e); G.next(e)) // cout << G.id(G.tail(e)) << "->" << G.id(G.head(e)) << " "; // cout << "in edges: "; // for(InEdgeIt e=G.first(n); G.valid(e); G.next(e)) // cout << G.id(G.tail(e)) << "->" << G.id(G.head(e)) << " "; // cout << endl; // } { std::cout << "on-the-fly max bipartite matching (Edmonds-Karp) demo on wrapped leda graph..." << std::endl; Graph::EdgeMap flow(G); //0 flow Graph::EdgeMap cap(G, 1); Timer ts; ts.reset(); MaxMatching, Graph::EdgeMap > max_flow_test(G, s_map, t_map, flow, cap); int i=0; while (max_flow_test.augmentOnShortestPath()) { // for(EdgeIt e=G.first(); G.valid(e); G.next(e)) // std::cout << G.id(G.tail(e)) << "-" << flow.get(e) << "->" << G.id(G.head(e)) << " "; // std::cout<(); G.valid(e); G.next(e)) // if (flow.get(e)) // std::cout << G.id(G.tail(e)) << "-" << flow.get(e) << "->" << G.id(G.head(e)) << " "; // std::cout<(); G.valid(e); G.next(e)) // if (!flow.get(e)) // std::cout << G.id(G.tail(e)) << "-" << flow.get(e) << "->" << G.id(G.head(e)) << " "; // std::cout< flow(G); //0 flow // Graph::EdgeMap cap(G, 1); // Timer ts; // ts.reset(); // MaxMatching, Graph::EdgeMap > max_flow_test(G, s_map, t_map, flow, cap); // int i=0; // while (max_flow_test.augmentOnBlockingFlow2()) { // // for(EdgeIt e=G.first(); G.valid(e); G.next(e)) // // std::cout << G.id(G.tail(e)) << "-" << flow.get(e) << "->" << G.id(G.head(e)) << " "; // // std::cout<(); G.valid(e); G.next(e)) // // if (flow.get(e)) // // std::cout << G.id(G.tail(e)) << "-" << flow.get(e) << "->" << G.id(G.head(e)) << " "; // // std::cout<(); G.valid(e); G.next(e)) // // if (!flow.get(e)) // // std::cout << G.id(G.tail(e)) << "-" << flow.get(e) << "->" << G.id(G.head(e)) << " "; // // std::cout< flow(G); //0 flow //Graph::EdgeMap cap(G, 1); leda_node_array NC(g); Timer ts; ts.reset(); //MaxMatching, Graph::EdgeMap > max_flow_test(G, s_map, t_map, flow, cap); //int i=0; //while (max_flow_test.augmentOnShortestPath()) { ++i; } //leda_list l=MAX_CARD_BIPARTITE_MATCHING_HK(g, A, B, NC, false); leda_list l=MAX_CARD_BIPARTITE_MATCHING(g); // std::cout << "maximum matching: "<< std::endl; // for(EdgeIt e=G.first(); G.valid(e); G.next(e)) // if (flow.get(e)) // std::cout << G.id(G.tail(e)) << "-" << flow.get(e) << "->" << G.id(G.head(e)) << " "; // std::cout<(); G.valid(e); G.next(e)) // if (!flow.get(e)) // std::cout << G.id(G.tail(e)) << "-" << flow.get(e) << "->" << G.id(G.head(e)) << " "; // std::cout<