# HG changeset patch # User klao # Date 1099614709 0 # Node ID 1a770e9f80b274e49d51de758a4460adbf2404b3 # Parent 289d80c33f04b70a1ed3fa3f95daf59eed864d8e Undirect graph implementation. Not yet done, untested. diff -r 289d80c33f04 -r 1a770e9f80b2 src/lemon/Makefile.am --- a/src/lemon/Makefile.am Thu Nov 04 22:04:51 2004 +0000 +++ b/src/lemon/Makefile.am Fri Nov 05 00:31:49 2004 +0000 @@ -33,11 +33,13 @@ idmappable_graph_extender.h \ extendable_graph_extender.h \ clearable_graph_extender.h \ - erasable_graph_extender.h + erasable_graph_extender.h \ + undir_graph_extender.h noinst_HEADERS = \ concept/graph.h \ concept/graph_component.h \ + concept/undir_graph.h \ concept/sym_graph.h \ concept/maps.h \ concept/path.h diff -r 289d80c33f04 -r 1a770e9f80b2 src/lemon/alteration_observer_registry.h --- a/src/lemon/alteration_observer_registry.h Thu Nov 04 22:04:51 2004 +0000 +++ b/src/lemon/alteration_observer_registry.h Fri Nov 05 00:31:49 2004 +0000 @@ -278,16 +278,22 @@ }; - /// Class to extend a graph functionality with the possibility of alteration observing. - - /// AlterableGraphExtender extends the _Base graphs functionality with the possibility of - /// alteration observing. It defines two observer registrys for the nodes and mapes. + /// \brief Class to extend a graph with the functionality of alteration + /// observing. + /// + /// AlterableGraphExtender extends the _Base graphs functionality with + /// the possibility of alteration observing. It defines two observer + /// registrys for the nodes and mapes. + /// + /// \todo Document what "alteration observing" is. And probably find a + /// better (shorter) name. /// /// \param _Base is the base class to extend. /// /// \pre _Base is conform to the BaseGraphComponent concept. /// - /// \post AlterableGraphExtender<_Base> is conform to the AlterableGraphComponent concept. + /// \post AlterableGraphExtender<_Base> is conform to the + /// AlterableGraphComponent concept. /// /// \author Balazs Dezso @@ -301,9 +307,9 @@ typedef typename Parent::Node Node; typedef typename Parent::Edge Edge; + /// The edge observer registry. + typedef AlterationObserverRegistry EdgeObserverRegistry; /// The node observer registry. - typedef AlterationObserverRegistry EdgeObserverRegistry; - /// The edge observer registry. typedef AlterationObserverRegistry NodeObserverRegistry; @@ -330,6 +336,42 @@ }; + /// \brief Class to extend an undirected graph with the functionality of + /// alteration observing. + /// + /// \todo Document. + /// + /// \sa AlterableGraphExtender + /// + /// \bug This should be done some other way. Possibilities: template + /// specialization (not very easy, if at all possible); some kind of + /// enable_if boost technique? + + template + class AlterableUndirGraphExtender + : public AlterableGraphExtender<_Base> { + public: + + typedef AlterableUndirGraphExtender Graph; + typedef AlterableGraphExtender<_Base> Parent; + + typedef typename Parent::UndirEdge UndirEdge; + + /// The edge observer registry. + typedef AlterationObserverRegistry UndirEdgeObserverRegistry; + + protected: + + mutable UndirEdgeObserverRegistry undir_edge_observers; + + UndirEdgeObserverRegistry& getUndirEdgeObserverRegistry() const { + return undir_edge_observers; + } + + ~AlterableUndirGraphExtender() { + undir_edge_observers.clear(); + } + }; /// @} diff -r 289d80c33f04 -r 1a770e9f80b2 src/lemon/concept/graph_component.h --- a/src/lemon/concept/graph_component.h Thu Nov 04 22:04:51 2004 +0000 +++ b/src/lemon/concept/graph_component.h Fri Nov 05 00:31:49 2004 +0000 @@ -263,15 +263,14 @@ function_requires< GraphItemConcept >(); function_requires< GraphItemConcept >(); { - const Graph& const_graph = graph; Node n; Edge e; - n = const_graph.tail(e); - n = const_graph.head(e); + n = graph.tail(e); + n = graph.head(e); } } - Graph& graph; + const Graph& graph; }; /// An empty iterable base graph class. @@ -645,7 +644,6 @@ template struct IterableGraphComponentConcept { - void constraints() { function_requires< BaseIterableGraphComponentConcept >(); @@ -661,7 +659,6 @@ function_requires< GraphIncIteratorConcept >(); function_requires< GraphIncIteratorConcept >(); } - Graph& graph; }; diff -r 289d80c33f04 -r 1a770e9f80b2 src/lemon/concept/undir_graph.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lemon/concept/undir_graph.h Fri Nov 05 00:31:49 2004 +0000 @@ -0,0 +1,78 @@ +/* -*- C++ -*- + * + * src/lemon/concept/undir_graph_component.h - 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. + * + */ + +///\ingroup concept +///\file +///\brief Undirected graphs and components of. + + +#ifndef LEMON_CONCEPT_UNDIR_GRAPH_H +#define LEMON_CONCEPT_UNDIR_GRAPH_H + +#include + +namespace lemon { + namespace concept { + + /// \todo to be done + class BaseIterableUndirGraph; + + template + struct BaseIterableUndirGraphConcept { + typedef typename Graph::UndirEdge UndirEdge; + typedef typename Graph::Edge Edge; + typedef typename Graph::Node Node; + void constraints() { + function_requires< BaseIterableGraphComponentConcept >(); + function_requires< GraphItemConcept >(); + + /// \bug this should be base_and_derived: + UndirEdge ue = e; + ue = e; + + Node n; + n = graph.head(ue); + n = graph.tail(ue); + + graph.first(ue); + graph.next(ue); + } + const Graph &graph; + Edge e; + }; + + template + struct IterableUndirGraphConcept { + void constraints() { + function_requires< BaseIterableUndirGraphConcept > (); + function_requires< IterableGraphComponentConcept > (); + + typedef typename Graph::UndirEdge UndirEdge; + typedef typename Graph::UndirEdgeIt UndirEdgeIt; + + function_requires< + GraphIteratorConcept >(); + } + }; + + } + +} + +#endif diff -r 289d80c33f04 -r 1a770e9f80b2 src/lemon/iterable_graph_extender.h --- a/src/lemon/iterable_graph_extender.h Thu Nov 04 22:04:51 2004 +0000 +++ b/src/lemon/iterable_graph_extender.h Fri Nov 05 00:31:49 2004 +0000 @@ -8,12 +8,11 @@ template class IterableGraphExtender : public _Base { + public: typedef _Base Parent; typedef IterableGraphExtender<_Base> Graph; - public: - typedef typename Parent::Node Node; typedef typename Parent::Edge Edge; @@ -26,7 +25,7 @@ NodeIt(Invalid i) : Node(i) { } - explicit NodeIt(const Graph& _graph) : Node(), graph(&_graph) { + explicit NodeIt(const Graph& _graph) : graph(&_graph) { _graph.first(*static_cast(this)); } @@ -49,7 +48,7 @@ EdgeIt(Invalid i) : Edge(i) { } - explicit EdgeIt(const Graph& _graph) : Edge(), graph(&_graph) { + explicit EdgeIt(const Graph& _graph) : graph(&_graph) { _graph.first(*static_cast(this)); } @@ -73,7 +72,7 @@ OutEdgeIt(Invalid i) : Edge(i) { } OutEdgeIt(const Graph& _graph, const Node& node) - : Edge(), graph(&_graph) { + : graph(&_graph) { _graph.firstOut(*this, node); } @@ -97,7 +96,7 @@ InEdgeIt(Invalid i) : Edge(i) { } InEdgeIt(const Graph& _graph, const Node& node) - : Edge(), graph(&_graph) { + : graph(&_graph) { _graph.firstIn(*this, node); } @@ -126,6 +125,39 @@ }; + template + class IterableUndirGraphExtender : public IterableGraphExtender<_Base> { + public: + + typedef IterableGraphExtender<_Base> Parent; + typedef IterableUndirGraphExtender<_Base> Graph; + + typedef typename Parent::UndirEdge UndirEdge; + + class UndirEdgeIt : public UndirEdge { + const Graph* graph; + public: + + UndirEdgeIt() { } + + UndirEdgeIt(Invalid i) : UndirEdge(i) { } + + explicit UndirEdgeIt(const Graph& _graph) : graph(&_graph) { + _graph.first(*static_cast(this)); + } + + UndirEdgeIt(const Graph& _graph, const UndirEdge& e) : + UndirEdge(e), graph(&_graph) { } + + UndirEdgeIt& operator++() { + graph->next(*this); + return *this; + } + + }; + + + }; } #endif // LEMON_GRAPH_EXTENDER_H diff -r 289d80c33f04 -r 1a770e9f80b2 src/lemon/undir_graph_extender.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lemon/undir_graph_extender.h Fri Nov 05 00:31:49 2004 +0000 @@ -0,0 +1,193 @@ +/* -*- C++ -*- + * + * src/lemon/undir_graph_extender.h - 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. + * + */ + +#ifndef LEMON_UNDIR_GRAPH_EXTENDER_H +#define LEMON_UNDIR_GRAPH_EXTENDER_H + +#include + +namespace lemon { + + template + class UndirGraphExtender : public _Base { + typedef _Base Parent; + typedef UndirGraphExtender Graph; + + public: + + typedef typename Parent::Edge UndirEdge; + typedef typename Parent::Node Node; + + class Edge : public UndirEdge { + friend class Graph; + + protected: + // FIXME: Marci use opposite logic in his graph wrappers. It would + // be reasonable to syncronize... + bool forward; + + public: + Edge() {} + /// Construct a direct edge from undirect edge and a direction. + Edge(const UndirEdge &ue, bool _forward) : + UndirEdge(ue), forward(_forward) {} + /// Invalid edge constructor + Edge(Invalid i) : UndirEdge(i), forward(false) {} + + bool operator==(const Edge &that) const { + return forward==that.forward && UndirEdge(*this)==UndirEdge(that); + } + bool operator!=(const Edge &that) const { + return forward!=that.forward || UndirEdge(*this)!=UndirEdge(that); + } + bool operator<(const Edge &that) const { + return forward +#include +#include +#include +#include + +#include "test_tools.h" + + +using namespace lemon; +using namespace lemon::concept; + + +int main() { + typedef UndirGraphExtender UndirListGraphBase; + + function_requires< BaseIterableUndirGraphConcept >(); + + typedef IterableUndirGraphExtender< + AlterableUndirGraphExtender > IterableUndirListGraph; + + function_requires< IterableUndirGraphConcept >(); + + return 0; +}