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