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