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

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


Author: marci
Date: Tue Sep 28 15:45:39 2004
New Revision: 1226

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

Log:
beginning of a modular, generic merge_graph_wrapper...


Modified: hugo/trunk/src/work/marci/makefile
==============================================================================
--- hugo/trunk/src/work/marci/makefile	(original)
+++ hugo/trunk/src/work/marci/makefile	Tue Sep 28 15:45:39 2004
@@ -4,7 +4,7 @@
 INCLUDEDIRS ?= -I../{jacint,marci,alpar,klao,akos,athos} -I../.. -I.. -I$(BOOSTROOT)
 
 LEDABINARIES = leda_graph_demo leda_bfs_dfs max_bipartite_matching_demo
-BINARIES = sub_graph_wrapper_demo.cc graph_wrapper_time max_flow_demo iterator_bfs_demo macro_test lg_vs_sg_vs_sg bfsit_vs_byhand bipartite_graph_wrapper_test bipartite_matching_demo top_sort_test max_flow_1 proba7 proba10
+BINARIES = merge_node_graph_wrapper_test#sub_graph_wrapper_demo.cc graph_wrapper_time max_flow_demo iterator_bfs_demo macro_test lg_vs_sg_vs_sg bfsit_vs_byhand bipartite_graph_wrapper_test bipartite_matching_demo top_sort_test max_flow_1 proba7 proba10 
 #BINARIES = preflow_bug
 #gw_vs_not preflow_demo_boost edmonds_karp_demo_boost preflow_demo_jacint preflow_demo_athos edmonds_karp_demo_alpar preflow_demo_leda
 

Added: hugo/trunk/src/work/marci/merge_node_graph_wrapper.h
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/marci/merge_node_graph_wrapper.h	Tue Sep 28 15:45:39 2004
@@ -0,0 +1,123 @@
+/* -*- C++ -*-
+ * src/hugo/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).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#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> 
+  class MergeNodeGraphWrapper : 
+    public GraphWrapper<Graph1>, public GraphWrapper<Graph2> {
+    typedef GraphWrapper<Graph1> Parent1;
+    typedef GraphWrapper<Graph2> Parent2;
+    typedef typename GraphWrapper<Graph1>::Node Graph1Node;
+    typedef typename GraphWrapper<Graph2>::Node Graph2Node;
+  public:
+    class Node;
+    class NodeIt;
+    friend class Node;
+    friend class NodeIt;
+
+    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;
+    protected:
+      bool backward; //true, iff backward
+    public:
+      Node() { }
+      /// \todo =false is needed, or causes problems?
+      /// If \c _backward is false, then we get an edge corresponding to the 
+      /// original one, otherwise its oppositely directed pair is obtained.
+      Node(const Graph1Node& n1, 
+	   const Graph2Node& n2, bool _backward) : 
+	Graph1Node(n1), Graph2Node(n2), backward(_backward) { }
+      Node(Invalid i) : Graph1Node(i), Graph2Node(i), backward(true) { }
+      bool operator==(const Node& v) const { 
+	return (this->backward==v.backward && 
+		static_cast<Graph1Node>(*this)==
+		static_cast<Graph1Node>(v) && 
+		static_cast<Graph2Node>(*this)==
+		static_cast<Graph2Node>(v));
+      } 
+      bool operator!=(const Node& v) const { 
+	return (this->backward!=v.backward || 
+		static_cast<Graph1Node>(*this)!=
+		static_cast<Graph1Node>(v) || 
+		static_cast<Graph2Node>(*this)!=
+		static_cast<Graph2Node>(v));
+      }
+    };
+
+    class NodeIt : public Node {
+      friend class MergeNodeGraphWrapper<Graph1, Graph2>;
+    protected:
+      const MergeNodeGraphWrapper<Graph1, Graph2>* gw;
+    public:
+      NodeIt() { }
+      NodeIt(Invalid i) : Node(i) { }
+      NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw) : 
+	Node(typename Graph1::NodeIt(*_gw.Parent1::graph), 
+	     typename Graph2::NodeIt(),
+	     false), gw(&_gw) { 
+	if (*static_cast<Graph1Node*>(this)==INVALID) {
+	  *static_cast<Node*>(this)=
+	    Node(Graph1Node(INVALID), 
+		 typename Graph2::NodeIt(*_gw.Parent2::graph), 
+		 true);
+	}
+      }
+      NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw, 
+	     const Node& n) : 
+	Node(n), gw(&_gw) { }
+      NodeIt& operator++() { 
+	if (!this->backward) {
+	  *(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);
+	  }
+	} else {
+	  *(static_cast<Graph2Node*>(this))=
+	    ++(typename Graph2::NodeIt(*gw->Parent2::graph, *this));
+	}
+	return *this;
+      }
+    };
+
+    int id(const Node& n) const { 
+      if (!n.backward) 
+	return this->Parent1::graph->id(n);
+      else
+	return this->Parent2::graph->id(n);
+    }
+
+  };
+
+} //namespace hugo
+
+#endif //HUGO_MERGE_NODE_GRAPH_WRAPPER_H

Added: hugo/trunk/src/work/marci/merge_node_graph_wrapper_test.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/marci/merge_node_graph_wrapper_test.cc	Tue Sep 28 15:45:39 2004
@@ -0,0 +1,26 @@
+#include <iostream>
+
+#include <hugo/list_graph.h>
+#include <hugo/smart_graph.h>
+#include <merge_node_graph_wrapper.h>
+
+using std::cout;
+using std::endl;
+
+using namespace hugo;
+
+int main() {
+  SmartGraph g;
+  ListGraph h;
+  typedef MergeNodeGraphWrapper<SmartGraph, ListGraph> GW;
+  GW gw(g, h);
+  g.addNode();
+  g.addNode();
+  g.addNode();
+  h.addNode();
+  h.addNode();
+  //GW::NodeIt n(gw)
+  for (GW::NodeIt n(gw); n!=INVALID; ++n) { 
+    cout << gw.id(n) << endl;
+  }
+}



More information about the Lemon-commits mailing list