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

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


Author: marci
Date: Fri Apr 30 19:10:01 2004
New Revision: 659

Modified:
   hugo/trunk/src/work/marci/bipartite_graph_wrapper.h
   hugo/trunk/src/work/marci/bipartite_matching_try_2.cc
   hugo/trunk/src/work/marci/graph_wrapper.h

Log:
A bipartite graph template can be used as BipartiteGraph<ListGraph>.


Modified: hugo/trunk/src/work/marci/bipartite_graph_wrapper.h
==============================================================================
--- hugo/trunk/src/work/marci/bipartite_graph_wrapper.h	(original)
+++ hugo/trunk/src/work/marci/bipartite_graph_wrapper.h	Fri Apr 30 19:10:01 2004
@@ -31,9 +31,9 @@
     SFalseTTrueMap;
     SFalseTTrueMap* s_false_t_true_map;
 
-    BipartiteGraphWrapper() : GraphWrapper<Graph>(0) { }
+    BipartiteGraphWrapper() : GraphWrapper<Graph>() { }
     void setSFalseTTrueMap(SFalseTTrueMap& _s_false_t_true_map) { 
-      s_false_t_true_map=_s_false_t_true_map;
+      s_false_t_true_map=&_s_false_t_true_map;
     }
 
   public:
@@ -196,11 +196,11 @@
   public:
     typedef typename Parent::Node Node;
     typedef typename Parent::Edge Edge;
-    BipartiteGraph() : BipartiteGraphWrapper<Graph>(0), 
+    BipartiteGraph() : BipartiteGraphWrapper<Graph>(), 
 		       gr(), bipartite_map(gr), 
 		       s_false_t_true_map(bipartite_map) { 
       Parent::setGraph(gr); 
-      Parent::setSFalseTTrueMap(bipartite_map);
+      Parent::setSFalseTTrueMap(s_false_t_true_map);
     }
 
     /// the \c bool parameter which can be \c S_Class or \c T_Class shows 

Modified: hugo/trunk/src/work/marci/bipartite_matching_try_2.cc
==============================================================================
--- hugo/trunk/src/work/marci/bipartite_matching_try_2.cc	(original)
+++ hugo/trunk/src/work/marci/bipartite_matching_try_2.cc	Fri Apr 30 19:10:01 2004
@@ -10,7 +10,6 @@
 #include <time_measure.h>
 #include <for_each_macros.h>
 #include <bfs_iterator.h>
-#include <graph_wrapper.h>
 #include <bipartite_graph_wrapper.h>
 #include <maps.h>
 #include <max_flow.h>
@@ -40,7 +39,9 @@
 using namespace hugo;
 
 int main() {
-  typedef UndirListGraph Graph; 
+  //typedef UndirListGraph Graph; 
+  typedef BipartiteGraph<ListGraph> Graph;
+  
   typedef Graph::Node Node;
   typedef Graph::NodeIt NodeIt;
   typedef Graph::Edge Edge;
@@ -63,108 +64,30 @@
   std::cin >> m; 
   
 
-  for (int i=0; i<a; ++i) s_nodes.push_back(g.addNode());
-  for (int i=0; i<b; ++i) t_nodes.push_back(g.addNode());
+  for (int i=0; i<a; ++i) s_nodes.push_back(g.addNode(false));
+  for (int i=0; i<b; ++i) t_nodes.push_back(g.addNode(true));
 
   random_init();
   for(int i=0; i<m; ++i) {
     g.addEdge(s_nodes[random(a)], t_nodes[random(b)]);
   }
 
-  Graph::NodeMap<int> ref_map(g, -1);
-
-  IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
-  for (int i=0; i<a; ++i) bipartite_map.insert(s_nodes[i], false);
-  for (int i=0; i<b; ++i) bipartite_map.insert(t_nodes[i], true);
-
-//   Graph::Node u;
-//   std::cout << "These nodes will be in S:\n";
-//   //FIXME azert kellene ++, es invalid vizsgalat u-bol, hogy ezt le lehessen 
-//   //irni 1etlen FOR_EACH-csel.
-//   for (bipartite_map.first(u, false); g.valid(u); bipartite_map.next(u)) 
-//     std::cout << u << " ";
-//   std::cout << "\n";
-//   std::cout << "These nodes will be in T:\n";
-//   for (bipartite_map.first(u, true); g.valid(u); bipartite_map.next(u)) 
-//     std::cout << u << " ";
-//   std::cout << "\n";
-
-  typedef BipartiteGraphWrapper<Graph> BGW;
-  BGW bgw(g, bipartite_map);
+  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 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<int> dbyj(bgw);
-//  BGW::EdgeMap<int> dbyxcj(bgw);
-
-  typedef stGraphWrapper<BGW> stGW;
-  stGW stgw(bgw);
+  typedef stGraphWrapper<Graph> stGW;
+  stGW stgw(g);
   ConstMap<stGW::Edge, int> const1map(1);
-//  stGW::NodeMap<int> ize(stgw);
 
-//   BfsIterator< BGW, BGW::NodeMap<bool> > 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<bool> 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<bool> > 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<int> max_flow(stgw);
+  stGW::EdgeMap<int> flow(stgw);
   MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> > 
-    max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, max_flow);
+    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<MutableGraph>()) {
@@ -173,10 +96,10 @@
   }
   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";
+  FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { 
+    if (flow[e]) std::cout << e << std::endl; 
+  }
+  std::cout << std::endl;
 
   ts.reset();
   stGW::EdgeMap<int> pre_flow(stgw);

Modified: hugo/trunk/src/work/marci/graph_wrapper.h
==============================================================================
--- hugo/trunk/src/work/marci/graph_wrapper.h	(original)
+++ hugo/trunk/src/work/marci/graph_wrapper.h	Fri Apr 30 19:10:01 2004
@@ -11,7 +11,7 @@
 ///\author Marton Makai
 
 #include <invalid.h>
-#include <iter_map.h>
+//#include <iter_map.h>
 
 namespace hugo {
 



More information about the Lemon-commits mailing list