# HG changeset patch # User marci # Date 1083075019 0 # Node ID 77ef5c7a57d96adff1b54c10a521b9e305b29c21 # Parent 6fe0d7d7067415e30cf6ae7a890b570b5cfb450b comparison for matchings with leda diff -r 6fe0d7d70674 -r 77ef5c7a57d9 src/work/marci/leda/bipartite_matching_leda.cc --- a/src/work/marci/leda/bipartite_matching_leda.cc Tue Apr 27 13:53:27 2004 +0000 +++ b/src/work/marci/leda/bipartite_matching_leda.cc Tue Apr 27 14:10:19 2004 +0000 @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -89,88 +90,15 @@ 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 stGraphWrapper 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(); diff -r 6fe0d7d70674 -r 77ef5c7a57d9 src/work/marci/leda/bipartite_matching_leda_gen.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/leda/bipartite_matching_leda_gen.cc Tue Apr 27 14:10:19 2004 +0000 @@ -0,0 +1,158 @@ +// -*- c++ -*- +#include +#include +#include +#include + +#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() { + //for leda graph + leda::graph lg; + //lg.make_undirected(); + typedef LedaGraphWrapper Graph; + Graph g(lg); + + //for UndirListGraph + //typedef UndirListGraph 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; + 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; + int k; + std::cout << "number of groups in LEDA random group graph="; + std::cin >> k; + + leda_list lS; + leda_list lT; + random_bigraph(lg, a, b, m, lS, lT, k); + +// 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); + + // BGW::NodeMap dbyj(bgw); + // BGW::EdgeMap dbyxcj(bgw); + + typedef stGraphWrapper stGW; + stGW stgw(bgw); + ConstMap const1map(1); + stGW::EdgeMap flow(stgw); + + Timer ts; + FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0); + ts.reset(); + // stGW::EdgeMap pre_flow(stgw); + Preflow, stGW::EdgeMap > + pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow, true); + pre_flow_test.run(); + std::cout << "HUGO pre flow value: " << pre_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"; + + ts.reset(); + leda_list ml=MAX_CARD_BIPARTITE_MATCHING(lg); + // stGW::EdgeMap pre_flow(stgw); + //Preflow, stGW::EdgeMap > + // pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, pre_flow, true); + //pre_flow_test.run(); + std::cout << "LEDA matching value: " << ml.size() << 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"; + + FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0); + ts.reset(); + MaxFlow, stGW::EdgeMap > + max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow); +// while (max_flow_test.augmentOnShortestPath()) { } + typedef ListGraph MutableGraph; +// while (max_flow_test.augmentOnBlockingFlow1()) { + while (max_flow_test.augmentOnBlockingFlow2()) { + std::cout << max_flow_test.flowValue() << std::endl; + } + std::cout << "HUGO blocking 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"; + + return 0; +} diff -r 6fe0d7d70674 -r 77ef5c7a57d9 src/work/marci/leda/leda_graph_wrapper.h --- a/src/work/marci/leda/leda_graph_wrapper.h Tue Apr 27 13:53:27 2004 +0000 +++ b/src/work/marci/leda/leda_graph_wrapper.h Tue Apr 27 14:10:19 2004 +0000 @@ -63,6 +63,7 @@ protected: template friend class NodeMap; leda_node _n; + public: //FIXME Node(leda_node __n) : _n(__n) { } public: /// @warning The default constructor sets the iterator @@ -95,6 +96,7 @@ protected: template friend class EdgeMap; leda_edge _e; + public: //FIXME Edge(leda_edge __e) : _e(__e) { } public: /// @warning The default constructor sets the iterator diff -r 6fe0d7d70674 -r 77ef5c7a57d9 src/work/marci/leda/makefile --- a/src/work/marci/leda/makefile Tue Apr 27 13:53:27 2004 +0000 +++ b/src/work/marci/leda/makefile Tue Apr 27 14:10:19 2004 +0000 @@ -4,7 +4,7 @@ INCLUDEDIRS ?= -I../../../include -I../.. -I../../{marci,jacint,alpar,klao,akos,athos} -I$(LEDAROOT)/incl -I. LDFLAGS = -L$(LEDAROOT) -lG -lL -lm -BINARIES = bipartite_matching_leda +BINARIES = bipartite_matching_leda bipartite_matching_leda_gen include ../../makefile