[Lemon-commits] [lemon_svn] marci: r672 - hugo/trunk/src/work/marci

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:40:53 CET 2006


Author: marci
Date: Mon May  3 13:43:27 2004
New Revision: 672

Modified:
   hugo/trunk/src/work/marci/bipartite_matching_try_3.cc

Log:
bip matching...


Modified: hugo/trunk/src/work/marci/bipartite_matching_try_3.cc
==============================================================================
--- hugo/trunk/src/work/marci/bipartite_matching_try_3.cc	(original)
+++ hugo/trunk/src/work/marci/bipartite_matching_try_3.cc	Mon May  3 13:43:27 2004
@@ -43,12 +43,6 @@
 template <typename Graph, typename EdgeCap, typename NodeCap, 
 	  typename EdgeFlow, typename NodeFlow>
 class MaxMatching {
-// : public MaxFlow<stGraphWrapper<Graph>, 
-// 				   stGraphWrapper<Graph>:: EdgeMapWrapper<EdgeCan, NodeCap>, stGraphWrapper<Graph>::EdgeMapWrapper<EdgeFlow, NodeFlow> > {
-//   typedef MaxFlow<stGraphWrapper<Graph>, 
-// 		  stGraphWrapper<Graph>::EdgeMapWrapper<EdgeCan, NodeCap>, 
-// 		  stGraphWrapper<Graph>::EdgeMapWrapper<EdgeFlow, NodeFlow> >
-//   Parent;
 protected:
 //   EdgeCap* edge_cap;
 //   NodeCap* node_cap;
@@ -58,6 +52,7 @@
   stGW stgw;
   typedef typename stGW::template EdgeMapWrapper<EdgeCap, NodeCap> CapMap; 
   CapMap cap;
+  NodeFlow* node_flow;
   typedef typename stGW::template EdgeMapWrapper<EdgeFlow, NodeFlow> FlowMap;
   FlowMap flow;
   MaxFlow<stGW, int, CapMap, FlowMap> 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 << "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 << "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 << "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 << "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;
 
   typedef stGraphWrapper<Graph> 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<Graph::Edge, int> 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<Graph, ConstMap<Graph::Edge, int>, ConstMap<Graph::Node, int>, 
+    Graph::EdgeMap<int>, Graph::NodeMap<int> > 
+    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;
 }



More information about the Lemon-commits mailing list