[Lemon-commits] Alpar Juttner: Merge

Lemon HG hg at lemon.cs.elte.hu
Tue Dec 2 16:35:21 CET 2008


details:   http://lemon.cs.elte.hu/hg/lemon/rev/ad483acf1654
changeset: 434:ad483acf1654
user:      Alpar Juttner <alpar [at] cs.elte.hu>
date:      Tue Dec 02 15:33:22 2008 +0000
description:
	Merge

diffstat:

8 files changed, 6878 insertions(+)
doc/groups.dox                      |   73 
lemon/Makefile.am                   |    3 
lemon/adaptors.h                    | 3347 +++++++++++++++++++++++++++++++++++
lemon/bits/graph_adaptor_extender.h |  403 ++++
lemon/bits/variant.h                |  494 +++++
lemon/connectivity.h                | 1572 ++++++++++++++++
test/Makefile.am                    |    2 
test/graph_adaptor_test.cc          |  984 ++++++++++

diffs (truncated from 6946 to 300 lines):

diff -r d8b87e9b90c3 -r ad483acf1654 doc/groups.dox
--- a/doc/groups.dox	Tue Dec 02 11:01:48 2008 +0000
+++ b/doc/groups.dox	Tue Dec 02 15:33:22 2008 +0000
@@ -59,6 +59,79 @@
 with any graph structure.
 
 <b>See also:</b> \ref graph_concepts "Graph Structure Concepts".
