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

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


Author: marci
Date: Tue Sep 28 19:00:18 2004
New Revision: 1228

Modified:
   hugo/trunk/src/work/marci/merge_node_graph_wrapper.h
   hugo/trunk/src/work/marci/merge_node_graph_wrapper_test.cc

Log:
merge_node_graph_wrapper::nodemap


Modified: hugo/trunk/src/work/marci/merge_node_graph_wrapper.h
==============================================================================
--- hugo/trunk/src/work/marci/merge_node_graph_wrapper.h	(original)
+++ hugo/trunk/src/work/marci/merge_node_graph_wrapper.h	Tue Sep 28 19:00:18 2004
@@ -1,5 +1,5 @@
 /* -*- C++ -*-
- * src/hugo/graph_wrapper.h - Part of HUGOlib, a generic C++ optimization library
+ * src/hugo/merge_node_graph_wrapper.h - Part of HUGOlib, a generic C++ optimization library
  *
  * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
  * (Egervary Combinatorial Optimization Research Group, EGRES).
@@ -14,18 +14,18 @@
  *
  */
 
+#ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H
+#define HUGO_MERGE_NODE_GRAPH_WRAPPER_H
+
 #include <hugo/invalid.h>
 #include <hugo/maps.h>
 #include <hugo/map_defines.h>
 #include <hugo/graph_wrapper.h>
 #include <iostream>
 
-#ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H
-#define HUGO_MERGE_NODE_GRAPH_WRAPPER_H
-
 namespace hugo {
 
-  template <typename Graph1, typename Graph2> 
+  template <typename Graph1, typename Graph2, typename Enable=void> 
   class MergeNodeGraphWrapper : 
     public GraphWrapper<Graph1>, public GraphWrapper<Graph2> {
     typedef GraphWrapper<Graph1> Parent1;
@@ -37,13 +37,14 @@
     class NodeIt;
     friend class Node;
     friend class NodeIt;
+    template<typename Value> class NodeMap;
 
     MergeNodeGraphWrapper(Graph1& _graph1, Graph2& _graph2) : 
       Parent1(_graph1), Parent2(_graph2) { }
 
     class Node : public Graph1Node, public Graph2Node {
       friend class MergeNodeGraphWrapper<Graph1, Graph2>;
-      //template<typename T> friend class NodeMap;
+      template<typename Value> friend class NodeMap;
     protected:
       bool backward; //true, iff backward
     public:
@@ -80,13 +81,16 @@
       NodeIt(Invalid i) : Node(i) { }
       NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw) : 
 	Node(typename Graph1::NodeIt(*_gw.Parent1::graph), 
-	     typename Graph2::NodeIt(),
+	     typename Graph2::Node(),
 	     false), gw(&_gw) { 
 	if (*static_cast<Graph1Node*>(this)==INVALID) {
-	  *static_cast<Node*>(this)=
-	    Node(Graph1Node(INVALID), 
-		 typename Graph2::NodeIt(*_gw.Parent2::graph), 
-		 true);
+// 	  *static_cast<Node*>(this)=
+// 	    Node(Graph1Node(INVALID), 
+// 		 typename Graph2::NodeIt(*_gw.Parent2::graph), 
+// 		 true);
+	  *static_cast<Graph2Node*>(this)=
+	    typename Graph2::NodeIt(*_gw.Parent2::graph);
+	  backward=true;
 	}
       }
       NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw, 
@@ -97,9 +101,12 @@
 	  *(static_cast<Graph1Node*>(this))=
 	    ++(typename Graph1::NodeIt(*gw->Parent1::graph, *this));
 	  if (*static_cast<Graph1Node*>(this)==INVALID) {
-	    *static_cast<Node*>(this)=
-	      Node(typename Graph1::Node(INVALID), 
-		   typename Graph2::NodeIt(*gw->Parent2::graph), true);
+// 	    *static_cast<Node*>(this)=
+// 	      Node(typename Graph1::Node(INVALID), 
+// 		   typename Graph2::NodeIt(*gw->Parent2::graph), true);
+	    *static_cast<Graph2Node*>(this)=
+	      typename Graph2::NodeIt(*gw->Parent2::graph);
+	    backward=true;
 	  }
 	} else {
 	  *(static_cast<Graph2Node*>(this))=
@@ -116,6 +123,53 @@
 	return this->Parent2::graph->id(n);
     }
 
+    template <typename Value> 
+    class NodeMap : public Parent1::template NodeMap<Value>, 
+		    public Parent2::template NodeMap<Value> { 
+      typedef typename Parent1::template NodeMap<Value> ParentMap1;
+      typedef typename Parent2::template NodeMap<Value> ParentMap2;
+    public:
+      NodeMap(const MergeNodeGraphWrapper<Graph1, Graph2>& gw) : 
+	ParentMap1(gw), 
+	ParentMap2(gw) { }
+      NodeMap(const MergeNodeGraphWrapper<Graph1, Graph2>& gw, 
+	      const Value& value)
+	: ParentMap1(gw, value), 
+	  ParentMap2(gw, value) { }
+      NodeMap(const NodeMap& copy)
+	: ParentMap1(copy), 
+	  ParentMap2(copy) { }
+      template <typename TT>
+      NodeMap(const NodeMap<TT>& copy)
+	: ParentMap1(copy),
+	  ParentMap2(copy) { }
+      NodeMap& operator=(const NodeMap& copy) {
+	ParentMap1::operator=(copy);
+	ParentMap2::operator=(copy);
+	return *this;
+      }
+      template <typename TT>
+      NodeMap& operator=(const NodeMap<TT>& copy) {
+	ParentMap1::operator=(copy);
+	ParentMap2::operator=(copy);
+	return *this;
+      }
+      Value operator[](const Node& n) const {
+	if (!n.backward) 
+	  return ParentMap1::operator[](n);
+	else 
+	  return ParentMap2::operator[](n);
+      }
+      void set(const Node& n, const Value& value) {
+	if (!n.backward) 
+	  ParentMap1::set(n, value);
+	else 
+	  ParentMap2::set(n, value);
+      }
+      using ParentMap1::operator[];
+      using ParentMap2::operator[];
+    };
+    
   };
 
 } //namespace hugo

