[Lemon-commits] Balazs Dezso: Port ListDigraph and ListGraph fro...
Lemon HG
hg at lemon.cs.elte.hu
Tue Jan 22 12:00:15 CET 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/c1acf0018c0a
changeset: 57:c1acf0018c0a
user: Balazs Dezso <deba [at] inf.elte.hu>
date: Sun Jan 20 20:43:48 2008 +0100
description:
Port ListDigraph and ListGraph from svn -r 3433 Details:
- port Digraph and Graph concepts
- port ListDigraph and ListGraph
- port Basic graph constructing tools
- port Digraph and Graph tests
diffstat:
18 files changed, 7825 insertions(+), 1 deletion(-)
lemon/Makefile.am | 12
lemon/bits/alteration_notifier.h | 485 ++++++++++++
lemon/bits/array_map.h | 346 ++++++++
lemon/bits/base_extender.h | 495 ++++++++++++
lemon/bits/default_map.h | 181 ++++
lemon/bits/graph_extender.h | 747 ++++++++++++++++++
lemon/bits/map_extender.h | 321 +++++++
lemon/bits/traits.h | 272 ++++++
lemon/bits/vector_map.h | 243 ++++++
lemon/concepts/digraph.h | 453 +++++++++++
lemon/concepts/graph.h | 702 +++++++++++++++++
lemon/concepts/graph_components.h | 1490 +++++++++++++++++++++++++++++++++++++
lemon/list_graph.h | 1449 +++++++++++++++++++++++++++++++++++
test/Makefile.am | 4
test/digraph_test.cc | 82 ++
test/digraph_test.h | 188 ++++
test/graph_test.cc | 207 +++++
test/map_test.h | 149 +++
diffs (truncated from 7922 to 300 lines):
diff -r 9bd0d6e0c279 -r c1acf0018c0a lemon/Makefile.am
--- a/lemon/Makefile.am Sat Jan 12 23:30:44 2008 +0000
+++ b/lemon/Makefile.am Sun Jan 20 20:43:48 2008 +0100
@@ -21,7 +21,17 @@ lemon_HEADERS += \
lemon/tolerance.h
bits_HEADERS += \
+ lemon/bits/alteration_notifier.h \
+ lemon/bits/array_map.h \
+ lemon/bits/base_extender.h \
+ lemon/bits/default_map.h \
lemon/bits/invalid.h \
- lemon/bits/utility.h
+ lemon/bits/map_extender.h \
+ lemon/bits/utility.h \
+ lemon/bits/vector_map.h
concept_HEADERS +=
+ lemon/concept_check.h \
+ lemon/concepts/digraph.h \
+ lemon/concepts/graph.h \
+ lemon/concepts/graph_components.h
diff -r 9bd0d6e0c279 -r c1acf0018c0a lemon/bits/alteration_notifier.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lemon/bits/alteration_notifier.h Sun Jan 20 20:43:48 2008 +0100
@@ -0,0 +1,485 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2007
+ * 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_ALTERATION_NOTIFIER_H
+#define LEMON_BITS_ALTERATION_NOTIFIER_H
+
+#include <vector>
+#include <list>
+
+#include <lemon/bits/utility.h>
+
+///\ingroup graphbits
+///\file
+///\brief Observer notifier for graph alteration observers.
+
+namespace lemon {
+
+ /// \ingroup graphbits
+ ///
+ /// \brief Notifier class to notify observes about alterations in
+ /// a container.
+ ///
+ /// The simple graph's can be refered as two containers, one node container
+ /// and one edge container. But they are not standard containers they
+ /// does not store values directly they are just key continars for more
+ /// value containers which are the node and edge maps.
+ ///
+ /// The graph's node and edge sets can be changed as we add or erase
+ /// nodes and edges in the graph. Lemon would like to handle easily
+ /// that the node and edge maps should contain values for all nodes or
+ /// edges. If we want to check on every indicing if the map contains
+ /// the current indicing key that cause a drawback in the performance
+ /// in the library. We use another solution we notify all maps about
+ /// an alteration in the graph, which cause only drawback on the
+ /// alteration of the graph.
+ ///
+ /// This class provides an interface to the container. The \e first() and \e
+ /// next() member functions make possible to iterate on the keys of the
+ /// container. The \e id() function returns an integer id for each key.
+ /// The \e maxId() function gives back an upper bound of the ids.
+ ///
+ /// For the proper functonality of this class, we should notify it
+ /// about each alteration in the container. The alterations have four type
+ /// as \e add(), \e erase(), \e build() and \e clear(). The \e add() and
+ /// \e erase() signals that only one or few items added or erased to or
+ /// from the graph. If all items are erased from the graph or from an empty
+ /// graph a new graph is builded then it can be signaled with the
+ /// clear() and build() members. Important rule that if we erase items
+ /// from graph we should first signal the alteration and after that erase
+ /// them from the container, on the other way on item addition we should
+ /// first extend the container and just after that signal the alteration.
+ ///
+ /// The alteration can be observed with a class inherited from the
+ /// \e ObserverBase nested class. The signals can be handled with
+ /// overriding the virtual functions defined in the base class. The
+ /// observer base can be attached to the notifier with the
+ /// \e attach() member and can be detached with detach() function. The
+ /// alteration handlers should not call any function which signals
+ /// an other alteration in the same notifier and should not
+ /// detach any observer from the notifier.
+ ///
+ /// Alteration observers try to be exception safe. If an \e add() or
+ /// a \e clear() function throws an exception then the remaining
+ /// observeres will not be notified and the fulfilled additions will
+ /// be rolled back by calling the \e erase() or \e clear()
+ /// functions. Thence the \e erase() and \e clear() should not throw
+ /// exception. Actullay, it can be throw only
+ /// \ref AlterationObserver::ImmediateDetach ImmediateDetach
+ /// exception which detach the observer from the notifier.
+ ///
+ /// There are some place when the alteration observing is not completly
+ /// reliable. If we want to carry out the node degree in the graph
+ /// as in the \ref InDegMap and we use the reverseEdge that cause
+ /// unreliable functionality. Because the alteration observing signals
+ /// only erasing and adding but not the reversing it will stores bad
+ /// degrees. The sub graph adaptors cannot signal the alterations because
+ /// just a setting in the filter map can modify the graph and this cannot
+ /// be watched in any way.
+ ///
+ /// \param _Container The container which is observed.
+ /// \param _Item The item type which is obserbved.
+ ///
+ /// \author Balazs Dezso
+
+ template <typename _Container, typename _Item>
+ class AlterationNotifier {
+ public:
+
+ typedef True Notifier;
+
+ typedef _Container Container;
+ typedef _Item Item;
+
+ /// \brief Exception which can be called from \e clear() and
+ /// \e erase().
+ ///
+ /// From the \e clear() and \e erase() function only this
+ /// exception is allowed to throw. The exception immediatly
+ /// detaches the current observer from the notifier. Because the
+ /// \e clear() and \e erase() should not throw other exceptions
+ /// it can be used to invalidate the observer.
+ struct ImmediateDetach {};
+
+ /// \brief ObserverBase is the base class for the observers.
+ ///
+ /// ObserverBase is the abstract base class for the observers.
+ /// It will be notified about an item was inserted into or
+ /// erased from the graph.
+ ///
+ /// The observer interface contains some pure virtual functions
+ /// to override. The add() and erase() functions are
+ /// to notify the oberver when one item is added or
+ /// erased.
+ ///
+ /// The build() and clear() members are to notify the observer
+ /// about the container is built from an empty container or
+ /// is cleared to an empty container.
+ ///
+ /// \author Balazs Dezso
+
+ class ObserverBase {
+ protected:
+ typedef AlterationNotifier Notifier;
+
+ friend class AlterationNotifier;
+
+ /// \brief Default constructor.
+ ///
+ /// Default constructor for ObserverBase.
+ ///
+ ObserverBase() : _notifier(0) {}
+
+ /// \brief Constructor which attach the observer into notifier.
+ ///
+ /// Constructor which attach the observer into notifier.
+ ObserverBase(AlterationNotifier& nf) {
+ attach(nf);
+ }
+
+ /// \brief Constructor which attach the obserever to the same notifier.
+ ///
+ /// Constructor which attach the obserever to the same notifier as
+ /// the other observer is attached to.
+ ObserverBase(const ObserverBase& copy) {
+ if (copy.attached()) {
+ attach(*copy.notifier());
+ }
+ }
+
+ /// \brief Destructor
+ virtual ~ObserverBase() {
+ if (attached()) {
+ detach();
+ }
+ }
+
+ /// \brief Attaches the observer into an AlterationNotifier.
+ ///
+ /// This member attaches the observer into an AlterationNotifier.
+ ///
+ void attach(AlterationNotifier& nf) {
+ nf.attach(*this);
+ }
+
+ /// \brief Detaches the observer into an AlterationNotifier.
+ ///
+ /// This member detaches the observer from an AlterationNotifier.
+ ///
+ void detach() {
+ _notifier->detach(*this);
+ }
+
+ /// \brief Gives back a pointer to the notifier which the map
+ /// attached into.
+ ///
+ /// This function gives back a pointer to the notifier which the map
+ /// attached into.
+ ///
+ Notifier* notifier() const { return const_cast<Notifier*>(_notifier); }
+
+ /// Gives back true when the observer is attached into a notifier.
+ bool attached() const { return _notifier != 0; }
+
+ private:
+
+ ObserverBase& operator=(const ObserverBase& copy);
+
+ protected:
+
+ Notifier* _notifier;
+ typename std::list<ObserverBase*>::iterator _index;
+
+ /// \brief The member function to notificate the observer about an
+ /// item is added to the container.
+ ///
+ /// The add() member function notificates the observer about an item
+ /// is added to the container. It have to be overrided in the
+ /// subclasses.
+ virtual void add(const Item&) = 0;
+
+ /// \brief The member function to notificate the observer about
+ /// more item is added to the container.
+ ///
+ /// The add() member function notificates the observer about more item
+ /// is added to the container. It have to be overrided in the
+ /// subclasses.
+ virtual void add(const std::vector<Item>& items) = 0;
+
+ /// \brief The member function to notificate the observer about an
+ /// item is erased from the container.
+ ///
+ /// The erase() member function notificates the observer about an
+ /// item is erased from the container. It have to be overrided in
+ /// the subclasses.
+ virtual void erase(const Item&) = 0;
+
+ /// \brief The member function to notificate the observer about
+ /// more item is erased from the container.
+ ///
+ /// The erase() member function notificates the observer about more item
+ /// is erased from the container. It have to be overrided in the
+ /// subclasses.
+ virtual void erase(const std::vector<Item>& items) = 0;
+
+ /// \brief The member function to notificate the observer about the
+ /// container is built.
+ ///
+ /// The build() member function notificates the observer about the
+ /// container is built from an empty container. It have to be
+ /// overrided in the subclasses.
+
+ virtual void build() = 0;
+
+ /// \brief The member function to notificate the observer about all
+ /// items are erased from the container.
+ ///
+ /// The clear() member function notificates the observer about all
+ /// items are erased from the container. It have to be overrided in
+ /// the subclasses.
+ virtual void clear() = 0;
+
+ };
+
+ protected:
+
+ const Container* container;
+
+ typedef std::list<ObserverBase*> Observers;
+ Observers _observers;
+
+
+ public:
+
+ /// \brief Default constructor.
+ ///
+ /// The default constructor of the AlterationNotifier.
+ /// It creates an empty notifier.
+ AlterationNotifier()
+ : container(0) {}
More information about the Lemon-commits
mailing list