+*/
+
+/**
+ at defgroup graph_adaptors Adaptor Classes for graphs
+ at ingroup graphs
+\brief This group contains several adaptor classes for digraphs and graphs
+
+The main parts of LEMON are the different graph structures, generic
+graph algorithms, graph concepts which couple these, and graph
+adaptors. While the previous notions are more or less clear, the
+latter one needs further explanation. Graph adaptors are graph classes
+which serve for considering graph structures in different ways.
+
+A short example makes this much clearer.  Suppose that we have an
+instance \c g of a directed graph type say ListDigraph and an algorithm
+\code
+template <typename Digraph>
+int algorithm(const Digraph&);
+\endcode
+is needed to run on the reverse oriented graph.  It may be expensive
+(in time or in memory usage) to copy \c g with the reversed
+arcs.  In this case, an adaptor class is used, which (according
+to LEMON digraph concepts) works as a digraph.  The adaptor uses the
+original digraph structure and digraph operations when methods of the
+reversed oriented graph are called.  This means that the adaptor have
+minor memory usage, and do not perform sophisticated algorithmic
+actions.  The purpose of it is to give a tool for the cases when a
+graph have to be used in a specific alteration.  If this alteration is
+obtained by a usual construction like filtering the arc-set or
+considering a new orientation, then an adaptor is worthwhile to use.
+To come back to the reverse oriented graph, in this situation
+\code
+template<typename Digraph> class ReverseDigraph;
+\endcode
+template class can be used. The code looks as follows
+\code
+ListDigraph g;
+ReverseDigraph<ListGraph> rg(g);
+int result = algorithm(rg);
+\endcode
+After running the algorithm, the original graph \c g is untouched.
+This techniques gives rise to an elegant code, and based on stable
+graph adaptors, complex algorithms can be implemented easily.
+
+In flow, circulation and bipartite matching problems, the residual
+graph is of particular importance. Combining an adaptor implementing
+this, shortest path algorithms and minimum mean cycle algorithms,
+a range of weighted and cardinality optimization algorithms can be
+obtained. For other examples, the interested user is referred to the
+detailed documentation of particular adaptors.
+
+The behavior of graph adaptors can be very different. Some of them keep
+capabilities of the original graph while in other cases this would be
+meaningless. This means that the concepts that they are models of depend
+on the graph adaptor, and the wrapped graph(s).
+If an arc of \c rg is deleted, this is carried out by deleting the
+corresponding arc of \c g, thus the adaptor modifies the original graph.
+
+But for a residual graph, this operation has no sense.
+Let us stand one more example here to simplify your work.
+RevGraphAdaptor has constructor
+\code
+ReverseDigraph(Digraph& digraph);
+\endcode
+This means that in a situation, when a <tt>const ListDigraph&</tt>
+reference to a graph is given, then it have to be instantiated with
+<tt>Digraph=const ListDigraph</tt>.
+\code
+int algorithm1(const ListDigraph& g) {
+  RevGraphAdaptor<const ListDigraph> rg(g);
+  return algorithm2(rg);
+}
+\endcode
 */
 
 /**
diff -r d8b87e9b90c3 -r ad483acf1654 lemon/Makefile.am
--- a/lemon/Makefile.am	Tue Dec 02 11:01:48 2008 +0000
+++ b/lemon/Makefile.am	Tue Dec 02 15:33:22 2008 +0000
@@ -16,6 +16,7 @@
 #lemon_libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS) $(SOPLEX_LIBS)
 
 lemon_HEADERS += \
+	lemon/adaptors.h \
         lemon/arg_parser.h \
 	lemon/assert.h \
         lemon/bfs.h \
@@ -60,10 +61,12 @@
         lemon/bits/bezier.h \
 	lemon/bits/default_map.h \
         lemon/bits/enable_if.h \
+	lemon/bits/graph_adaptor_extender.h \
 	lemon/bits/graph_extender.h \
 	lemon/bits/map_extender.h \
 	lemon/bits/path_dump.h \
 	lemon/bits/traits.h \
+	lemon/bits/variant.h \
 	lemon/bits/vector_map.h
 
 concept_HEADERS += \
diff -r d8b87e9b90c3 -r ad483acf1654 lemon/adaptors.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lemon/adaptors.h	Tue Dec 02 15:33:22 2008 +0000
@@ -0,0 +1,3347 @@
+/* -*- mode: C++; indent-tabs-mode: nil; -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library.
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, 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.
+ *
+ */
+
+#ifndef LEMON_ADAPTORS_H
+#define LEMON_ADAPTORS_H
+
+/// \ingroup graph_adaptors
+/// \file
+/// \brief Several graph adaptors
+///
+/// This file contains several useful adaptors for digraphs and graphs.
+
+#include <lemon/core.h>
+#include <lemon/maps.h>
+#include <lemon/bits/variant.h>
+
+#include <lemon/bits/graph_adaptor_extender.h>
+#include <lemon/tolerance.h>
+
+#include <algorithm>
+
+namespace lemon {
+
+  template<typename _Digraph>
+  class DigraphAdaptorBase {
+  public:
+    typedef _Digraph Digraph;
+    typedef DigraphAdaptorBase Adaptor;
+    typedef Digraph ParentDigraph;
+
+  protected:
+    Digraph* _digraph;
+    DigraphAdaptorBase() : _digraph(0) { }
+    void setDigraph(Digraph& digraph) { _digraph = &digraph; }
+
+  public:
+    DigraphAdaptorBase(Digraph& digraph) : _digraph(&digraph) { }
+
+    typedef typename Digraph::Node Node;
+    typedef typename Digraph::Arc Arc;
+
+    void first(Node& i) const { _digraph->first(i); }
+    void first(Arc& i) const { _digraph->first(i); }
+    void firstIn(Arc& i, const Node& n) const { _digraph->firstIn(i, n); }
+    void firstOut(Arc& i, const Node& n ) const { _digraph->firstOut(i, n); }
+
+    void next(Node& i) const { _digraph->next(i); }
+    void next(Arc& i) const { _digraph->next(i); }
+    void nextIn(Arc& i) const { _digraph->nextIn(i); }
+    void nextOut(Arc& i) const { _digraph->nextOut(i); }
+
+    Node source(const Arc& a) const { return _digraph->source(a); }
+    Node target(const Arc& a) const { return _digraph->target(a); }
+
+    typedef NodeNumTagIndicator<Digraph> NodeNumTag;
+    int nodeNum() const { return _digraph->nodeNum(); }
+
+    typedef EdgeNumTagIndicator<Digraph> EdgeNumTag;
+    int arcNum() const { return _digraph->arcNum(); }
+
+    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
+    Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
+      return _digraph->findArc(u, v, prev);
+    }
+
+    Node addNode() { return _digraph->addNode(); }
+    Arc addArc(const Node& u, const Node& v) { return _digraph->addArc(u, v); }
+
+    void erase(const Node& n) const { _digraph->erase(n); }
+    void erase(const Arc& a) const { _digraph->erase(a); }
+
+    void clear() const { _digraph->clear(); }
+
+    int id(const Node& n) const { return _digraph->id(n); }
+    int id(const Arc& a) const { return _digraph->id(a); }
+
+    Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
+    Arc arcFromId(int ix) const { return _digraph->arcFromId(ix); }
+
+    int maxNodeId() const { return _digraph->maxNodeId(); }
+    int maxArcId() const { return _digraph->maxArcId(); }
+
+    typedef typename ItemSetTraits<Digraph, Node>::ItemNotifier NodeNotifier;
+    NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
+
+    typedef typename ItemSetTraits<Digraph, Arc>::ItemNotifier ArcNotifier;
+    ArcNotifier& notifier(Arc) const { return _digraph->notifier(Arc()); }
+
+    template <typename _Value>
+    class NodeMap : public Digraph::template NodeMap<_Value> {
+    public:
+
+      typedef typename Digraph::template NodeMap<_Value> Parent;
+
+      explicit NodeMap(const Adaptor& adaptor)
+        : Parent(*adaptor._digraph) {}
+
+      NodeMap(const Adaptor& adaptor, const _Value& value)
+        : Parent(*adaptor._digraph, value) { }
+
+    private:
+      NodeMap& operator=(const NodeMap& cmap) {
+        return operator=<NodeMap>(cmap);
+      }
+
+      template <typename CMap>
+      NodeMap& operator=(const CMap& cmap) {
+        Parent::operator=(cmap);
+        return *this;
+      }
+
+    };
+
+    template <typename _Value>
+    class ArcMap : public Digraph::template ArcMap<_Value> {
+    public:
+
+      typedef typename Digraph::template ArcMap<_Value> Parent;
+
+      explicit ArcMap(const Adaptor& adaptor)
+        : Parent(*adaptor._digraph) {}
+
+      ArcMap(const Adaptor& adaptor, const _Value& value)
+        : Parent(*adaptor._digraph, value) {}
+
+    private:
+      ArcMap& operator=(const ArcMap& cmap) {
+        return operator=<ArcMap>(cmap);
+      }
+
+      template <typename CMap>
+      ArcMap& operator=(const CMap& cmap) {
+        Parent::operator=(cmap);
+        return *this;
+      }
+
+    };
+
+  };
+
+  template<typename _Graph>
+  class GraphAdaptorBase {
+  public:
+    typedef _Graph Graph;
+    typedef Graph ParentGraph;
+
+  protected:
+    Graph* _graph;
+
+    GraphAdaptorBase() : _graph(0) {}
+
+    void setGraph(Graph& graph) { _graph = &graph; }
+
+  public:
+    GraphAdaptorBase(Graph& graph) : _graph(&graph) {}
+
+    typedef typename Graph::Node Node;
+    typedef typename Graph::Arc Arc;
+    typedef typename Graph::Edge Edge;
+
+    void first(Node& i) const { _graph->first(i); }
+    void first(Arc& i) const { _graph->first(i); }
+    void first(Edge& i) const { _graph->first(i); }
+    void firstIn(Arc& i, const Node& n) const { _graph->firstIn(i, n); }
+    void firstOut(Arc& i, const Node& n ) const { _graph->firstOut(i, n); }
+    void firstInc(Edge &i, bool &d, const Node &n) const {
+      _graph->firstInc(i, d, n);
+    }
+
+    void next(Node& i) const { _graph->next(i); }
+    void next(Arc& i) const { _graph->next(i); }
+    void next(Edge& i) const { _graph->next(i); }
+    void nextIn(Arc& i) const { _graph->nextIn(i); }
+    void nextOut(Arc& i) const { _graph->nextOut(i); }



More information about the Lemon-commits mailing list