# HG changeset patch # User marci # Date 1083584607 0 # Node ID d5fe2f3f95fc63070e21a562210b09e1b6bee1bd # Parent 325c9430723e13e10537cbf28308e2cb598f037b bip matching... diff -r 325c9430723e -r d5fe2f3f95fc src/work/marci/bipartite_matching_try_3.cc --- a/src/work/marci/bipartite_matching_try_3.cc Mon May 03 10:27:20 2004 +0000 +++ b/src/work/marci/bipartite_matching_try_3.cc Mon May 03 11:43:27 2004 +0000 @@ -43,12 +43,6 @@ template class MaxMatching { -// : public MaxFlow, -// stGraphWrapper:: EdgeMapWrapper, stGraphWrapper::EdgeMapWrapper > { -// typedef MaxFlow, -// stGraphWrapper::EdgeMapWrapper, -// stGraphWrapper::EdgeMapWrapper > -// Parent; protected: // EdgeCap* edge_cap; // NodeCap* node_cap; @@ -58,6 +52,7 @@ stGW stgw; typedef typename stGW::template EdgeMapWrapper CapMap; CapMap cap; + NodeFlow* node_flow; typedef typename stGW::template EdgeMapWrapper FlowMap; FlowMap flow; MaxFlow mf; @@ -68,8 +63,18 @@ MaxMatching(Graph& _g, EdgeCap& _edge_cap, NodeCap& _node_cap, EdgeFlow& _edge_flow, NodeFlow& _node_flow) : stgw(_g), - cap(_edge_cap, _node_cap), flow(_edge_flow, _node_flow), + cap(_edge_cap, _node_cap), + node_flow(0), + flow(_edge_flow, _node_flow), mf(stgw, stgw.S_NODE, stgw.T_NODE, cap, flow) { } + MaxMatching(Graph& _g, EdgeCap& _edge_cap, NodeCap& _node_cap, + EdgeFlow& _edge_flow/*, NodeFlow& _node_flow*/) : + stgw(_g), + cap(_edge_cap, _node_cap), + node_flow(new NodeFlow(_g)), + flow(_edge_flow, *node_flow), + mf(stgw, stgw.S_NODE, stgw.T_NODE, cap, flow) { } + ~MaxMatching() { if (node_flow) delete node_flow; } void run() { mf.run(); } int matchingValue() { return mf.flowValue(); } }; @@ -130,34 +135,34 @@ g.addEdge(s_nodes[random(a)], t_nodes[random(b)]); } - std::cout << "Edges of the bipartite graph:" << std::endl; - FOR_EACH_LOC(EdgeIt, e, g) std::cout << e << " "; - std::cout << std::endl; +// std::cout << "Edges of the bipartite graph:" << std::endl; +// FOR_EACH_LOC(EdgeIt, e, g) std::cout << e << " "; +// std::cout << std::endl; - std::cout << "Nodes:" << std::endl; - FOR_EACH_LOC(Graph::NodeIt, v, g) std::cout << v << " "; - std::cout << std::endl; - std::cout << "Nodes in T:" << std::endl; - FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " "; - std::cout << std::endl; - std::cout << "Nodes in S:" << std::endl; - FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " "; - std::cout << std::endl; +// std::cout << "Nodes:" << std::endl; +// FOR_EACH_LOC(Graph::NodeIt, v, g) std::cout << v << " "; +// std::cout << std::endl; +// std::cout << "Nodes in T:" << std::endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " "; +// std::cout << std::endl; +// std::cout << "Nodes in S:" << std::endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " "; +// std::cout << std::endl; - std::cout << "Erasing the first node..." << std::endl; - NodeIt n; - g.first(n); - g.erase(n); - std::cout << "Nodes of the bipartite graph:" << std::endl; - FOR_EACH_GLOB(n, g) std::cout << n << " "; - std::cout << std::endl; +// std::cout << "Erasing the first node..." << std::endl; +// NodeIt n; +// g.first(n); +// g.erase(n); +// std::cout << "Nodes of the bipartite graph:" << std::endl; +// FOR_EACH_GLOB(n, g) std::cout << n << " "; +// std::cout << std::endl; - std::cout << "Nodes in T:" << std::endl; - FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " "; - std::cout << std::endl; - std::cout << "Nodes in S:" << std::endl; - FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " "; - std::cout << std::endl; +// std::cout << "Nodes in T:" << std::endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " "; +// std::cout << std::endl; +// std::cout << "Nodes in S:" << std::endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " "; +// std::cout << std::endl; typedef stGraphWrapper stGW; stGW stgw(g); @@ -177,9 +182,9 @@ // } 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) { - if (flow[e]) std::cout << e << std::endl; - } +// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { +// if (flow[e]) std::cout << e << std::endl; +// } std::cout << std::endl; typedef ConstMap EdgeCap; @@ -229,5 +234,21 @@ // if (gef[e]) std::cout << e << std::endl; // } std::cout << std::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); + MaxMatching, ConstMap, + Graph::EdgeMap, Graph::NodeMap > + matching_test_1(g, ge1, gn1, gef/*, gnf*/); + matching_test_1.run(); + + std::cout << "max flow value: " << matching_test_1.matchingValue() << std::endl; + std::cout << "elapsed time: " << ts << std::endl; +// FOR_EACH_LOC(Graph::EdgeIt, e, g) { +// if (gef[e]) std::cout << e << std::endl; +// } + std::cout << std::endl; + return 0; }