# HG changeset patch # User marci # Date 1079535001 0 # Node ID 100770da4336a1ea8fc82d91164b44e695811bbe # Parent efea403c959544012fbaabf89117c5bb93ba27d6 . diff -r efea403c9595 -r 100770da4336 src/work/marci/max_bipartite_matching_demo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/max_bipartite_matching_demo.cc Wed Mar 17 14:50:01 2004 +0000 @@ -0,0 +1,107 @@ +// -*- c++ -*- +#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::endl; + +int main() { + leda::graph g; + typedef LedaGraphWrapper Graph; + Graph G(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; + + for(int i=0; i<20; ++i) { + s_nodes.push_back(G.addNode()); + } + for(int i=0; i<20; ++i) { + t_nodes.push_back(G.addNode()); + } + random_init(); + for(int i=0; i<50; ++i) { + G.addEdge(s_nodes[random(20)], t_nodes[random(20)]); + } + Graph::NodeMap s_map; //false + Graph::NodeMap t_map; //false + + for(int i=0; i<20; ++i) { + s_map.set(s_nodes[i], true); + t_map.set(t_nodes[i], true); + } + + { + std::cout << "on-the-fly max bipartite matching demo on wrapped leda graph..." << std::endl; + Graph::EdgeMap flow(G); //0 flow + Graph::EdgeMap capacity(G, 1); + + Timer ts; + ts.reset(); + + MaxMatching, Graph::EdgeMap > max_flow_test(G, s_map, t_map, flow, cap); + //max_flow_test.augmentWithBlockingFlow(); + int i=0; + while (max_flow_test.augmentOnShortestPath()) { +// for(EdgeIt e=G.template first(); e.valid(); ++e) { +// std::cout<<"("<"<(); e.valid(); ++e) { +// std::cout<<"("<"<