# HG changeset patch # User marci # Date 1093261476 0 # Node ID ad7dff9ee2fd50631f8458bc044c57610de094d4 # Parent 6387df9aadb023b39d40e313a577d88e22987831 sg is moved sg is not... diff -r 6387df9aadb0 -r ad7dff9ee2fd src/work/marci/bipartite_matching_demo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/bipartite_matching_demo.cc Mon Aug 23 11:44:36 2004 +0000 @@ -0,0 +1,183 @@ +// -*- c++ -*- +#include +#include +#include + +#include +//#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace hugo; + +using std::cin; +using std::cout; +using std::endl; + +int main() { + //typedef UndirListGraph Graph; + typedef BipartiteGraph Graph; + + typedef Graph::Node Node; + typedef Graph::NodeIt NodeIt; + typedef Graph::Edge Edge; + typedef Graph::EdgeIt EdgeIt; + typedef Graph::OutEdgeIt OutEdgeIt; + + Graph g; + + 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; + + cout << "Generatig a random bipartite graph..." << endl; + random_init(); + randomBipartiteGraph(g, a, b, m); + +// cout << "Edges of the bipartite graph:" << endl; +// FOR_EACH_LOC(EdgeIt, e, g) cout << e << " "; +// cout << endl; + +// cout << "Nodes:" << endl; +// FOR_EACH_LOC(Graph::NodeIt, v, g) cout << v << " "; +// cout << endl; +// cout << "Nodes in T:" << endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " "; +// cout << endl; +// cout << "Nodes in S:" << endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " "; +// cout << endl; + +// cout << "Erasing the first node..." << endl; +// NodeIt n; +// g.first(n); +// g.erase(n); +// cout << "Nodes of the bipartite graph:" << endl; +// FOR_EACH_GLOB(n, g) cout << n << " "; +// cout << endl; + +// cout << "Nodes in T:" << endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " "; +// cout << endl; +// cout << "Nodes in S:" << endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " "; +// cout << endl; + + typedef stBipartiteGraphWrapper stGW; + stGW stgw(g); + ConstMap const1map(1); + + Timer ts; + cout << "max bipartite matching with stGraphWrapper..." << endl; + ts.reset(); + stGW::EdgeMap flow(stgw); + MaxFlow, stGW::EdgeMap > + max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow); + max_flow_test.run(); +// while (max_flow_test.augmentOnShortestPath()) { } +// typedef ListGraph MutableGraph; +// while (max_flow_test.augmentOnBlockingFlow1()) { +// while (max_flow_test.augmentOnBlockingFlow2()) { +// cout << max_flow_test.flowValue() << endl; +// } + cout << "matching value: " << max_flow_test.flowValue() << endl; + cout << "elapsed time: " << ts << endl; +// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { +// if (flow[e]) cout << e << endl; +// } + cout << endl; + + typedef ConstMap EdgeCap; + EdgeCap ge1(1); + typedef ConstMap NodeCap; + NodeCap gn1(1); + typedef Graph::EdgeMap EdgeFlow; + EdgeFlow gef(g); //0 + typedef Graph::NodeMap NodeFlow; + NodeFlow gnf(g); //0 + + typedef stGW::EdgeMapWrapper CapMap; + typedef stGW::EdgeMapWrapper FlowMap; + CapMap cm(ge1, gn1); + FlowMap fm(gef, gnf); + + //Timer ts; + cout << "max bipartite matching with stGraphWrapper..." << endl; + ts.reset(); + //stGW::EdgeMap flow(stgw); + MaxFlow + max_flow_test1(stgw, stgw.S_NODE, stgw.T_NODE, cm, fm); + max_flow_test1.run(); +// while (max_flow_test.augmentOnShortestPath()) { } +// typedef ListGraph MutableGraph; +// while (max_flow_test.augmentOnBlockingFlow1()) { +// while (max_flow_test.augmentOnBlockingFlow2()) { +// cout << max_flow_test.flowValue() << endl; +// } + cout << "matching value: " << max_flow_test1.flowValue() << endl; + cout << "elapsed time: " << ts << endl; +// FOR_EACH_LOC(Graph::EdgeIt, e, g) { +// if (gef[e]) cout << e << endl; +// } + cout << endl; + + cout << "max bipartite matching with stGraphWrapper..." << endl; + ts.reset(); + FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0); + FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0); + MaxBipartiteMatching, ConstMap, + Graph::EdgeMap, Graph::NodeMap > + matching_test(g, ge1, gn1, gef, gnf); + matching_test.run(); + + cout << "matching value: " << matching_test.matchingValue() << endl; + cout << "elapsed time: " << ts << endl; +// FOR_EACH_LOC(Graph::EdgeIt, e, g) { +// if (gef[e]) cout << e << endl; +// } + cout << endl; + + cout << "max bipartite matching with MaxBipartiteMatching..." << endl; + ts.reset(); + FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0); + //FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0); + typedef MaxBipartiteMatching, + ConstMap, + Graph::EdgeMap, Graph::NodeMap > MaxBipartiteMatching; + MaxBipartiteMatching matching_test_1(g, ge1, gn1, gef/*, gnf*/); + matching_test_1.run(); + + cout << "matching value: " << matching_test_1.matchingValue() << endl; + cout << "elapsed time: " << ts << endl; +// FOR_EACH_LOC(Graph::EdgeIt, e, g) { +// if (gef[e]) cout << e << endl; +// } + cout << endl; + + cout << "testing optimality with MaxBipartiteMatching..." << endl; + ts.reset(); + matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING); + cout << "matching value: " << matching_test_1.matchingValue() << endl; + cout << "elapsed time: " << ts << endl; + + cout << "testing optimality with MaxBipartiteMatching..." << endl; + ts.reset(); + matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING_WITH_GOOD_NODE_FLOW); + cout << "matching value: " << matching_test_1.matchingValue() << endl; + cout << "elapsed time: " << ts << endl; + + return 0; +} diff -r 6387df9aadb0 -r ad7dff9ee2fd src/work/marci/bipartite_matching_try.cc --- a/src/work/marci/bipartite_matching_try.cc Mon Aug 23 11:28:26 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -// -*- c++ -*- -#include -#include -#include -#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; - -int main() { - typedef UndirSageGraph Graph; - typedef Graph::Node Node; - typedef Graph::NodeIt NodeIt; - typedef Graph::Edge Edge; - typedef Graph::EdgeIt EdgeIt; - typedef Graph::OutEdgeIt OutEdgeIt; - - Graph g; - - std::vector s_nodes; - std::vector t_nodes; - - int a; - std::cout << "number of nodes in the first color class="; - std::cin >> a; - int b; - std::cout << "number of nodes in the second color class="; - std::cin >> b; - int m; - std::cout << "number of edges="; - std::cin >> m; - - - for (int i=0; i ref_map(g, -1); - - IterableBoolMap< Graph::NodeMap > bipartite_map(ref_map); - for (int i=0; i BGW; - BGW bgw(g, bipartite_map); - -// std::cout << "Nodes by NodeIt:\n"; -// FOR_EACH_LOC(BGW::NodeIt, n, bgw) { -// std::cout << n << " "; -// } -// std::cout << "\n"; -// std::cout << "Nodes in S by ClassNodeIt:\n"; -// FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.S_CLASS) { -// std::cout << n << " "; -// } -// std::cout << "\n"; -// std::cout << "Nodes in T by ClassNodeIt:\n"; -// FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.T_CLASS) { -// std::cout << n << " "; -// } -// std::cout << "\n"; -// std::cout << "Edges of the bipartite graph:\n"; -// FOR_EACH_LOC(BGW::EdgeIt, e, bgw) { -// std::cout << bgw.tail(e) << "->" << bgw.head(e) << std::endl; -// } - -// BGW::NodeMap dbyj(bgw); -// BGW::EdgeMap dbyxcj(bgw); - - typedef stBipartiteGraphWrapper stGW; - stGW stgw(bgw); - ConstMap const1map(1); -// stGW::NodeMap ize(stgw); - -// BfsIterator< BGW, BGW::NodeMap > bfs(bgw); -// Graph::NodeIt si; -// Graph::Node s; -// s=g.first(si); -// bfs.pushAndSetReached(BGW::Node(s)); -// while (!bfs.finished()) { ++bfs; } - -// FOR_EACH_LOC(stGW::NodeIt, n, stgw) { -// std::cout << "out-edges of " << n << ":\n"; -// FOR_EACH_INC_LOC(stGW::OutEdgeIt, e, stgw, n) { -// std::cout << " " << e << "\n"; -// std::cout << " aNode: " << stgw.aNode(e) << "\n"; -// std::cout << " bNode: " << stgw.bNode(e) << "\n"; -// } -// std::cout << "in-edges of " << n << ":\n"; -// FOR_EACH_INC_LOC(stGW::InEdgeIt, e, stgw, n) { -// std::cout << " " << e << "\n"; -// std::cout << " aNode: " << stgw.aNode(e) << "\n"; -// std::cout << " bNode: " << stgw.bNode(e) << "\n"; -// } -// } -// std::cout << "Edges of the stGraphWrapper:\n"; -// FOR_EACH_LOC(stGW::EdgeIt, n, stgw) { -// std::cout << " " << n << "\n"; -// } - -// stGW::NodeMap b(stgw); -// FOR_EACH_LOC(stGW::NodeIt, n, stgw) { -// std::cout << n << ": " << b[n] <<"\n"; -// } - -// std::cout << "Bfs from s: \n"; -// BfsIterator< stGW, stGW::NodeMap > bfs_stgw(stgw); -// bfs_stgw.pushAndSetReached(stgw.S_NODE); -// while (!bfs_stgw.finished()) { -// std::cout << " " << stGW::OutEdgeIt(bfs_stgw) << "\n"; -// ++bfs_stgw; -// } - - - Timer ts; - ts.reset(); - stGW::EdgeMap max_flow(stgw); - AugmentingFlow, stGW::EdgeMap > - max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, max_flow); -// while (max_flow_test.augmentOnShortestPath()) { } - typedef SageGraph MutableGraph; -// while (max_flow_test.augmentOnBlockingFlow1()) { - while (max_flow_test.augmentOnBlockingFlow2()) { - std::cout << max_flow_test.flowValue() << std::endl; - } - std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl; - std::cout << "elapsed time: " << ts << std::endl; -// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { -// std::cout << e << ": " << max_flow[e] << "\n"; -// } -// std::cout << "\n"; - - ts.reset(); - stGW::EdgeMap pre_flow(stgw); - MaxFlow, stGW::EdgeMap > - pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, pre_flow/*, true*/); - pre_flow_test.run(); - std::cout << "pre flow value: " << max_flow_test.flowValue() << std::endl; - std::cout << "elapsed time: " << ts << std::endl; -// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { -// std::cout << e << ": " << pre_flow[e] << "\n"; -// } -// std::cout << "\n"; - - return 0; -} diff -r 6387df9aadb0 -r ad7dff9ee2fd src/work/marci/bipartite_matching_try_3.cc --- a/src/work/marci/bipartite_matching_try_3.cc Mon Aug 23 11:28:26 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,182 +0,0 @@ -// -*- c++ -*- -#include -#include -#include - -#include -//#include -//#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace hugo; - -using std::cout; -using std::endl; - -int main() { - //typedef UndirListGraph Graph; - typedef BipartiteGraph Graph; - - typedef Graph::Node Node; - typedef Graph::NodeIt NodeIt; - typedef Graph::Edge Edge; - typedef Graph::EdgeIt EdgeIt; - typedef Graph::OutEdgeIt OutEdgeIt; - - Graph g; - - int a; - cout << "number of nodes in the first color class="; - std::cin >> a; - int b; - cout << "number of nodes in the second color class="; - std::cin >> b; - int m; - cout << "number of edges="; - std::cin >> m; - - cout << "Generatig a random bipartite graph..." << endl; - random_init(); - randomBipartiteGraph(g, a, b, m); - -// cout << "Edges of the bipartite graph:" << endl; -// FOR_EACH_LOC(EdgeIt, e, g) cout << e << " "; -// cout << endl; - -// cout << "Nodes:" << endl; -// FOR_EACH_LOC(Graph::NodeIt, v, g) cout << v << " "; -// cout << endl; -// cout << "Nodes in T:" << endl; -// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " "; -// cout << endl; -// cout << "Nodes in S:" << endl; -// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " "; -// cout << endl; - -// cout << "Erasing the first node..." << endl; -// NodeIt n; -// g.first(n); -// g.erase(n); -// cout << "Nodes of the bipartite graph:" << endl; -// FOR_EACH_GLOB(n, g) cout << n << " "; -// cout << endl; - -// cout << "Nodes in T:" << endl; -// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " "; -// cout << endl; -// cout << "Nodes in S:" << endl; -// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " "; -// cout << endl; - - typedef stBipartiteGraphWrapper stGW; - stGW stgw(g); - ConstMap const1map(1); - - Timer ts; - cout << "max bipartite matching with stGraphWrapper..." << endl; - ts.reset(); - stGW::EdgeMap flow(stgw); - MaxFlow, stGW::EdgeMap > - max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow); - max_flow_test.run(); -// while (max_flow_test.augmentOnShortestPath()) { } -// typedef ListGraph MutableGraph; -// while (max_flow_test.augmentOnBlockingFlow1()) { -// while (max_flow_test.augmentOnBlockingFlow2()) { -// cout << max_flow_test.flowValue() << endl; -// } - cout << "matching value: " << max_flow_test.flowValue() << endl; - cout << "elapsed time: " << ts << endl; -// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { -// if (flow[e]) cout << e << endl; -// } - cout << endl; - - typedef ConstMap EdgeCap; - EdgeCap ge1(1); - typedef ConstMap NodeCap; - NodeCap gn1(1); - typedef Graph::EdgeMap EdgeFlow; - EdgeFlow gef(g); //0 - typedef Graph::NodeMap NodeFlow; - NodeFlow gnf(g); //0 - - typedef stGW::EdgeMapWrapper CapMap; - typedef stGW::EdgeMapWrapper FlowMap; - CapMap cm(ge1, gn1); - FlowMap fm(gef, gnf); - - //Timer ts; - cout << "max bipartite matching with stGraphWrapper..." << endl; - ts.reset(); - //stGW::EdgeMap flow(stgw); - MaxFlow - max_flow_test1(stgw, stgw.S_NODE, stgw.T_NODE, cm, fm); - max_flow_test1.run(); -// while (max_flow_test.augmentOnShortestPath()) { } -// typedef ListGraph MutableGraph; -// while (max_flow_test.augmentOnBlockingFlow1()) { -// while (max_flow_test.augmentOnBlockingFlow2()) { -// cout << max_flow_test.flowValue() << endl; -// } - cout << "matching value: " << max_flow_test1.flowValue() << endl; - cout << "elapsed time: " << ts << endl; -// FOR_EACH_LOC(Graph::EdgeIt, e, g) { -// if (gef[e]) cout << e << endl; -// } - cout << endl; - - cout << "max bipartite matching with stGraphWrapper..." << endl; - ts.reset(); - FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0); - FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0); - MaxBipartiteMatching, ConstMap, - Graph::EdgeMap, Graph::NodeMap > - matching_test(g, ge1, gn1, gef, gnf); - matching_test.run(); - - cout << "matching value: " << matching_test.matchingValue() << endl; - cout << "elapsed time: " << ts << endl; -// FOR_EACH_LOC(Graph::EdgeIt, e, g) { -// if (gef[e]) cout << e << endl; -// } - cout << endl; - - cout << "max bipartite matching with MaxBipartiteMatching..." << endl; - ts.reset(); - FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0); - //FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0); - typedef MaxBipartiteMatching, - ConstMap, - Graph::EdgeMap, Graph::NodeMap > MaxBipartiteMatching; - MaxBipartiteMatching matching_test_1(g, ge1, gn1, gef/*, gnf*/); - matching_test_1.run(); - - cout << "matching value: " << matching_test_1.matchingValue() << endl; - cout << "elapsed time: " << ts << endl; -// FOR_EACH_LOC(Graph::EdgeIt, e, g) { -// if (gef[e]) cout << e << endl; -// } - cout << endl; - - cout << "testing optimality with MaxBipartiteMatching..." << endl; - ts.reset(); - matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING); - cout << "matching value: " << matching_test_1.matchingValue() << endl; - cout << "elapsed time: " << ts << endl; - - cout << "testing optimality with MaxBipartiteMatching..." << endl; - ts.reset(); - matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING_WITH_GOOD_NODE_FLOW); - cout << "matching value: " << matching_test_1.matchingValue() << endl; - cout << "elapsed time: " << ts << endl; - - return 0; -} diff -r 6387df9aadb0 -r ad7dff9ee2fd src/work/marci/leda/bipartite_matching_comparison.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/leda/bipartite_matching_comparison.cc Mon Aug 23 11:44:36 2004 +0000 @@ -0,0 +1,152 @@ +// -*- c++ -*- +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +//#include +//#include +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +using std::endl; + +using namespace hugo; + +int main() { + //for leda graph + leda::graph lg; + //lg.make_undirected(); + typedef LedaGraphWrapper Graph; + Graph g(lg); + + //for UndirSageGraph + //typedef UndirSageGraph Graph; + //Graph g; + + typedef Graph::Node Node; + typedef Graph::NodeIt NodeIt; + typedef Graph::Edge Edge; + typedef Graph::EdgeIt EdgeIt; + typedef Graph::OutEdgeIt OutEdgeIt; + + 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; + int k; + 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"; + cout << "number of groups in LEDA random group graph="; + cin >> k; + cout << endl; + + leda_list lS; + leda_list lT; + random_bigraph(lg, a, b, m, lS, lT, k); + + Graph::NodeMap ref_map(g, -1); + IterableBoolMap< Graph::NodeMap > bipartite_map(ref_map); + + //generating leda random group graph + leda_node ln; + forall(ln, lS) bipartite_map.insert(ln, false); + forall(ln, lT) bipartite_map.insert(ln, true); + + //making bipartite graph + typedef BipartiteGraphWrapper BGW; + BGW bgw(g, bipartite_map); + + + //st-wrapper + typedef stBipartiteGraphWrapper stGW; + stGW stgw(bgw); + ConstMap const1map(1); + stGW::EdgeMap flow(stgw); + + Timer ts; + + ts.reset(); + FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0); + MaxFlow, stGW::EdgeMap > + max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow/*, true*/); + max_flow_test.run(); + cout << "HUGO max matching algorithm based on preflow." << endl + << "Size of matching: " + << max_flow_test.flowValue() << endl; + cout << "elapsed time: " << ts << endl << endl; + + ts.reset(); + leda_list ml=MAX_CARD_BIPARTITE_MATCHING(lg); + cout << "LEDA max matching algorithm." << endl + << "Size of matching: " + << ml.size() << endl; + cout << "elapsed time: " << ts << endl << endl; + +// ts.reset(); +// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0); +// typedef SageGraph MutableGraph; +// while (max_flow_test.augmentOnBlockingFlow()) { } +// cout << "HUGO max matching algorithm based on blocking flow augmentation." +// << endl << "Matching size: " +// << max_flow_test.flowValue() << endl; +// cout << "elapsed time: " << ts << endl << endl; + + { + SageGraph hg; + SageGraph::Node s=hg.addNode(); + SageGraph::Node t=hg.addNode(); + BGW::NodeMap b_s_nodes(bgw); + BGW::NodeMap b_t_nodes(bgw); + + FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, BGW::S_CLASS) { + b_s_nodes.set(n, hg.addNode()); + hg.addEdge(s, b_s_nodes[n]); + } + FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, BGW::T_CLASS) { + b_t_nodes.set(n, hg.addNode()); + hg.addEdge(b_t_nodes[n], t); + } + + FOR_EACH_LOC(BGW::EdgeIt, e, bgw) + hg.addEdge(b_s_nodes[bgw.tail(e)], b_t_nodes[bgw.head(e)]); + + ConstMap cm(1); + SageGraph::EdgeMap flow(hg); //0 + + Timer ts; + + ts.reset(); + MaxFlow, + SageGraph::EdgeMap > + max_flow_test(hg, s, t, cm, flow); + max_flow_test.run(); + cout << "HUGO max matching algorithm on SageGraph by copying the graph, based on preflow." + << endl + << "Size of matching: " + << max_flow_test.flowValue() << endl; + cout << "elapsed time: " << ts << endl << endl; + } + + return 0; +} diff -r 6387df9aadb0 -r ad7dff9ee2fd src/work/marci/leda/comparison.cc --- a/src/work/marci/leda/comparison.cc Mon Aug 23 11:28:26 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +0,0 @@ -// -*- c++ -*- -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -//#include -//#include -#include -#include -#include -#include -#include -#include - -using std::cin; -using std::cout; -using std::endl; - -using namespace hugo; - -int main() { - //for leda graph - leda::graph lg; - //lg.make_undirected(); - typedef LedaGraphWrapper Graph; - Graph g(lg); - - //for UndirSageGraph - //typedef UndirSageGraph Graph; - //Graph g; - - typedef Graph::Node Node; - typedef Graph::NodeIt NodeIt; - typedef Graph::Edge Edge; - typedef Graph::EdgeIt EdgeIt; - typedef Graph::OutEdgeIt OutEdgeIt; - - 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; - int k; - 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"; - cout << "number of groups in LEDA random group graph="; - cin >> k; - cout << endl; - - leda_list lS; - leda_list lT; - random_bigraph(lg, a, b, m, lS, lT, k); - - Graph::NodeMap ref_map(g, -1); - IterableBoolMap< Graph::NodeMap > bipartite_map(ref_map); - - //generating leda random group graph - leda_node ln; - forall(ln, lS) bipartite_map.insert(ln, false); - forall(ln, lT) bipartite_map.insert(ln, true); - - //making bipartite graph - typedef BipartiteGraphWrapper BGW; - BGW bgw(g, bipartite_map); - - - //st-wrapper - typedef stBipartiteGraphWrapper stGW; - stGW stgw(bgw); - ConstMap const1map(1); - stGW::EdgeMap flow(stgw); - - Timer ts; - - ts.reset(); - FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0); - MaxFlow, stGW::EdgeMap > - max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow/*, true*/); - max_flow_test.run(); - cout << "HUGO max matching algorithm based on preflow." << endl - << "Size of matching: " - << max_flow_test.flowValue() << endl; - cout << "elapsed time: " << ts << endl << endl; - - ts.reset(); - leda_list ml=MAX_CARD_BIPARTITE_MATCHING(lg); - cout << "LEDA max matching algorithm." << endl - << "Size of matching: " - << ml.size() << endl; - cout << "elapsed time: " << ts << endl << endl; - -// ts.reset(); -// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0); -// typedef SageGraph MutableGraph; -// while (max_flow_test.augmentOnBlockingFlow()) { } -// cout << "HUGO max matching algorithm based on blocking flow augmentation." -// << endl << "Matching size: " -// << max_flow_test.flowValue() << endl; -// cout << "elapsed time: " << ts << endl << endl; - - { - SageGraph hg; - SageGraph::Node s=hg.addNode(); - SageGraph::Node t=hg.addNode(); - BGW::NodeMap b_s_nodes(bgw); - BGW::NodeMap b_t_nodes(bgw); - - FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, BGW::S_CLASS) { - b_s_nodes.set(n, hg.addNode()); - hg.addEdge(s, b_s_nodes[n]); - } - FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, BGW::T_CLASS) { - b_t_nodes.set(n, hg.addNode()); - hg.addEdge(b_t_nodes[n], t); - } - - FOR_EACH_LOC(BGW::EdgeIt, e, bgw) - hg.addEdge(b_s_nodes[bgw.tail(e)], b_t_nodes[bgw.head(e)]); - - ConstMap cm(1); - SageGraph::EdgeMap flow(hg); //0 - - Timer ts; - - ts.reset(); - MaxFlow, - SageGraph::EdgeMap > - max_flow_test(hg, s, t, cm, flow); - max_flow_test.run(); - cout << "HUGO max matching algorithm on SageGraph by copying the graph, based on preflow." - << endl - << "Size of matching: " - << max_flow_test.flowValue() << endl; - cout << "elapsed time: " << ts << endl << endl; - } - - return 0; -} diff -r 6387df9aadb0 -r ad7dff9ee2fd src/work/marci/leda/makefile --- a/src/work/marci/leda/makefile Mon Aug 23 11:28:26 2004 +0000 +++ b/src/work/marci/leda/makefile Mon Aug 23 11:44:36 2004 +0000 @@ -4,7 +4,7 @@ INCLUDEDIRS ?= -I. -I../.. -I../../{marci,jacint,alpar,klao,akos,athos} -I$(LEDAROOT)/incl -I../../.. LDFLAGS = -L$(LEDAROOT) -lG -lL -lm -BINARIES = bipartite_matching_leda bipartite_matching_leda_gen comparison +BINARIES = bipartite_matching_leda bipartite_matching_leda_gen bipartite_matching_comparison include ../../makefile diff -r 6387df9aadb0 -r ad7dff9ee2fd src/work/marci/leda/max_bipartite_matching_demo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/leda/max_bipartite_matching_demo.cc Mon Aug 23 11:44:36 2004 +0000 @@ -0,0 +1,218 @@ +// -*- 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< -#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<