Modified: hugo/trunk/src/work/marci/merge_node_graph_wrapper_test.cc
==============================================================================
--- hugo/trunk/src/work/marci/merge_node_graph_wrapper_test.cc	(original)
+++ hugo/trunk/src/work/marci/merge_node_graph_wrapper_test.cc	Tue Sep 28 19:00:18 2004
@@ -10,17 +10,32 @@
 using namespace hugo;
 
 int main() {
-  SmartGraph g;
-  ListGraph h;
-  typedef MergeNodeGraphWrapper<SmartGraph, ListGraph> GW;
+  typedef SmartGraph Graph1;
+  typedef ListGraph Graph2;
+  Graph1 g;
+  Graph2 h;
+  typedef MergeNodeGraphWrapper<Graph1, Graph2> GW;
   GW gw(g, h);
-  g.addNode();
-  g.addNode();
-  g.addNode();
-  h.addNode();
-  h.addNode();
+  Graph1::Node n1=g.addNode();
+  Graph1::Node n2=g.addNode();
+  Graph1::Node n3=g.addNode();
+  Graph2::Node n4=h.addNode();
+  Graph2::Node n5=h.addNode();
   //GW::NodeIt n(gw)
   for (GW::NodeIt n(gw); n!=INVALID; ++n) { 
     cout << gw.id(n) << endl;
   }
+
+  GW::NodeMap<int> nm(gw);
+  int i=0;
+  for (GW::NodeIt n(gw); n!=INVALID; ++n) { 
+    ++i;
+    nm.set(n, i);
+  }
+  for (Graph1::NodeIt n(g); n!=INVALID; ++n) { 
+    cout << nm[n] << endl;
+  }
+  for (Graph2::NodeIt n(h); n!=INVALID; ++n) { 
+    cout << nm[n] << endl;
+  }
 }



More information about the Lemon-commits mailing list