[Lemon-commits] Alpar Juttner: Merge

Lemon HG hg at lemon.cs.elte.hu
Mon Jan 12 14:47:38 CET 2009


details:   http://lemon.cs.elte.hu/hg/lemon/rev/04c0631fd332
changeset: 492:04c0631fd332
user:      Alpar Juttner <alpar [at] cs.elte.hu>
date:      Mon Jan 12 13:37:37 2009 +0000
description:
	Merge

diffstat:

6 files changed, 2423 insertions(+)
lemon/Makefile.am              |    2 
lemon/bits/edge_set_extender.h |  628 +++++++++++++++++
lemon/edge_set.h               | 1410 ++++++++++++++++++++++++++++++++++++++++
test/CMakeLists.txt            |    1 
test/Makefile.am               |    2 
test/edge_set_test.cc          |  380 ++++++++++

diffs (truncated from 2482 to 300 lines):

diff --git a/lemon/Makefile.am b/lemon/Makefile.am
--- a/lemon/Makefile.am
+++ b/lemon/Makefile.am
@@ -60,6 +60,7 @@
 	lemon/dijkstra.h \
 	lemon/dim2.h \
 	lemon/dimacs.h \
+	lemon/edge_set.h \
 	lemon/elevator.h \
 	lemon/error.h \
 	lemon/full_graph.h \
@@ -97,6 +98,7 @@
 	lemon/bits/base_extender.h \
 	lemon/bits/bezier.h \
 	lemon/bits/default_map.h \
+	lemon/bits/edge_set_extender.h \
 	lemon/bits/enable_if.h \
 	lemon/bits/graph_adaptor_extender.h \
 	lemon/bits/graph_extender.h \
