[Lemon-commits] [lemon_svn] klao: r1265 - in hugo/branches/graph_factory/src: lemon/skeletons test

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


Author: klao
Date: Tue Oct  5 02:03:36 2004
New Revision: 1265

Added:
   hugo/branches/graph_factory/src/test/new_graph_test.cc
Modified:
   hugo/branches/graph_factory/src/lemon/skeletons/graph.h
   hugo/branches/graph_factory/src/test/   (props changed)
   hugo/branches/graph_factory/src/test/Makefile.am

Log:
Some preliminary concepts for the GraphBase and GraphFactory approach.

   * skeletons/graph.h: BaseGraphItem, GraphMap, GraphNode,
     BaseGraphItemConcept classes.
   * test/: first example for using concept checking classes.


Modified: hugo/branches/graph_factory/src/lemon/skeletons/graph.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/skeletons/graph.h	(original)
+++ hugo/branches/graph_factory/src/lemon/skeletons/graph.h	Tue Oct  5 02:03:36 2004
@@ -501,6 +501,127 @@
       void erase(Edge e) { }
     };
 
+
+
+
+    /************* New GraphBase stuff **************/
+
+
+    class BaseGraphItem {
+    public:
+      BaseGraphItem() {}
+      BaseGraphItem(Invalid) {}
+
+      // We explicitely list these:
+      BaseGraphItem(BaseGraphItem const&) {}
+      BaseGraphItem& operator=(BaseGraphItem const&) { return *this; }
+
+      bool operator==(BaseGraphItem) const { return false; }
+      bool operator!=(BaseGraphItem) const { return false; }
+
+      // Technical requirement. Do we really need this?
+      bool operator<(BaseGraphItem) const { return false; }
+    };
+
+
+    template<typename Item, typename T, typename Graph>
+    class GraphMap : public ReadWriteMap<Item, T> {
+      // I really, really don't like the idea that every graph should have
+      // reference maps! --klao
+
+    private:
+      // We state explicitly that graph maps have no default constructor?
+      GraphMap();
+
+    public:
+      explicit GraphMap(Graph const&) {}
+      // value for initializing
+      GraphMap(Graph const&, T) {}
+
+      // this probably should be required:
+      GraphMap(GraphMap const&) {}
+      GraphMap& operator=(GraphMap const&) { return *this; }
+
+      // but this is a absolute no-op! We should provide a more generic
+      // graph-map-copy operation.
+      //
+      // template<typename TT>
+      // GraphMap(GraphMap<TT> const&);
+      //
+      // template<typename TT>
+      // GraphMap& operator=(const GraphMap<TT>&);
+    };
+
+
+    /// A minimal GraphBase concept
+
+    /// This class describes a minimal concept which can be extended to a
+    /// full-featured graph with \ref GraphFactory.
+    class GraphBase {
+    public:
+
+      GraphBase() {}
+      
+      class Node : public BaseGraphItem {};
+      class Edge : public BaseGraphItem {};
+
+      // Graph operation
+      Node& first(Node &n) const { return n; }
+      Edge& first(Edge &e) const { return e; }
+
+      Edge& firstOut(Edge &e, Node) const { return e; }
+      Edge& firstIn(Edge &e, Node) const { return e; }
+
+      Node& next(Node &n) const { return n; }
+      Edge& next(Edge &e) const { return e; }
+
+
+      // Question: isn't it reasonable if this methods have a Node
+      // parameter? Like this:
+      // Edge& nextOut(Edge &e, Node) const { return e; }
+      Edge& nextOut(Edge &e) const { return e; }
+      Edge& nextIn(Edge &e) const { return e; }
+
+      Node head(Edge) const { return Node(); }
+      Node tail(Edge) const { return Node(); }
+      
+
+      // ... Egyeb sallang, mint az id, nodeNum, edgeNum kell ide?
+
+
+      // Maps.
+      //
+      // We need a special slimer concept which does not provide maps (it
+      // wouldn't be strictly slimer, cause for map-factory id() & friends
+      // a required...)
+
+      template<typename T>
+      class NodeMap : public GraphMap<Node, T, GraphBase> {};
+
+      template<typename T>
+      class EdgeMap : public GraphMap<Edge, T, GraphBase> {};
+    };
+
+
+
+    /**************** Concept checking classes ****************/
+
+    template<typename BGI>
+    struct BaseGraphItemConcept {
+      void constraints() {
+	BGI i1;
+	BGI i2 = i1;
+	BGI i3 = INVALID;
+	
+	i1 = i3;
+	if( i1 == i3 ) {
+	  if ( i2 != i3 && i3 < i2 )
+	    return;
+	}
+      }
+    };
+
+
     // @}
   } //namespace skeleton  
 } //namespace lemon

Modified: hugo/branches/graph_factory/src/test/Makefile.am
==============================================================================
--- hugo/branches/graph_factory/src/test/Makefile.am	(original)
+++ hugo/branches/graph_factory/src/test/Makefile.am	Tue Oct  5 02:03:36 2004
@@ -12,6 +12,7 @@
 	graph_wrapper_test \
 	kruskal_test \
 	min_cost_flow_test \
+	new_graph_test \
 	suurballe_test \
 	path_test \
 	preflow_test \
@@ -31,6 +32,7 @@
 graph_wrapper_test_SOURCES = graph_wrapper_test.cc
 kruskal_test_SOURCES = kruskal_test.cc
 min_cost_flow_test_SOURCES = min_cost_flow_test.cc
+new_graph_test_SOURCES = new_graph_test.cc
 suurballe_test_SOURCES = suurballe_test.cc
 path_test_SOURCES = path_test.cc
 preflow_test_SOURCES = preflow_test.cc

Added: hugo/branches/graph_factory/src/test/new_graph_test.cc
==============================================================================
--- (empty file)
+++ hugo/branches/graph_factory/src/test/new_graph_test.cc	Tue Oct  5 02:03:36 2004
@@ -0,0 +1,39 @@
+/* -*- C++ -*-
+ * src/test/new_graph_test.cc - Part of LEMON, 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 <lemon/skeletons/graph.h>
+// #include <boost/concept_check.hpp>
+
+using namespace lemon::skeleton;
+
+// Borrowed from boost:
+template <class T> inline void ignore_unused_variable_warning(const T&) { }
+
+int main()
+{
+  //    This is the "right" way to check a concept:
+  // boost::function_requires< BaseGraphItemConcept<BaseGraphItem> >();
+
+  //    which is equivalent (considering compile-time checks) to
+  // BaseGraphItemConcept<BaseGraphItem> bgic;
+  // bgic.constraints();
+  //    but not actually call or intatiates anything...
+  //    It's doing aproximately this:
+  typedef BaseGraphItemConcept<BaseGraphItem> CC;
+  void (CC::*x)() = &CC::constraints;
+  ignore_unused_variable_warning(x);
+  //    But even more hackish...
+}



More information about the Lemon-commits mailing list