diff --git a/lemon/bits/edge_set_extender.h b/lemon/bits/edge_set_extender.h
new file mode 100644
--- /dev/null
+++ b/lemon/bits/edge_set_extender.h
@@ -0,0 +1,628 @@
+/* -*- C++ -*-
+ *
+ * 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_BITS_EDGE_SET_EXTENDER_H
+#define LEMON_BITS_EDGE_SET_EXTENDER_H
+
+#include <lemon/error.h>
+#include <lemon/bits/default_map.h>
+
+///\ingroup digraphbits
+///\file
+///\brief Extenders for the arc set types
+namespace lemon {
+
+  /// \ingroup digraphbits
+  ///
+  /// \brief Extender for the ArcSets
+  template <typename Base>
+  class ArcSetExtender : public Base {
+  public:
+
+    typedef Base Parent;
+    typedef ArcSetExtender Digraph;
+
+    // Base extensions
+
+    typedef typename Parent::Node Node;
+    typedef typename Parent::Arc Arc;
+
+    int maxId(Node) const {
+      return Parent::maxNodeId();
+    }
+
+    int maxId(Arc) const {
+      return Parent::maxArcId();
+    }
+
+    Node fromId(int id, Node) const {
+      return Parent::nodeFromId(id);
+    }
+
+    Arc fromId(int id, Arc) const {
+      return Parent::arcFromId(id);
+    }
+
+    Node oppositeNode(const Node &n, const Arc &e) const {
+      if (n == Parent::source(e))
+	return Parent::target(e);
+      else if(n==Parent::target(e))
+	return Parent::source(e);
+      else
+	return INVALID;
+    }
+
+
+    // Alteration notifier extensions
+
+    /// The arc observer registry.
+    typedef AlterationNotifier<ArcSetExtender, Arc> ArcNotifier;
+
+  protected:
+
+    mutable ArcNotifier arc_notifier;
+
+  public:
+
+    using Parent::notifier;
+
+    /// \brief Gives back the arc alteration notifier.
+    ///
+    /// Gives back the arc alteration notifier.
+    ArcNotifier& notifier(Arc) const {
+      return arc_notifier;
+    }
+
+    // Iterable extensions
+
+    class NodeIt : public Node { 
+      const Digraph* digraph;
+    public:
+
+      NodeIt() {}
+
+      NodeIt(Invalid i) : Node(i) { }
+
+      explicit NodeIt(const Digraph& _graph) : digraph(&_graph) {
+	_graph.first(static_cast<Node&>(*this));
+      }
+
+      NodeIt(const Digraph& _graph, const Node& node) 
+	: Node(node), digraph(&_graph) {}
+
+      NodeIt& operator++() { 
+	digraph->next(*this);
+	return *this; 
+      }
+
+    };
+
+
+    class ArcIt : public Arc { 
+      const Digraph* digraph;
+    public:
+
+      ArcIt() { }
+
+      ArcIt(Invalid i) : Arc(i) { }
+
+      explicit ArcIt(const Digraph& _graph) : digraph(&_graph) {
+	_graph.first(static_cast<Arc&>(*this));
+      }
+
+      ArcIt(const Digraph& _graph, const Arc& e) : 
+	Arc(e), digraph(&_graph) { }
+
+      ArcIt& operator++() { 
+	digraph->next(*this);
+	return *this; 
+      }
+
+    };
+
+
+    class OutArcIt : public Arc { 
+      const Digraph* digraph;
+    public:
+
+      OutArcIt() { }
+
+      OutArcIt(Invalid i) : Arc(i) { }
+
+      OutArcIt(const Digraph& _graph, const Node& node) 
+	: digraph(&_graph) {
+	_graph.firstOut(*this, node);
+      }
+
+      OutArcIt(const Digraph& _graph, const Arc& arc) 
+	: Arc(arc), digraph(&_graph) {}
+
+      OutArcIt& operator++() { 
+	digraph->nextOut(*this);
+	return *this; 
+      }
+
+    };
+
+
+    class InArcIt : public Arc { 
+      const Digraph* digraph;
+    public:
+
+      InArcIt() { }
+
+      InArcIt(Invalid i) : Arc(i) { }
+
+      InArcIt(const Digraph& _graph, const Node& node) 
+	: digraph(&_graph) {
+	_graph.firstIn(*this, node);
+      }
+
+      InArcIt(const Digraph& _graph, const Arc& arc) : 
+	Arc(arc), digraph(&_graph) {}
+
+      InArcIt& operator++() { 
+	digraph->nextIn(*this);
+	return *this; 
+      }
+
+    };
+
+    /// \brief Base node of the iterator
+    ///
+    /// Returns the base node (ie. the source in this case) of the iterator
+    Node baseNode(const OutArcIt &e) const {
+      return Parent::source(static_cast<const Arc&>(e));
+    }
+    /// \brief Running node of the iterator
+    ///
+    /// Returns the running node (ie. the target in this case) of the
+    /// iterator
+    Node runningNode(const OutArcIt &e) const {
+      return Parent::target(static_cast<const Arc&>(e));
+    }
+
+    /// \brief Base node of the iterator
+    ///
+    /// Returns the base node (ie. the target in this case) of the iterator
+    Node baseNode(const InArcIt &e) const {
+      return Parent::target(static_cast<const Arc&>(e));
+    }
+    /// \brief Running node of the iterator
+    ///
+    /// Returns the running node (ie. the source in this case) of the
+    /// iterator
+    Node runningNode(const InArcIt &e) const {
+      return Parent::source(static_cast<const Arc&>(e));
+    }
+
+    using Parent::first;
+
+    // Mappable extension
+    
+    template <typename _Value>
+    class ArcMap 
+      : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
+    public:
+      typedef ArcSetExtender Digraph;
+      typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
+
+      explicit ArcMap(const Digraph& _g) 
+	: Parent(_g) {}
+      ArcMap(const Digraph& _g, const _Value& _v) 
+	: Parent(_g, _v) {}
+
+      ArcMap& operator=(const ArcMap& cmap) {
+	return operator=<ArcMap>(cmap);
+      }
+
+      template <typename CMap>
+      ArcMap& operator=(const CMap& cmap) {
+        Parent::operator=(cmap);
+	return *this;
+      }
+
+    };
+
+
+    // Alteration extension
+
+    Arc addArc(const Node& from, const Node& to) {
+      Arc arc = Parent::addArc(from, to);
+      notifier(Arc()).add(arc);
+      return arc;
+    }
+    
+    void clear() {
+      notifier(Arc()).clear();
+      Parent::clear();
+    }
+
+    void erase(const Arc& arc) {
+      notifier(Arc()).erase(arc);
+      Parent::erase(arc);
+    }
+
+    ArcSetExtender() {
+      arc_notifier.setContainer(*this);
+    }
+
+    ~ArcSetExtender() {
+      arc_notifier.clear();
+    }
+
+  };
+
+
+  /// \ingroup digraphbits
+  ///
+  /// \brief Extender for the EdgeSets
+  template <typename Base>
+  class EdgeSetExtender : public Base {



More information about the Lemon-commits mailing list