The graph_factory branch (@ 1321) has been merged to trunk.
authorklao
Wed, 27 Oct 2004 22:38:50 +0000
changeset 946c94ef40a22ce
parent 945 f2ea4aac9ada
child 947 93e9c45703ea
The graph_factory branch (@ 1321) has been merged to trunk.
src/benchmark/hcube.cc
src/lemon/Makefile.am
src/lemon/alteration_observer_registry.h
src/lemon/array_map.h
src/lemon/bfs.h
src/lemon/clearable_graph_extender.h
src/lemon/concept_check.h
src/lemon/default_map.h
src/lemon/dfs.h
src/lemon/erasable_graph_extender.h
src/lemon/extendable_graph_extender.h
src/lemon/full_graph.h
src/lemon/graph_utils.h
src/lemon/idmappable_graph_extender.h
src/lemon/iterable_graph_extender.h
src/lemon/list_graph.h
src/lemon/map_registry.h
src/lemon/mappable_graph_extender.h
src/lemon/preflow.h
src/lemon/skeletons/graph.h
src/lemon/skeletons/graph_component.h
src/lemon/skeletons/maps.h
src/lemon/smart_graph.h
src/lemon/suurballe.h
src/lemon/vector_map.h
src/test/Makefile.am
src/test/graph_factory_test.cc
src/test/graph_test.cc
src/test/graph_test.h
src/test/graph_utils_test.cc
src/test/graph_utils_test.h
src/test/graph_wrapper_test.cc
src/test/map_test.h
src/test/new_graph_test.cc
src/test/test_tools.h
src/work/klao/TODO
     1.1 --- a/src/benchmark/hcube.cc	Mon Oct 25 13:29:46 2004 +0000
     1.2 +++ b/src/benchmark/hcube.cc	Wed Oct 27 22:38:50 2004 +0000
     1.3 @@ -66,12 +66,15 @@
     1.4      for(int i=0;i<dim*(1<<dim);i++) P();
     1.5      
     1.6      //  for(EdgeIt e(G);G.valid(e);G.next(e)) map[e]=P();
     1.7 -    Edge te;
     1.8 -    for(int i=0;i<dim*(1<<dim);i++) {
     1.9 -      te.setToId(((long long int)(i)*93505)%(dim*(1<<dim)));
    1.10 -      //    map[Edge(((long long int)(i)*2987)%(dim*(1<<dim)))]=P();
    1.11 -      map[te]=P();
    1.12 -    }
    1.13 +
    1.14 +    ///\todo It must have been commented out because of
    1.15 +    ///setToId
    1.16 +//     Edge te;
    1.17 +//     for(int i=0;i<dim*(1<<dim);i++) {
    1.18 +//       te.setToId(((long long int)(i)*93505)%(dim*(1<<dim)));
    1.19 +//       //    map[Edge(((long long int)(i)*2987)%(dim*(1<<dim)))]=P();
    1.20 +//       map[te]=P();
    1.21 +//     }
    1.22      
    1.23  //     for(int i=0;i<(1<<dim);i++) {
    1.24  //       int mul= (1<<(numOfZeros(i,dim)/4));
     2.1 --- a/src/lemon/Makefile.am	Mon Oct 25 13:29:46 2004 +0000
     2.2 +++ b/src/lemon/Makefile.am	Wed Oct 27 22:38:50 2004 +0000
     2.3 @@ -10,13 +10,12 @@
     2.4  	fib_heap.h							\
     2.5  	full_graph.h							\
     2.6  	graph_wrapper.h							\
     2.7 +	graph_utils.h							\
     2.8  	invalid.h							\
     2.9  	kruskal.h							\
    2.10  	list_graph.h							\
    2.11 -	map_defines.h                                                   \
    2.12  	map_iterator.h                                                  \
    2.13 -	map_registry.h                                                  \
    2.14 -	map_bits.h							\
    2.15 +	alteration_observer_registry.h                                  \
    2.16  	maps.h								\
    2.17  	min_cost_flow.h                                                 \
    2.18  	suurballe.h                                                     \
    2.19 @@ -26,10 +25,19 @@
    2.20  	time_measure.h							\
    2.21  	unionfind.h							\
    2.22  	vector_map.h                                                    \
    2.23 -	xy.h
    2.24 +	xy.h								\
    2.25 +	concept_check.h							\
    2.26 +	map_defines.h							\
    2.27 +	map_bits.h							\
    2.28 +	iterable_graph_extender.h					\
    2.29 +	idmappable_graph_extender.h				   	\
    2.30 +	extendable_graph_extender.h					\
    2.31 +	clearable_graph_extender.h					\
    2.32 +	erasable_graph_extender.h
    2.33  
    2.34  noinst_HEADERS =							\
    2.35  	skeletons/graph.h						\
    2.36 +	skeletons/graph_component.h					\
    2.37  	skeletons/sym_graph.h                                           \
    2.38  	skeletons/maps.h                                                \
    2.39  	skeletons/path.h
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/lemon/alteration_observer_registry.h	Wed Oct 27 22:38:50 2004 +0000
     3.3 @@ -0,0 +1,339 @@
     3.4 +/* -*- C++ -*-
     3.5 + * src/lemon/observer_registry.h - Part of LEMON, a generic C++ optimization library
     3.6 + *
     3.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     3.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
     3.9 + *
    3.10 + * Permission to use, modify and distribute this software is granted
    3.11 + * provided that this copyright notice appears in all copies. For
    3.12 + * precise terms see the accompanying LICENSE file.
    3.13 + *
    3.14 + * This software is provided "AS IS" with no warranty of any kind,
    3.15 + * express or implied, and with no claim as to its suitability for any
    3.16 + * purpose.
    3.17 + *
    3.18 + */
    3.19 +
    3.20 +#ifndef LEMON_ALTERATION_OBSERVER_REGISTRY_H
    3.21 +#define LEMON_ALTERATION_OBSERVER_REGISTRY_H
    3.22 +
    3.23 +#include <vector>
    3.24 +#include <algorithm>
    3.25 +
    3.26 +///\ingroup graphmaps
    3.27 +///\file
    3.28 +///\brief Observer registry for graph alteration observers.
    3.29 +
    3.30 +using namespace std;
    3.31 +
    3.32 +namespace lemon {
    3.33 +
    3.34 +  /// \addtogroup graphmaps
    3.35 +  /// @{
    3.36 +
    3.37 +  /// Registry class to register objects observes alterations in the graph.
    3.38 +
    3.39 +  /// This class is a registry for the objects which observe the
    3.40 +  /// alterations in a container. The alteration observers can be attached
    3.41 +  /// to and detached from the registry. The observers have to inherit
    3.42 +  /// from the \ref AlterationObserverRegistry::ObserverBase and override
    3.43 +  /// the virtual functions in that.
    3.44 +  ///
    3.45 +  /// The most important application of the alteration observing is the
    3.46 +  /// dynamic map implementation when the observers are observing the
    3.47 +  /// alterations in the graph.
    3.48 +  ///
    3.49 +  /// \param _Item The item type what the observers are observing, usually
    3.50 +  /// edge or node.
    3.51 +  ///
    3.52 +  /// \author Balazs Dezso
    3.53 +
    3.54 +  template <typename _Item>
    3.55 +  class AlterationObserverRegistry {
    3.56 +  public:
    3.57 +    typedef _Item Item;
    3.58 +
    3.59 +    /// ObserverBase is the base class for the observers.
    3.60 +	
    3.61 +    /// ObserverBase is the abstract base class for the observers.
    3.62 +    /// It will be notified about an item was inserted into or
    3.63 +    /// erased from the graph.
    3.64 +    ///
    3.65 +    /// The observer interface contains some pure virtual functions
    3.66 +    /// to override. The add() and erase() functions are
    3.67 +    /// to notify the oberver when one item is added or
    3.68 +    /// erased.
    3.69 +    ///
    3.70 +    /// The build() and clear() members are to notify the observer
    3.71 +    /// about the container is builded from an empty container or
    3.72 +    /// is cleared to an empty container. 
    3.73 +    /// 
    3.74 +    /// \author Balazs Dezso
    3.75 +
    3.76 +    class ObserverBase {
    3.77 +    protected:
    3.78 +      typedef AlterationObserverRegistry Registry;
    3.79 +
    3.80 +      friend class Registry;
    3.81 +
    3.82 +      /// Default constructor.
    3.83 +
    3.84 +      /// Default constructor for ObserverBase.
    3.85 +      /// 
    3.86 +      ObserverBase() : registry(0) {}
    3.87 +
    3.88 +      virtual ~ObserverBase() {}
    3.89 +
    3.90 +      /// Attaches the observer into an AlterationObserverRegistry.
    3.91 +
    3.92 +      /// This member attaches the observer into an AlterationObserverRegistry.
    3.93 +      ///
    3.94 +      void attach(AlterationObserverRegistry& r) {
    3.95 +	registry = &r;
    3.96 +	registry->attach(*this);
    3.97 +      }
    3.98 +
    3.99 +      /// Detaches the observer into an AlterationObserverRegistry.
   3.100 +
   3.101 +      /// This member detaches the observer from an AlterationObserverRegistry.
   3.102 +      ///
   3.103 +      void detach() {
   3.104 +	if (registry) {
   3.105 +	  registry->detach(*this);
   3.106 +	}
   3.107 +      }
   3.108 +	
   3.109 +
   3.110 +      /// Gives back a pointer to the registry what the map attached into.
   3.111 +
   3.112 +      /// This function gives back a pointer to the registry what the map
   3.113 +      /// attached into.
   3.114 +      ///
   3.115 +      Registry* getRegistry() const { return const_cast<Registry*>(registry); }
   3.116 +      
   3.117 +      /// Gives back true when the observer is attached into a registry.
   3.118 +      bool attached() const { return registry != 0; }
   3.119 +	
   3.120 +    private:
   3.121 +
   3.122 +      ObserverBase(const ObserverBase& copy);
   3.123 +      ObserverBase& operator=(const ObserverBase& copy);
   3.124 +
   3.125 +    protected:
   3.126 +      
   3.127 +      Registry* registry;
   3.128 +      int registry_index;
   3.129 +
   3.130 +    public:
   3.131 +
   3.132 +      /// \brief The member function to notificate the observer about an
   3.133 +      /// item is added to the container.
   3.134 +      ///
   3.135 +      /// The add() member function notificates the observer about an item
   3.136 +      /// is added to the container. It have to be overrided in the
   3.137 +      /// subclasses.
   3.138 +	
   3.139 +      virtual void add(const Item&) = 0;	
   3.140 +
   3.141 +
   3.142 +      /// \brief The member function to notificate the observer about an
   3.143 +      /// item is erased from the container.
   3.144 +      ///
   3.145 +      /// The erase() member function notificates the observer about an
   3.146 +      /// item is erased from the container. It have to be overrided in
   3.147 +      /// the subclasses.
   3.148 +	
   3.149 +      virtual void erase(const Item&) = 0;
   3.150 +
   3.151 +      /// \brief The member function to notificate the observer about the
   3.152 +      /// container is builded.
   3.153 +      ///
   3.154 +      /// The build() member function notificates the observer about the
   3.155 +      /// container is builded from an empty container. It have to be
   3.156 +      /// overrided in the subclasses.
   3.157 +
   3.158 +      virtual void build() = 0;
   3.159 +
   3.160 +      /// \brief The member function to notificate the observer about all
   3.161 +      /// items are erased from the container.
   3.162 +      ///
   3.163 +      /// The clear() member function notificates the observer about all
   3.164 +      /// items are erased from the container. It have to be overrided in
   3.165 +      /// the subclasses.
   3.166 +      
   3.167 +      virtual void clear() = 0;
   3.168 +
   3.169 +    };
   3.170 +	
   3.171 +  protected:
   3.172 +	
   3.173 +
   3.174 +    typedef std::vector<ObserverBase*> Container; 
   3.175 +
   3.176 +    Container container;
   3.177 +
   3.178 +		
   3.179 +  public:
   3.180 +
   3.181 +    /// Default constructor.
   3.182 +	
   3.183 +    ///
   3.184 +    /// The default constructor of the AlterationObserverRegistry. 
   3.185 +    /// It creates an empty registry.
   3.186 +    AlterationObserverRegistry() {}
   3.187 +
   3.188 +    /// Copy Constructor of the AlterationObserverRegistry. 
   3.189 +	
   3.190 +    /// Copy constructor of the AlterationObserverRegistry. 
   3.191 +    /// It creates only an empty registry because the copiable
   3.192 +    /// registry's observers have to be registered still into that registry.
   3.193 +    AlterationObserverRegistry(const AlterationObserverRegistry&) {}
   3.194 +
   3.195 +    /// Assign operator.
   3.196 +		
   3.197 +    /// Assign operator for the AlterationObserverRegistry. 
   3.198 +    /// It makes the registry only empty because the copiable
   3.199 +    /// registry's observers have to be registered still into that registry.
   3.200 +    AlterationObserverRegistry& operator=(const AlterationObserverRegistry&) {
   3.201 +      typename Container::iterator it;
   3.202 +      for (it = container.begin(); it != container.end(); ++it) {
   3.203 +	(*it)->registry = 0;
   3.204 +      }
   3.205 +    }
   3.206 +
   3.207 +    /// Destructor.
   3.208 +				
   3.209 +    /// Destructor of the AlterationObserverRegistry.
   3.210 +    ///
   3.211 +    ~AlterationObserverRegistry() {
   3.212 +      typename Container::iterator it;
   3.213 +      for (it = container.begin(); it != container.end(); ++it) {
   3.214 +	(*it)->registry = 0;
   3.215 +      }
   3.216 +    }
   3.217 +	
   3.218 +	
   3.219 +  protected:
   3.220 +
   3.221 +    void attach(ObserverBase& observer) {
   3.222 +      container.push_back(&observer);
   3.223 +      observer.registry = this;
   3.224 +      observer.registry_index = container.size()-1;
   3.225 +    } 
   3.226 +
   3.227 +    void detach(ObserverBase& base) {
   3.228 +      container.back()->registry_index = base.registry_index; 
   3.229 +      container[base.registry_index] = container.back();
   3.230 +      container.pop_back();
   3.231 +      base.registry = 0;
   3.232 +    }
   3.233 +
   3.234 +  public:
   3.235 +	
   3.236 +    /// Notifies all the registered observers about an Item added to the container.
   3.237 +		
   3.238 +    /// It notifies all the registered observers about an Item added to the container.
   3.239 +    /// 
   3.240 +    void add(const Item& key) {
   3.241 +      typename Container::iterator it;
   3.242 +      for (it = container.begin(); it != container.end(); ++it) {
   3.243 +	(*it)->add(key);
   3.244 +      }
   3.245 +    }	
   3.246 +
   3.247 +    /// Notifies all the registered observers about an Item erased from the container.
   3.248 +		
   3.249 +    /// It notifies all the registered observers about an Item erased from the container.
   3.250 +    /// 
   3.251 +    void erase(const Item& key) {
   3.252 +      typename Container::iterator it;
   3.253 +      for (it = container.begin(); it != container.end(); ++it) {
   3.254 +	(*it)->erase(key);
   3.255 +      }
   3.256 +    }
   3.257 +    
   3.258 +
   3.259 +    /// Notifies all the registered observers about the container is builded.
   3.260 +		
   3.261 +    /// Notifies all the registered observers about the container is builded
   3.262 +    /// from an empty container.
   3.263 +    void build() {
   3.264 +      typename Container::iterator it;
   3.265 +      for (it = container.begin(); it != container.end(); ++it) {
   3.266 +	(*it)->build();
   3.267 +      }
   3.268 +    }
   3.269 +
   3.270 +
   3.271 +    /// Notifies all the registered observers about all Items are erased.
   3.272 +
   3.273 +    /// Notifies all the registered observers about all Items are erased
   3.274 +    /// from the container.
   3.275 +    void clear() {
   3.276 +      typename Container::iterator it;
   3.277 +      for (it = container.begin(); it != container.end(); ++it) {
   3.278 +	(*it)->clear();
   3.279 +      }
   3.280 +    }
   3.281 +  };
   3.282 +
   3.283 +
   3.284 +  /// Class to extend a graph functionality with the possibility of alteration observing.
   3.285 +
   3.286 +  /// AlterableGraphExtender extends the _Base graphs functionality with the possibility of 
   3.287 +  /// alteration observing. It defines two observer registrys for the nodes and mapes.
   3.288 +  ///
   3.289 +  /// \param _Base is the base class to extend.
   3.290 +  ///
   3.291 +  /// \pre _Base is conform to the BaseGraphComponent concept.
   3.292 +  ///
   3.293 +  /// \post AlterableGraphExtender<_Base> is conform to the AlterableGraphComponent concept.
   3.294 +  ///
   3.295 +  /// \author Balazs Dezso
   3.296 +
   3.297 +  template <typename _Base> 
   3.298 +  class AlterableGraphExtender : public _Base {
   3.299 +  public:
   3.300 +
   3.301 +    typedef AlterableGraphExtender Graph;
   3.302 +    typedef _Base Parent;
   3.303 +
   3.304 +    typedef typename Parent::Node Node;
   3.305 +    typedef typename Parent::Edge Edge;
   3.306 +
   3.307 +    /// The node observer registry.
   3.308 +    typedef AlterationObserverRegistry<Edge> EdgeObserverRegistry;
   3.309 +    /// The edge observer registry.
   3.310 +    typedef AlterationObserverRegistry<Node> NodeObserverRegistry;
   3.311 +
   3.312 +
   3.313 +  protected:
   3.314 +
   3.315 +    mutable EdgeObserverRegistry edge_observers;
   3.316 +
   3.317 +    mutable NodeObserverRegistry node_observers;
   3.318 +
   3.319 +  public:
   3.320 +
   3.321 +    EdgeObserverRegistry& getEdgeObserverRegistry() const {
   3.322 +      return edge_observers;
   3.323 +    }
   3.324 +
   3.325 +    NodeObserverRegistry& getNodeObserverRegistry() const {
   3.326 +      return node_observers;
   3.327 +    }
   3.328 +
   3.329 +    ~AlterableGraphExtender() {
   3.330 +      node_observers.clear();
   3.331 +      edge_observers.clear();
   3.332 +    }
   3.333 +    
   3.334 +  };
   3.335 +
   3.336 +  
   3.337 +/// @}
   3.338 +  
   3.339 +
   3.340 +}
   3.341 +
   3.342 +#endif
     4.1 --- a/src/lemon/array_map.h	Mon Oct 25 13:29:46 2004 +0000
     4.2 +++ b/src/lemon/array_map.h	Wed Oct 27 22:38:50 2004 +0000
     4.3 @@ -20,7 +20,6 @@
     4.4  #include <memory>
     4.5  
     4.6  #include <lemon/map_iterator.h>
     4.7 -#include <lemon/map_bits.h>
     4.8  
     4.9  ///\ingroup graphmaps
    4.10  ///\file
    4.11 @@ -42,22 +41,32 @@
    4.12     *  will belong to and the ValueType.
    4.13     */
    4.14  
    4.15 -  template <typename MapRegistry, typename Value> 
    4.16 -  class ArrayMap : public MapRegistry::MapBase {
    4.17 +  template <typename _Graph, 
    4.18 +	    typename _Item,
    4.19 +	    typename _ItemIt,
    4.20 +	    typename _IdMap,
    4.21 +	    typename _Value>
    4.22 +  class ArrayMap : public AlterationObserverRegistry<_Item>::ObserverBase {
    4.23  
    4.24 -    template <typename MR, typename V> friend class ArrayMap;
    4.25 -		
    4.26    public:
    4.27  		
    4.28      /// The graph type of the maps. 
    4.29 -    typedef typename MapRegistry::Graph Graph;
    4.30 +    typedef _Graph Graph;
    4.31      /// The key type of the maps.
    4.32 -    typedef typename MapRegistry::KeyType KeyType;
    4.33 +    typedef _Item KeyType;
    4.34 +
    4.35 +    typedef AlterationObserverRegistry<_Item> Registry;
    4.36 +
    4.37 +  private:
    4.38      /// The iterator to iterate on the keys.
    4.39 -    typedef typename MapRegistry::KeyIt KeyIt;
    4.40 +    typedef _ItemIt KeyIt;
    4.41 +
    4.42 +    typedef _IdMap IdMap;
    4.43 +
    4.44 +    typedef _Value Value;
    4.45  
    4.46      /// The MapBase of the Map which imlements the core regisitry function.
    4.47 -    typedef typename MapRegistry::MapBase MapBase;
    4.48 +    typedef typename Registry::ObserverBase Parent;
    4.49  		
    4.50      
    4.51    public:
    4.52 @@ -77,52 +86,47 @@
    4.53      typedef const Value* ConstPointerType;
    4.54  
    4.55  
    4.56 +  private:
    4.57      typedef std::allocator<Value> Allocator;
    4.58  
    4.59 -	
    4.60 +
    4.61 +  public:
    4.62 +
    4.63      /** Graph and Registry initialized map constructor.
    4.64       */
    4.65 -    ArrayMap(const Graph& g, MapRegistry& r) : MapBase(g, r) {
    4.66 +    ArrayMap(const Graph& _g, Registry& _r) : graph(&_g) {
    4.67 +      attach(_r);
    4.68        allocate_memory();
    4.69 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    4.70 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
    4.71 +      for (KeyIt it(*graph); it != INVALID; ++it) {
    4.72 +	int id = IdMap(*graph)[it];
    4.73  	allocator.construct(&(values[id]), Value());
    4.74        }								
    4.75      }
    4.76  
    4.77 -    /** Constructor to use default value to initialize the map. 
    4.78 -     */
    4.79 -    ArrayMap(const Graph& g, MapRegistry& r, const Value& v) 
    4.80 -      : MapBase(g, r) {
    4.81 +    /// Constructor to use default value to initialize the map. 
    4.82 +
    4.83 +    /// It constrates a map and initialize all of the the map. 
    4.84 +
    4.85 +    ArrayMap(const Graph& _g, Registry& _r, const Value& _v) : graph(&_g) {
    4.86 +      attach(_r);
    4.87        allocate_memory();
    4.88 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    4.89 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
    4.90 -	allocator.construct(&(values[id]), v);
    4.91 +      for (KeyIt it(*graph); it != INVALID; ++it) {
    4.92 +	int id = IdMap(*graph)[it];
    4.93 +	allocator.construct(&(values[id]), _v);
    4.94        }								
    4.95      }
    4.96  
    4.97      /** Constructor to copy a map of the same map type.
    4.98       */
    4.99 -    ArrayMap(const ArrayMap& copy) : MapBase(copy) {
   4.100 +    ArrayMap(const ArrayMap& copy) {
   4.101 +      if (copy.attached()) {
   4.102 +	attach(*copy.getRegistry());
   4.103 +      }
   4.104        capacity = copy.capacity;
   4.105        if (capacity == 0) return;
   4.106        values = allocator.allocate(capacity);
   4.107 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
   4.108 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
   4.109 -	allocator.construct(&(values[id]), copy.values[id]);
   4.110 -      }
   4.111 -    }
   4.112 -
   4.113 -    /** Constructor to copy a map of an other map type.
   4.114 -     */
   4.115 -    template <typename TT>
   4.116 -    ArrayMap(const ArrayMap<MapRegistry, TT>& copy) 
   4.117 -      : MapBase(copy) {
   4.118 -      capacity = copy.capacity;
   4.119 -      if (capacity == 0) return;
   4.120 -      values = allocator.allocate(capacity);
   4.121 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
   4.122 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
   4.123 +      for (KeyIt it(*graph); it != INVALID; ++it) {
   4.124 +	int id = IdMap(*graph)[it];
   4.125  	allocator.construct(&(values[id]), copy.values[id]);
   4.126        }
   4.127      }
   4.128 @@ -132,58 +136,33 @@
   4.129      ArrayMap& operator=(const ArrayMap& copy) {
   4.130        if (&copy == this) return *this;
   4.131        
   4.132 -      if (MapBase::getGraph() != copy.getGraph()) {
   4.133 -	if (capacity != 0) {
   4.134 -	  MapBase::destroy();
   4.135 -	  allocator.deallocate(values, capacity);
   4.136 +      if (graph != copy.graph) {
   4.137 +	if (attached()) {
   4.138 +	  clear();
   4.139 +	  detach();
   4.140  	}
   4.141 -
   4.142 -	MapBase::operator=(copy);
   4.143 +	if (copy.attached()) {
   4.144 +	  attach(*copy.getRegistry());
   4.145 +	}
   4.146  	capacity = copy.capacity;
   4.147  	if (capacity == 0) return *this;
   4.148  	values = allocator.allocate(capacity);      
   4.149        }
   4.150  
   4.151 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
   4.152 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
   4.153 +      for (KeyIt it(*graph); it != INVALID; ++it) {
   4.154 +	int id = IdMap(*graph)[it];
   4.155  	allocator.construct(&(values[id]), copy.values[id]);
   4.156        }
   4.157  
   4.158        return *this;
   4.159      }
   4.160  
   4.161 -    /** Assign operator to copy a map of an other map type.
   4.162 -     */
   4.163 -    template <typename TT>
   4.164 -    ArrayMap& operator=(const ArrayMap<MapRegistry, TT>& copy) {
   4.165 -
   4.166 -      if (MapBase::getGraph() != copy.getGraph()) {
   4.167 -	if (capacity != 0) {
   4.168 -	  MapBase::destroy();
   4.169 -	  allocator.deallocate(values, capacity);
   4.170 -	}
   4.171 -
   4.172 -	MapBase::operator=(copy);
   4.173 -
   4.174 -	capacity = copy.capacity;
   4.175 -	if (capacity == 0) return *this;
   4.176 -	values = allocator.allocate(capacity);
   4.177 -      }
   4.178 -
   4.179 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
   4.180 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
   4.181 -	allocator.construct(&(values[id]), copy.values[id]);
   4.182 -      }
   4.183 -
   4.184 -      return *this;
   4.185 -    }
   4.186 -				
   4.187      /** The destructor of the map.
   4.188       */
   4.189 -    virtual ~ArrayMap() {
   4.190 -      if (capacity != 0) {
   4.191 -	MapBase::destroy();
   4.192 -	allocator.deallocate(values, capacity);
   4.193 +    virtual ~ArrayMap() {      
   4.194 +      if (attached()) {
   4.195 +	clear();
   4.196 +	detach();
   4.197        }
   4.198      }
   4.199  	
   4.200 @@ -193,7 +172,7 @@
   4.201       * actual keys of the graph. 
   4.202       */
   4.203      ReferenceType operator[](const KeyType& key) {
   4.204 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
   4.205 +      int id = IdMap(*graph)[key];
   4.206        return values[id];
   4.207      } 
   4.208  		
   4.209 @@ -202,7 +181,7 @@
   4.210       * actual keys of the graph. 
   4.211       */
   4.212      ConstReferenceType operator[](const KeyType& key) const {
   4.213 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
   4.214 +      int id = IdMap(*graph)[key];
   4.215        return values[id];
   4.216      }
   4.217  	
   4.218 @@ -210,22 +189,21 @@
   4.219       *  This is a compatibility feature with the not dereferable maps.
   4.220       */
   4.221      void set(const KeyType& key, const ValueType& val) {
   4.222 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
   4.223 -      values[id] = val;
   4.224 +      (*this)[key] = val;
   4.225      }
   4.226  		
   4.227      /** Add a new key to the map. It called by the map registry.
   4.228       */
   4.229      void add(const KeyType& key) {
   4.230 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
   4.231 +      int id = IdMap(*graph)[key];
   4.232        if (id >= capacity) {
   4.233  	int new_capacity = (capacity == 0 ? 1 : capacity);
   4.234  	while (new_capacity <= id) {
   4.235  	  new_capacity <<= 1;
   4.236  	}
   4.237 -	Value* new_values = allocator.allocate(new_capacity);;
   4.238 -	for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
   4.239 -	  int jd = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
   4.240 +	Value* new_values = allocator.allocate(new_capacity);
   4.241 +	for (KeyIt it(*graph); it != INVALID; ++it) {
   4.242 +	  int jd = IdMap(*graph)[it];
   4.243  	  if (id != jd) {
   4.244  	    allocator.construct(&(new_values[jd]), values[jd]);
   4.245  	    allocator.destroy(&(values[jd]));
   4.246 @@ -241,77 +219,86 @@
   4.247      /** Erase a key from the map. It called by the map registry.
   4.248       */
   4.249      void erase(const KeyType& key) {
   4.250 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
   4.251 +      int id = IdMap(*graph)[key];
   4.252        allocator.destroy(&(values[id]));
   4.253      }
   4.254  
   4.255 -    /** Clear the data structure.
   4.256 -     */
   4.257 +    void build() {
   4.258 +      allocate_memory();
   4.259 +      for (KeyIt it(*graph); it != INVALID; ++it) {
   4.260 +	int id = IdMap(*graph)[it];
   4.261 +	allocator.construct(&(values[id]), Value());
   4.262 +      }								
   4.263 +    }
   4.264 +
   4.265      void clear() {	
   4.266        if (capacity != 0) {
   4.267 -	MapBase::destroy();
   4.268 +	for (KeyIt it(*graph); it != INVALID; ++it) {
   4.269 +	  int id = IdMap(*graph)[it];
   4.270 +	  allocator.destroy(&(values[id]));
   4.271 +	}								
   4.272  	allocator.deallocate(values, capacity);
   4.273  	capacity = 0;
   4.274        }
   4.275      }
   4.276  
   4.277 -    /// The stl compatible pair iterator of the map.
   4.278 -    typedef MapIterator<ArrayMap> Iterator;
   4.279 -    /// The stl compatible const pair iterator of the map.
   4.280 -    typedef MapConstIterator<ArrayMap> ConstIterator;
   4.281 +//     /// The stl compatible pair iterator of the map.
   4.282 +//     typedef MapIterator<ArrayMap> Iterator;
   4.283 +//     /// The stl compatible const pair iterator of the map.
   4.284 +//     typedef MapConstIterator<ArrayMap> ConstIterator;
   4.285  
   4.286 -    /** Returns the begin iterator of the map.
   4.287 -     */
   4.288 -    Iterator begin() {
   4.289 -      return Iterator(*this, KeyIt(*MapBase::getGraph()));
   4.290 -    }
   4.291 +//     /** Returns the begin iterator of the map.
   4.292 +//      */
   4.293 +//     Iterator begin() {
   4.294 +//       return Iterator(*this, KeyIt(*MapBase::getGraph()));
   4.295 +//     }
   4.296  
   4.297 -    /** Returns the end iterator of the map.
   4.298 -     */
   4.299 -    Iterator end() {
   4.300 -      return Iterator(*this, INVALID);
   4.301 -    }
   4.302 +//     /** Returns the end iterator of the map.
   4.303 +//      */
   4.304 +//     Iterator end() {
   4.305 +//       return Iterator(*this, INVALID);
   4.306 +//     }
   4.307  
   4.308 -    /** Returns the begin ConstIterator of the map.
   4.309 -     */
   4.310 -    ConstIterator begin() const {
   4.311 -      return ConstIterator(*this, KeyIt(*MapBase::getGraph()));
   4.312 -    }
   4.313 +//     /** Returns the begin ConstIterator of the map.
   4.314 +//      */
   4.315 +//     ConstIterator begin() const {
   4.316 +//       return ConstIterator(*this, KeyIt(*MapBase::getGraph()));
   4.317 +//     }
   4.318  
   4.319 -    /** Returns the end const_iterator of the map.
   4.320 -     */
   4.321 -    ConstIterator end() const {
   4.322 -      return ConstIterator(*this, INVALID);
   4.323 -    }
   4.324 +//     /** Returns the end const_iterator of the map.
   4.325 +//      */
   4.326 +//     ConstIterator end() const {
   4.327 +//       return ConstIterator(*this, INVALID);
   4.328 +//     }
   4.329  
   4.330 -    /// The KeySet of the Map.
   4.331 -    typedef MapConstKeySet<ArrayMap> ConstKeySet;
   4.332 +//     /// The KeySet of the Map.
   4.333 +//     typedef MapConstKeySet<ArrayMap> ConstKeySet;
   4.334  
   4.335 -    /// KeySet getter function.
   4.336 -    ConstKeySet keySet() const {
   4.337 -      return ConstKeySet(*this); 
   4.338 -    }
   4.339 +//     /// KeySet getter function.
   4.340 +//     ConstKeySet keySet() const {
   4.341 +//       return ConstKeySet(*this); 
   4.342 +//     }
   4.343  
   4.344 -    /// The ConstValueSet of the Map.
   4.345 -    typedef MapConstValueSet<ArrayMap> ConstValueSet;
   4.346 +//     /// The ConstValueSet of the Map.
   4.347 +//     typedef MapConstValueSet<ArrayMap> ConstValueSet;
   4.348  
   4.349 -    /// ConstValueSet getter function.
   4.350 -    ConstValueSet valueSet() const {
   4.351 -      return ConstValueSet(*this);
   4.352 -    }
   4.353 +//     /// ConstValueSet getter function.
   4.354 +//     ConstValueSet valueSet() const {
   4.355 +//       return ConstValueSet(*this);
   4.356 +//     }
   4.357  
   4.358 -    /// The ValueSet of the Map.
   4.359 -    typedef MapValueSet<ArrayMap> ValueSet;
   4.360 +//     /// The ValueSet of the Map.
   4.361 +//     typedef MapValueSet<ArrayMap> ValueSet;
   4.362  
   4.363 -    /// ValueSet getter function.
   4.364 -    ValueSet valueSet() {
   4.365 -      return ValueSet(*this);
   4.366 -    }
   4.367 +//     /// ValueSet getter function.
   4.368 +//     ValueSet valueSet() {
   4.369 +//       return ValueSet(*this);
   4.370 +//     }
   4.371  
   4.372    private:
   4.373        
   4.374      void allocate_memory() {
   4.375 -      int max_id = KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph());
   4.376 +      int max_id = IdMap(*graph).maxId();
   4.377        if (max_id == -1) {
   4.378  	capacity = 0;
   4.379  	values = 0;
   4.380 @@ -324,24 +311,88 @@
   4.381        values = allocator.allocate(capacity);	
   4.382      }      
   4.383  
   4.384 +    const Graph* graph;
   4.385      int capacity;
   4.386      Value* values;
   4.387      Allocator allocator;
   4.388  
   4.389    public:
   4.390 -    // STL  compatibility typedefs.
   4.391 -    typedef Iterator iterator;
   4.392 -    typedef ConstIterator const_iterator;
   4.393 -    typedef typename Iterator::PairValueType value_type;
   4.394 -    typedef typename Iterator::KeyType key_type;
   4.395 -    typedef typename Iterator::ValueType data_type;
   4.396 -    typedef typename Iterator::PairReferenceType reference;
   4.397 -    typedef typename Iterator::PairPointerType pointer;
   4.398 -    typedef typename ConstIterator::PairReferenceType const_reference;
   4.399 -    typedef typename ConstIterator::PairPointerType const_pointer;
   4.400 -    typedef int difference_type;		
   4.401 +//     // STL  compatibility typedefs.
   4.402 +//     typedef Iterator iterator;
   4.403 +//     typedef ConstIterator const_iterator;
   4.404 +//     typedef typename Iterator::PairValueType value_type;
   4.405 +//     typedef typename Iterator::KeyType key_type;
   4.406 +//     typedef typename Iterator::ValueType data_type;
   4.407 +//     typedef typename Iterator::PairReferenceType reference;
   4.408 +//     typedef typename Iterator::PairPointerType pointer;
   4.409 +//     typedef typename ConstIterator::PairReferenceType const_reference;
   4.410 +//     typedef typename ConstIterator::PairPointerType const_pointer;
   4.411 +//     typedef int difference_type;		
   4.412    };		
   4.413  
   4.414 +  template <typename _Base> 
   4.415 +  class ArrayMappableGraphExtender : public _Base {
   4.416 +  public:
   4.417 +
   4.418 +    typedef ArrayMappableGraphExtender<_Base> Graph;
   4.419 +    typedef _Base Parent;
   4.420 +
   4.421 +    typedef typename Parent::Node Node;
   4.422 +    typedef typename Parent::NodeIt NodeIt;
   4.423 +    typedef typename Parent::NodeIdMap NodeIdMap;
   4.424 +    typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
   4.425 +
   4.426 +    typedef typename Parent::Edge Edge;
   4.427 +    typedef typename Parent::EdgeIt EdgeIt;
   4.428 +    typedef typename Parent::EdgeIdMap EdgeIdMap;
   4.429 +    typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
   4.430 +
   4.431 +    
   4.432 +
   4.433 +    template <typename _Value>
   4.434 +    class NodeMap : public ArrayMap<Graph, Node, NodeIt, NodeIdMap, _Value> {
   4.435 +    public:
   4.436 +      typedef ArrayMappableGraphExtender<_Base> Graph;
   4.437 +
   4.438 +      typedef typename Graph::Node Node;
   4.439 +      typedef typename Graph::NodeIt NodeIt;
   4.440 +      typedef typename Graph::NodeIdMap NodeIdMap;
   4.441 +
   4.442 +      typedef ArrayMap<Graph, Node, NodeIt, NodeIdMap, _Value> Parent;
   4.443 +
   4.444 +      typedef typename Parent::Graph Graph;
   4.445 +      typedef typename Parent::Value Value;
   4.446 +
   4.447 +      NodeMap(const Graph& g) 
   4.448 +	: Parent(g, g.getNodeObserverRegistry()) {}
   4.449 +      NodeMap(const Graph& g, const Value& v) 
   4.450 +	: Parent(g, g.getNodeObserverRegistry(), v) {}
   4.451 +
   4.452 +    };
   4.453 +
   4.454 +    template <typename _Value>
   4.455 +    class EdgeMap : public ArrayMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> {
   4.456 +    public:
   4.457 +      typedef ArrayMappableGraphExtender<_Base> Graph;
   4.458 +
   4.459 +      typedef typename Graph::Edge Edge;
   4.460 +      typedef typename Graph::EdgeIt EdgeIt;
   4.461 +      typedef typename Graph::EdgeIdMap EdgeIdMap;
   4.462 +
   4.463 +      typedef ArrayMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> Parent;
   4.464 +
   4.465 +      typedef typename Parent::Graph Graph;
   4.466 +      typedef typename Parent::Value Value;
   4.467 +
   4.468 +      EdgeMap(const Graph& g) 
   4.469 +	: Parent(g, g.getEdgeObserverRegistry()) {}
   4.470 +      EdgeMap(const Graph& g, const Value& v) 
   4.471 +	: Parent(g, g.getEdgeObserverRegistry(), v) {}
   4.472 +
   4.473 +    };
   4.474 +    
   4.475 +  };
   4.476 +
   4.477  /// @}
   4.478  
   4.479  }
     5.1 --- a/src/lemon/bfs.h	Mon Oct 25 13:29:46 2004 +0000
     5.2 +++ b/src/lemon/bfs.h	Wed Oct 27 22:38:50 2004 +0000
     5.3 @@ -195,7 +195,7 @@
     5.4  	pred_node->set(u,INVALID);
     5.5        }
     5.6        
     5.7 -      int N=G->nodeNum();
     5.8 +      int N = countNodes(*G);
     5.9        std::vector<typename Graph::Node> Q(N);
    5.10        int Qh=0;
    5.11        int Qt=0;
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/lemon/clearable_graph_extender.h	Wed Oct 27 22:38:50 2004 +0000
     6.3 @@ -0,0 +1,28 @@
     6.4 +// -*- c++ -*-
     6.5 +
     6.6 +#ifndef LEMON_CLEARABLE_GRAPH_EXTENDER_H
     6.7 +#define LEMON_CLEARABLE_GRAPH_EXTENDER_H
     6.8 +
     6.9 +#include <lemon/invalid.h>
    6.10 +
    6.11 +
    6.12 +namespace lemon {
    6.13 +
    6.14 +  template <typename _Base> 
    6.15 +  class ClearableGraphExtender : public _Base {
    6.16 +  public:
    6.17 +
    6.18 +    typedef ClearableGraphExtender Graph;
    6.19 +    typedef _Base Parent;
    6.20 +
    6.21 +    void clear() {
    6.22 +      Parent::getNodeObserverRegistry().clear();
    6.23 +      Parent::getEdgeObserverRegistry().clear();
    6.24 +      Parent::clear();
    6.25 +    }
    6.26 +
    6.27 +  };
    6.28 +
    6.29 +}
    6.30 +
    6.31 +#endif
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/lemon/concept_check.h	Wed Oct 27 22:38:50 2004 +0000
     7.3 @@ -0,0 +1,80 @@
     7.4 +// -*- C++ -*-
     7.5 +// Modified for use in LEMON.
     7.6 +// We should really consider using Boost...
     7.7 +
     7.8 +
     7.9 +//
    7.10 +// (C) Copyright Jeremy Siek 2000.
    7.11 +// Distributed under the Boost Software License, Version 1.0. (See
    7.12 +// accompanying file LICENSE_1_0.txt or copy at
    7.13 +// http://www.boost.org/LICENSE_1_0.txt)
    7.14 +//
    7.15 +// Revision History:
    7.16 +//   05 May   2001: Workarounds for HP aCC from Thomas Matelich. (Jeremy Siek)
    7.17 +//   02 April 2001: Removed limits header altogether. (Jeremy Siek)
    7.18 +//   01 April 2001: Modified to use new <boost/limits.hpp> header. (JMaddock)
    7.19 +//
    7.20 +
    7.21 +// See http://www.boost.org/libs/concept_check for documentation.
    7.22 +
    7.23 +#ifndef LEMON_BOOST_CONCEPT_CHECKS_HPP
    7.24 +#define LEMON_BOOST_CONCEPT_CHECKS_HPP
    7.25 +
    7.26 +namespace lemon {
    7.27 +
    7.28 +  /*
    7.29 +    "inline" is used for ignore_unused_variable_warning()
    7.30 +    and function_requires() to make sure there is no
    7.31 +    overhead with g++.
    7.32 +  */
    7.33 +
    7.34 +  template <class T> inline void ignore_unused_variable_warning(const T&) { }
    7.35 +
    7.36 +  template <class Concept>
    7.37 +  inline void function_requires()
    7.38 +  {
    7.39 +#if !defined(NDEBUG)
    7.40 +    void (Concept::*x)() = & Concept::constraints;
    7.41 +    ignore_unused_variable_warning(x);
    7.42 +#endif
    7.43 +  }
    7.44 +
    7.45 +#define BOOST_CLASS_REQUIRE(type_var, ns, concept) \
    7.46 +  typedef void (ns::concept <type_var>::* func##type_var##concept)(); \
    7.47 +  template <func##type_var##concept Tp1_> \
    7.48 +  struct concept_checking_##type_var##concept { }; \
    7.49 +  typedef concept_checking_##type_var##concept< \
    7.50 +    BOOST_FPTR ns::concept<type_var>::constraints> \
    7.51 +    concept_checking_typedef_##type_var##concept
    7.52 +
    7.53 +#define BOOST_CLASS_REQUIRE2(type_var1, type_var2, ns, concept) \
    7.54 +  typedef void (ns::concept <type_var1,type_var2>::* \
    7.55 +     func##type_var1##type_var2##concept)(); \
    7.56 +  template <func##type_var1##type_var2##concept Tp1_> \
    7.57 +  struct concept_checking_##type_var1##type_var2##concept { }; \
    7.58 +  typedef concept_checking_##type_var1##type_var2##concept< \
    7.59 +    BOOST_FPTR ns::concept<type_var1,type_var2>::constraints> \
    7.60 +    concept_checking_typedef_##type_var1##type_var2##concept
    7.61 +
    7.62 +#define BOOST_CLASS_REQUIRE3(tv1, tv2, tv3, ns, concept) \
    7.63 +  typedef void (ns::concept <tv1,tv2,tv3>::* \
    7.64 +     func##tv1##tv2##tv3##concept)(); \
    7.65 +  template <func##tv1##tv2##tv3##concept Tp1_> \
    7.66 +  struct concept_checking_##tv1##tv2##tv3##concept { }; \
    7.67 +  typedef concept_checking_##tv1##tv2##tv3##concept< \
    7.68 +    BOOST_FPTR ns::concept<tv1,tv2,tv3>::constraints> \
    7.69 +    concept_checking_typedef_##tv1##tv2##tv3##concept
    7.70 +
    7.71 +#define BOOST_CLASS_REQUIRE4(tv1, tv2, tv3, tv4, ns, concept) \
    7.72 +  typedef void (ns::concept <tv1,tv2,tv3,tv4>::* \
    7.73 +     func##tv1##tv2##tv3##tv4##concept)(); \
    7.74 +  template <func##tv1##tv2##tv3##tv4##concept Tp1_> \
    7.75 +  struct concept_checking_##tv1##tv2##tv3##tv4##concept { }; \
    7.76 +  typedef concept_checking_##tv1##tv2##tv3##tv4##concept< \
    7.77 +    BOOST_FPTR ns::concept<tv1,tv2,tv3,tv4>::constraints> \
    7.78 +    concept_checking_typedef_##tv1##tv2##tv3##tv4##concept
    7.79 +
    7.80 +
    7.81 +} // namespace lemon
    7.82 +
    7.83 +#endif // LEMON_BOOST_CONCEPT_CHECKS_HPP
     8.1 --- a/src/lemon/default_map.h	Mon Oct 25 13:29:46 2004 +0000
     8.2 +++ b/src/lemon/default_map.h	Wed Oct 27 22:38:50 2004 +0000
     8.3 @@ -23,7 +23,7 @@
     8.4  
     8.5  ///\ingroup graphmaps
     8.6  ///\file
     8.7 -///\brief Graph maps that construates and destruates
     8.8 +///\brief Graph maps that construct and destruct
     8.9  ///their elements dynamically.
    8.10  
    8.11  namespace lemon {
    8.12 @@ -41,100 +41,185 @@
    8.13     */
    8.14  
    8.15  
    8.16 -  /** Macro to implement the DefaultMap.
    8.17 -   */
    8.18 -#define DEFAULT_MAP_BODY(DynMap, Value) \
    8.19 -{ \
    8.20 -\
    8.21 -public: \
    8.22 -\
    8.23 -typedef DynMap<MapRegistry, Value> Parent; \
    8.24 -\
    8.25 -typedef typename MapRegistry::Graph Graph; \
    8.26 -\
    8.27 -DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
    8.28 -DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
    8.29 -  : Parent(g, r, v) {} \
    8.30 -DefaultMap(const DefaultMap& copy) \
    8.31 -  : Parent(static_cast<const Parent&>(copy)) {} \
    8.32 -template <typename TT> \
    8.33 -DefaultMap(const DefaultMap<MapRegistry, TT>& copy) \
    8.34 -  : Parent(*copy.getGraph()) { \
    8.35 -  if (Parent::getGraph()) { \
    8.36 -    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
    8.37 -      Parent::operator[](it) = copy[it]; \
    8.38 -    } \
    8.39 -  } \
    8.40 -} \
    8.41 -DefaultMap& operator=(const DefaultMap& copy) { \
    8.42 -  Parent::operator=(static_cast<const Parent&>(copy)); \
    8.43 -  return *this; \
    8.44 -} \
    8.45 -template <typename TT> \
    8.46 -DefaultMap& operator=(const DefaultMap<MapRegistry, TT>& copy) { \
    8.47 -  if (Parent::getGraph() != copy.getGraph()) { \
    8.48 -    Parent::clear(); \
    8.49 -    Parent::MapBase::operator=(copy); \
    8.50 -    Parent::construct(); \
    8.51 -  } \
    8.52 -  if (Parent::getGraph()) { \
    8.53 -    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
    8.54 -      Parent::operator[](it) = copy[it]; \
    8.55 -    } \
    8.56 -  } \
    8.57 -  return *this; \
    8.58 -} \
    8.59 -};
    8.60  
    8.61 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap, typename _Value>
    8.62 +  struct DefaultMapSelector {
    8.63 +    typedef ArrayMap<_Graph, _Item, _ItemIt, _IdMap, _Value> Map;
    8.64 +  };
    8.65  
    8.66 -  template <typename MapRegistry, typename Type>
    8.67 -  class DefaultMap : public ArrayMap<MapRegistry, Type> 
    8.68 -  DEFAULT_MAP_BODY(ArrayMap, Type);
    8.69 +  // bool
    8.70 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
    8.71 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, bool> {
    8.72 +    typedef VectorMap<_Graph, _Item, _IdMap, bool> Map;
    8.73 +  };
    8.74  
    8.75 -  template <typename MapRegistry>
    8.76 -  class DefaultMap<MapRegistry, bool> 
    8.77 -    : public VectorMap<MapRegistry, bool> 
    8.78 -  DEFAULT_MAP_BODY(VectorMap, bool);
    8.79 +  // char
    8.80 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
    8.81 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, char> {
    8.82 +    typedef VectorMap<_Graph, _Item, _IdMap, char> Map;
    8.83 +  };
    8.84  
    8.85 -  template <typename MapRegistry>
    8.86 -  class DefaultMap<MapRegistry, char> 
    8.87 -    : public VectorMap<MapRegistry, char> 
    8.88 -  DEFAULT_MAP_BODY(VectorMap, char);
    8.89 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
    8.90 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed char> {
    8.91 +    typedef VectorMap<_Graph, _Item, _IdMap, signed char> Map;
    8.92 +  };
    8.93  
    8.94 -  template <typename MapRegistry>
    8.95 -  class DefaultMap<MapRegistry, int> 
    8.96 -    : public VectorMap<MapRegistry, int> 
    8.97 -  DEFAULT_MAP_BODY(VectorMap, int);
    8.98 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
    8.99 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned char> {
   8.100 +    typedef VectorMap<_Graph, _Item, _IdMap, unsigned char> Map;
   8.101 +  };
   8.102  
   8.103 -  template <typename MapRegistry>
   8.104 -  class DefaultMap<MapRegistry, short> 
   8.105 -    : public VectorMap<MapRegistry, short> 
   8.106 -  DEFAULT_MAP_BODY(VectorMap, short);
   8.107  
   8.108 -  template <typename MapRegistry>
   8.109 -  class DefaultMap<MapRegistry, long> 
   8.110 -    : public VectorMap<MapRegistry, long> 
   8.111 -  DEFAULT_MAP_BODY(VectorMap, long);
   8.112 +  // int
   8.113 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
   8.114 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed int> {
   8.115 +    typedef VectorMap<_Graph, _Item, _IdMap, signed int> Map;
   8.116 +  };
   8.117  
   8.118 -  template <typename MapRegistry>
   8.119 -  class DefaultMap<MapRegistry, float> 
   8.120 -    : public VectorMap<MapRegistry, float> 
   8.121 -  DEFAULT_MAP_BODY(VectorMap, float);
   8.122 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
   8.123 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned int> {
   8.124 +    typedef VectorMap<_Graph, _Item, _IdMap, unsigned int> Map;
   8.125 +  };
   8.126  
   8.127 -  template <typename MapRegistry>
   8.128 -  class DefaultMap<MapRegistry, double> 
   8.129 -    : public VectorMap<MapRegistry, double> 
   8.130 -  DEFAULT_MAP_BODY(VectorMap, double);
   8.131  
   8.132 -  template <typename MapRegistry>
   8.133 -  class DefaultMap<MapRegistry, long double> 
   8.134 -    : public VectorMap<MapRegistry, long double> 
   8.135 -  DEFAULT_MAP_BODY(VectorMap, long double);
   8.136 +  // short
   8.137 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
   8.138 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed short> {
   8.139 +    typedef VectorMap<_Graph, _Item, _IdMap, signed short> Map;
   8.140 +  };
   8.141  
   8.142 -  template <typename MapRegistry, typename Type>
   8.143 -  class DefaultMap<MapRegistry, Type*>
   8.144 -    : public VectorMap<MapRegistry, Type*> 
   8.145 -  DEFAULT_MAP_BODY(VectorMap, Type*);
   8.146 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
   8.147 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned short> {
   8.148 +    typedef VectorMap<_Graph, _Item, _IdMap, unsigned short> Map;
   8.149 +  };
   8.150 +
   8.151 +
   8.152 +  // long
   8.153 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
   8.154 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed long> {
   8.155 +    typedef VectorMap<_Graph, _Item, _IdMap, signed long> Map;
   8.156 +  };
   8.157 +
   8.158 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
   8.159 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned long> {
   8.160 +    typedef VectorMap<_Graph, _Item, _IdMap, unsigned long> Map;
   8.161 +  };
   8.162 +
   8.163 +  // \todo handling long long type
   8.164 +
   8.165 +
   8.166 +  // float
   8.167 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
   8.168 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, float> {
   8.169 +    typedef VectorMap<_Graph, _Item, _IdMap, float> Map;
   8.170 +  };
   8.171 +
   8.172 +
   8.173 +  // double
   8.174 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
   8.175 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, double> {
   8.176 +    typedef VectorMap<_Graph, _Item, _IdMap,  double> Map;
   8.177 +  };
   8.178 +
   8.179 +
   8.180 +  // long double
   8.181 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
   8.182 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, long double> {
   8.183 +    typedef VectorMap<_Graph, _Item, _IdMap, long double> Map;
   8.184 +  };
   8.185 +
   8.186 +
   8.187 +  // pointer
   8.188 +  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap, typename _Ptr>
   8.189 +  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Ptr*> {
   8.190 +    typedef VectorMap<_Graph, _Item, _IdMap, _Ptr*> Map;
   8.191 +  };
   8.192 +
   8.193 +
   8.194 +
   8.195 +  template <typename _Graph, 
   8.196 +	    typename _Item,
   8.197 +	    typename _ItemIt,
   8.198 +	    typename _IdMap,
   8.199 +	    typename _Value>
   8.200 +  class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map {
   8.201 +  public:
   8.202 +    typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map Parent;
   8.203 +    typedef DefaultMap<_Graph, _Item, _ItemIt, _IdMap, bool> Map;
   8.204 +    
   8.205 +    typedef typename Parent::Graph Graph;
   8.206 +    typedef typename Parent::Registry Registry;
   8.207 +    typedef typename Parent::ValueType ValueType;
   8.208 +
   8.209 +    DefaultMap(const Graph& _g, Registry& _r) : Parent(_g, _r) {}
   8.210 +    DefaultMap(const Graph& _g, Registry& _r, const ValueType& _v) : Parent(_g, _r, _v) {}
   8.211 +  };
   8.212 +
   8.213 +
   8.214 +
   8.215 +  template <typename _Base> 
   8.216 +  class DefaultMappableGraphExtender : public _Base {
   8.217 +  public:
   8.218 +
   8.219 +    typedef DefaultMappableGraphExtender<_Base> Graph;
   8.220 +    typedef _Base Parent;
   8.221 +
   8.222 +    typedef typename Parent::Node Node;
   8.223 +    typedef typename Parent::NodeIt NodeIt;
   8.224 +    typedef typename Parent::NodeIdMap NodeIdMap;
   8.225 +    typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
   8.226 +
   8.227 +    typedef typename Parent::Edge Edge;
   8.228 +    typedef typename Parent::EdgeIt EdgeIt;
   8.229 +    typedef typename Parent::EdgeIdMap EdgeIdMap;
   8.230 +    typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
   8.231 +
   8.232 +    
   8.233 +
   8.234 +    template <typename _Value>
   8.235 +    class NodeMap : public DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> {
   8.236 +    public:
   8.237 +      typedef DefaultMappableGraphExtender<_Base> Graph;
   8.238 +
   8.239 +      typedef typename Graph::Node Node;
   8.240 +      typedef typename Graph::NodeIt NodeIt;
   8.241 +      typedef typename Graph::NodeIdMap NodeIdMap;
   8.242 +
   8.243 +      typedef DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> Parent;
   8.244 +
   8.245 +      typedef typename Parent::Graph Graph;
   8.246 +      typedef typename Parent::ValueType ValueType;
   8.247 +
   8.248 +      NodeMap(const Graph& g) 
   8.249 +	: Parent(g, g.getNodeObserverRegistry()) {}
   8.250 +      NodeMap(const Graph& g, const ValueType& v) 
   8.251 +	: Parent(g, g.getNodeObserverRegistry(), v) {}
   8.252 +
   8.253 +    };
   8.254 +
   8.255 +    template <typename _Value>
   8.256 +    class EdgeMap : public DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> {
   8.257 +    public:
   8.258 +      typedef DefaultMappableGraphExtender<_Base> Graph;
   8.259 +
   8.260 +      typedef typename Graph::Edge Edge;
   8.261 +      typedef typename Graph::EdgeIt EdgeIt;
   8.262 +      typedef typename Graph::EdgeIdMap EdgeIdMap;
   8.263 +
   8.264 +      typedef DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> Parent;
   8.265 +
   8.266 +      typedef typename Parent::Graph Graph;
   8.267 +      typedef typename Parent::ValueType ValueType;
   8.268 +
   8.269 +      EdgeMap(const Graph& g) 
   8.270 +	: Parent(g, g.getEdgeObserverRegistry()) {}
   8.271 +      EdgeMap(const Graph& g, const ValueType& v) 
   8.272 +	: Parent(g, g.getEdgeObserverRegistry(), v) {}
   8.273 +
   8.274 +    };
   8.275 +    
   8.276 +  };
   8.277 +
   8.278  
   8.279  }
   8.280  
     9.1 --- a/src/lemon/dfs.h	Mon Oct 25 13:29:46 2004 +0000
     9.2 +++ b/src/lemon/dfs.h	Wed Oct 27 22:38:50 2004 +0000
     9.3 @@ -23,7 +23,7 @@
     9.4  ///
     9.5  ///\todo Revise Manual.
     9.6  
     9.7 -#include <lemon/bin_heap.h>
     9.8 +#include <lemon/graph_utils.h>
     9.9  #include <lemon/invalid.h>
    9.10  
    9.11  namespace lemon {
    9.12 @@ -193,12 +193,12 @@
    9.13  	pred_node->set(u,INVALID);
    9.14        }
    9.15        
    9.16 -      int N=G->nodeNum();
    9.17 +      int N = countNodes(*G);
    9.18        std::vector<typename Graph::OutEdgeIt> Q(N);
    9.19  
    9.20        int Qh=0;
    9.21        
    9.22 -      G->first(Q[Qh],s);
    9.23 +      Q[Qh] = OutEdgeIt(*G, s);
    9.24        distance->set(s, 0);
    9.25  
    9.26        Node n=s;
    9.27 @@ -209,7 +209,7 @@
    9.28  	  if((m=G->head(e))!=s && (*predecessor)[m=G->head(e)]==INVALID) {
    9.29  	    predecessor->set(m,e);
    9.30  	    pred_node->set(m,n);
    9.31 -	    G->first(Q[++Qh],m);
    9.32 +	    Q[++Qh] = OutEdgeIt(*G, m);
    9.33  	    distance->set(m,Qh);
    9.34  	    n=m;
    9.35  	  }
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/lemon/erasable_graph_extender.h	Wed Oct 27 22:38:50 2004 +0000
    10.3 @@ -0,0 +1,48 @@
    10.4 +// -*- c++ -*-
    10.5 +
    10.6 +#ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H
    10.7 +#define LEMON_ERASABLE_GRAPH_EXTENDER_H
    10.8 +
    10.9 +#include <lemon/invalid.h>
   10.10 +
   10.11 +
   10.12 +namespace lemon {
   10.13 +
   10.14 +  template <typename _Base> 
   10.15 +  class ErasableGraphExtender : public _Base {
   10.16 +  public:
   10.17 +
   10.18 +    typedef ErasableGraphExtender Graph;
   10.19 +    typedef _Base Parent;
   10.20 +
   10.21 +    typedef typename Parent::Node Node;
   10.22 +    typedef typename Parent::Edge Edge;
   10.23 +
   10.24 +    void erase(const Node& node) {
   10.25 +      Edge edge;
   10.26 +      Parent::firstOut(edge, node);
   10.27 +      while (edge != INVALID ) {
   10.28 +	erase(edge);
   10.29 +	Parent::firstOut(edge, node);
   10.30 +      } 
   10.31 +
   10.32 +      Parent::firstIn(edge, node);
   10.33 +      while (edge != INVALID ) {
   10.34 +	erase(edge);
   10.35 +	Parent::firstIn(edge, node);
   10.36 +      }
   10.37 +
   10.38 +      Parent::getNodeObserverRegistry().erase(node);
   10.39 +      Parent::erase(node);
   10.40 +    }
   10.41 +    
   10.42 +    void erase(const Edge& edge) {
   10.43 +      Parent::getEdgeObserverRegistry().erase(edge);
   10.44 +      Parent::erase(edge);
   10.45 +    }
   10.46 +
   10.47 +  };
   10.48 +
   10.49 +}
   10.50 +
   10.51 +#endif
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/lemon/extendable_graph_extender.h	Wed Oct 27 22:38:50 2004 +0000
    11.3 @@ -0,0 +1,34 @@
    11.4 +// -*- c++ -*-
    11.5 +
    11.6 +#ifndef LEMON_EXTENDABLE_GRAPH_EXTENDER_H
    11.7 +#define LEMON_EXTENDABLE_GRAPH_EXTENDER_H
    11.8 +
    11.9 +namespace lemon {
   11.10 +
   11.11 +  template <typename _Base> 
   11.12 +  class ExtendableGraphExtender : public _Base {
   11.13 +  public:
   11.14 +
   11.15 +    typedef ExtendableGraphExtender Graph;
   11.16 +    typedef _Base Parent;
   11.17 +
   11.18 +    typedef typename Parent::Node Node;
   11.19 +    typedef typename Parent::Edge Edge;
   11.20 +
   11.21 +    Node addNode() {
   11.22 +      Node node = Parent::addNode();
   11.23 +      Parent::getNodeObserverRegistry().add(node);
   11.24 +      return node;
   11.25 +    }
   11.26 +    
   11.27 +    Edge addEdge(const Node& from, const Node& to) {
   11.28 +      Edge edge = Parent::addEdge(from, to);
   11.29 +      Parent::getEdgeObserverRegistry().add(edge);
   11.30 +      return edge;
   11.31 +    }
   11.32 +
   11.33 +  };
   11.34 +
   11.35 +}
   11.36 +
   11.37 +#endif
    12.1 --- a/src/lemon/full_graph.h	Mon Oct 25 13:29:46 2004 +0000
    12.2 +++ b/src/lemon/full_graph.h	Wed Oct 27 22:38:50 2004 +0000
    12.3 @@ -17,20 +17,21 @@
    12.4  #ifndef LEMON_FULL_GRAPH_H
    12.5  #define LEMON_FULL_GRAPH_H
    12.6  
    12.7 +
    12.8 +#include <lemon/idmappable_graph_extender.h>
    12.9 +
   12.10 +#include <lemon/iterable_graph_extender.h>
   12.11 +
   12.12 +#include <lemon/alteration_observer_registry.h>
   12.13 +#include <lemon/default_map.h>
   12.14 +
   12.15  ///\ingroup graphs
   12.16  ///\file
   12.17  ///\brief FullGraph and SymFullGraph classes.
   12.18  
   12.19 -#include <vector>
   12.20 -#include <climits>
   12.21  
   12.22  #include <lemon/invalid.h>
   12.23  
   12.24 -#include <lemon/map_registry.h>
   12.25 -#include <lemon/array_map.h>
   12.26 -
   12.27 -#include <lemon/map_defines.h>
   12.28 -
   12.29  namespace lemon {
   12.30  
   12.31  /// \addtogroup graphs
   12.32 @@ -48,34 +49,26 @@
   12.33    ///\todo Don't we need SymEdgeMap?
   12.34    ///
   12.35    ///\author Alpar Juttner
   12.36 -  class FullGraph {
   12.37 +  class FullGraphBase {
   12.38      int NodeNum;
   12.39      int EdgeNum;
   12.40    public:
   12.41  
   12.42 -    typedef FullGraph Graph;
   12.43 +    typedef FullGraphBase Graph;
   12.44  
   12.45      class Node;
   12.46      class Edge;
   12.47  
   12.48 -    class NodeIt;
   12.49 -    class EdgeIt;
   12.50 -    class OutEdgeIt;
   12.51 -    class InEdgeIt;
   12.52 -    
   12.53 -
   12.54 -    // Create map registries.
   12.55 -    CREATE_MAP_REGISTRIES;
   12.56 -    // Create node and edge maps.
   12.57 -    CREATE_MAPS(ArrayMap);
   12.58 -    
   12.59    public:
   12.60  
   12.61 +    FullGraphBase() {}
   12.62 +
   12.63 +
   12.64      ///Creates a full graph with \c n nodes.
   12.65 -    FullGraph(int n) : NodeNum(n), EdgeNum(NodeNum*NodeNum) { }
   12.66 +    void construct(int n) { NodeNum = n; EdgeNum = n * n; }
   12.67      ///
   12.68 -    FullGraph(const FullGraph &_g)
   12.69 -      : NodeNum(_g.nodeNum()), EdgeNum(NodeNum*NodeNum) { }
   12.70 +    //    FullGraphBase(const FullGraphBase &_g)
   12.71 +    //      : NodeNum(_g.nodeNum()), EdgeNum(NodeNum*NodeNum) { }
   12.72      
   12.73      ///Number of nodes.
   12.74      int nodeNum() const { return NodeNum; }
   12.75 @@ -93,17 +86,9 @@
   12.76      ///\sa id(Edge)
   12.77      int maxEdgeId() const { return EdgeNum-1; }
   12.78  
   12.79 -    Node tail(Edge e) const { return e.n%NodeNum; }
   12.80 -    Node head(Edge e) const { return e.n/NodeNum; }
   12.81 +    Node tail(Edge e) const { return e.id % NodeNum; }
   12.82 +    Node head(Edge e) const { return e.id / NodeNum; }
   12.83  
   12.84 -    NodeIt& first(NodeIt& v) const {
   12.85 -      v=NodeIt(*this); return v; }
   12.86 -    EdgeIt& first(EdgeIt& e) const { 
   12.87 -      e=EdgeIt(*this); return e; }
   12.88 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
   12.89 -      e=OutEdgeIt(*this,v); return e; }
   12.90 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
   12.91 -      e=InEdgeIt(*this,v); return e; }
   12.92  
   12.93      /// Node ID.
   12.94      
   12.95 @@ -113,7 +98,8 @@
   12.96      ///
   12.97      /// The ID of the \ref INVALID node is -1.
   12.98      ///\return The ID of the node \c v. 
   12.99 -    static int id(Node v) { return v.n; }
  12.100 +
  12.101 +    static int id(Node v) { return v.id; }
  12.102      /// Edge ID.
  12.103      
  12.104      /// The ID of a valid Edge is a nonnegative integer not greater than
  12.105 @@ -122,7 +108,7 @@
  12.106      ///
  12.107      /// The ID of the \ref INVALID edge is -1.
  12.108      ///\return The ID of the edge \c e. 
  12.109 -    static int id(Edge e) { return e.n; }
  12.110 +    static int id(Edge e) { return e.id; }
  12.111  
  12.112      /// Finds an edge between two nodes.
  12.113      
  12.114 @@ -134,110 +120,102 @@
  12.115      /// \return The found edge or INVALID if there is no such an edge.
  12.116      Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  12.117      {
  12.118 -      return prev.n == -1 ? Edge(*this, u.n, v.n) : INVALID;
  12.119 +      return prev.id == -1 ? Edge(*this, u.id, v.id) : INVALID;
  12.120      }
  12.121      
  12.122        
  12.123      class Node {
  12.124 -      friend class FullGraph;
  12.125 -      template <typename T> friend class NodeMap;
  12.126 -
  12.127 -      friend class Edge;
  12.128 -      friend class OutEdgeIt;
  12.129 -      friend class InEdgeIt;
  12.130 -      friend class SymEdge;
  12.131 +      friend class FullGraphBase;
  12.132  
  12.133      protected:
  12.134 -      int n;
  12.135 -      friend int FullGraph::id(Node v); 
  12.136 -      Node(int nn) {n=nn;}
  12.137 +      int id;
  12.138 +      Node(int _id) { id = _id;}
  12.139      public:
  12.140        Node() {}
  12.141 -      Node (Invalid) { n=-1; }
  12.142 -      bool operator==(const Node i) const {return n==i.n;}
  12.143 -      bool operator!=(const Node i) const {return n!=i.n;}
  12.144 -      bool operator<(const Node i) const {return n<i.n;}
  12.145 +      Node (Invalid) { id = -1; }
  12.146 +      bool operator==(const Node node) const {return id == node.id;}
  12.147 +      bool operator!=(const Node node) const {return id != node.id;}
  12.148 +      bool operator<(const Node node) const {return id < node.id;}
  12.149      };
  12.150      
  12.151 -    class NodeIt : public Node {
  12.152 -      const FullGraph *G;
  12.153 -      friend class FullGraph;
  12.154 +
  12.155 +
  12.156 +    class Edge {
  12.157 +      friend class FullGraphBase;
  12.158 +      
  12.159 +    protected:
  12.160 +      int id;  // NodeNum * head + tail;
  12.161 +
  12.162 +      Edge(int _id) : id(_id) {}
  12.163 +
  12.164 +      Edge(const FullGraphBase& _graph, int tail, int head) 
  12.165 +	: id(_graph.NodeNum * head+tail) {}
  12.166      public:
  12.167 -      NodeIt() : Node() { }
  12.168 -      NodeIt(const FullGraph& _G,Node n) : Node(n), G(&_G) { }
  12.169 -      NodeIt(Invalid i) : Node(i) { }
  12.170 -      NodeIt(const FullGraph& _G) : Node(_G.NodeNum?0:-1), G(&_G) { }
  12.171 -      ///\todo Undocumented conversion Node -\> NodeIt.
  12.172 -      NodeIt& operator++() { n=(n+2)%(G->NodeNum+1)-1;return *this; }
  12.173 +      Edge() { }
  12.174 +      Edge (Invalid) { id = -1; }
  12.175 +      bool operator==(const Edge edge) const {return id == edge.id;}
  12.176 +      bool operator!=(const Edge edge) const {return id != edge.id;}
  12.177 +      bool operator<(const Edge edge) const {return id < edge.id;}
  12.178      };
  12.179  
  12.180 -    class Edge {
  12.181 -      friend class FullGraph;
  12.182 -      template <typename T> friend class EdgeMap;
  12.183 -      
  12.184 -      friend class Node;
  12.185 -      friend class NodeIt;
  12.186 -    protected:
  12.187 -      int n; //NodeNum*head+tail;
  12.188 -      friend int FullGraph::id(Edge e);
  12.189 +    void first(Node& node) const {
  12.190 +      node.id = NodeNum-1;
  12.191 +    }
  12.192  
  12.193 -      Edge(int nn) : n(nn) {}
  12.194 -      Edge(const FullGraph &G, int tail, int head) : n(G.NodeNum*head+tail) {}
  12.195 -    public:
  12.196 -      Edge() { }
  12.197 -      Edge (Invalid) { n=-1; }
  12.198 -      bool operator==(const Edge i) const {return n==i.n;}
  12.199 -      bool operator!=(const Edge i) const {return n!=i.n;}
  12.200 -      bool operator<(const Edge i) const {return n<i.n;}
  12.201 -      ///\bug This is a workaround until somebody tells me how to
  12.202 -      ///make class \c SymFullGraph::SymEdgeMap friend of Edge
  12.203 -      int &idref() {return n;}
  12.204 -      const int &idref() const {return n;}
  12.205 -    };
  12.206 +    static void next(Node& node) {
  12.207 +      --node.id;
  12.208 +    }
  12.209 +
  12.210 +    void first(Edge& edge) const {
  12.211 +      edge.id = EdgeNum-1;
  12.212 +    }
  12.213 +
  12.214 +    static void next(Edge& edge) {
  12.215 +      --edge.id;
  12.216 +    }
  12.217 +
  12.218 +    void firstOut(Edge& edge, const Node& node) const {
  12.219 +      edge.id = EdgeNum + node.id - NodeNum;
  12.220 +    }
  12.221 +
  12.222 +    void nextOut(Edge& edge) const {
  12.223 +      edge.id -= NodeNum;
  12.224 +      if (edge.id < 0) edge.id = -1;
  12.225 +    }
  12.226 +
  12.227 +    void firstIn(Edge& edge, const Node& node) const {
  12.228 +      edge.id = node.id * NodeNum;
  12.229 +    }
  12.230      
  12.231 -    class EdgeIt : public Edge {
  12.232 -      friend class FullGraph;
  12.233 -    public:
  12.234 -      EdgeIt(const FullGraph& _G) : Edge(_G.EdgeNum-1) { }
  12.235 -      EdgeIt(const FullGraph&, Edge e) : Edge(e) { }
  12.236 -      EdgeIt (Invalid i) : Edge(i) { }
  12.237 -      EdgeIt() : Edge() { }
  12.238 -      EdgeIt& operator++() { --n; return *this; }
  12.239 -
  12.240 -      ///\bug This is a workaround until somebody tells me how to
  12.241 -      ///make class \c SymFullGraph::SymEdgeMap friend of Edge
  12.242 -      int &idref() {return n;}
  12.243 -    };
  12.244 -    
  12.245 -    class OutEdgeIt : public Edge {
  12.246 -      const FullGraph *G;
  12.247 -      friend class FullGraph;
  12.248 -    public: 
  12.249 -      OutEdgeIt() : Edge() { }
  12.250 -      OutEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { }
  12.251 -      OutEdgeIt (Invalid i) : Edge(i) { }
  12.252 -
  12.253 -      OutEdgeIt(const FullGraph& _G,const Node v) : Edge(v.n), G(&_G) {}
  12.254 -      
  12.255 -      OutEdgeIt& operator++()
  12.256 -      { n+=G->NodeNum; if(n>=G->EdgeNum) n=-1; return *this; }
  12.257 -
  12.258 -    };
  12.259 -    
  12.260 -    class InEdgeIt : public Edge {
  12.261 -      const FullGraph *G;
  12.262 -      friend class FullGraph;
  12.263 -    public: 
  12.264 -      InEdgeIt() : Edge() { }
  12.265 -      InEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { }
  12.266 -      InEdgeIt (Invalid i) : Edge(i) { }
  12.267 -      InEdgeIt(const FullGraph& _G,Node v) : Edge(v.n*_G.NodeNum), G(&_G) {}
  12.268 -      InEdgeIt& operator++()
  12.269 -      { if(!((++n)%G->NodeNum)) n=-1; return *this; }
  12.270 -    };
  12.271 +    void nextIn(Edge& edge) const {
  12.272 +      ++edge.id;
  12.273 +      if (edge.id % NodeNum == 0) edge.id = -1;
  12.274 +    }
  12.275  
  12.276    };
  12.277  
  12.278 +
  12.279 +  typedef AlterableGraphExtender<FullGraphBase> AlterableFullGraphBase;
  12.280 +  typedef IterableGraphExtender<AlterableFullGraphBase> IterableFullGraphBase;
  12.281 +  typedef IdMappableGraphExtender<IterableFullGraphBase> IdMappableFullGraphBase;
  12.282 +  typedef DefaultMappableGraphExtender<IdMappableFullGraphBase> MappableFullGraphBase;
  12.283 +
  12.284 +  class FullGraph : public MappableFullGraphBase {
  12.285 +  public:
  12.286 +
  12.287 +    FullGraph(int n) { construct(n); }
  12.288 +  };
  12.289 +
  12.290 +  template <>
  12.291 +  int countNodes<FullGraph>(const FullGraph& graph) {
  12.292 +    return graph.nodeNum();
  12.293 +  }
  12.294 +
  12.295 +  template <>
  12.296 +  int countEdges<FullGraph>(const FullGraph& graph) {
  12.297 +    return graph.edgeNum();
  12.298 +  }
  12.299 +
  12.300    /// @}  
  12.301  
  12.302  } //namespace lemon
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/lemon/graph_utils.h	Wed Oct 27 22:38:50 2004 +0000
    13.3 @@ -0,0 +1,174 @@
    13.4 +/* -*- C++ -*-
    13.5 + * src/lemon/graph_utils.h - Part of LEMON, a generic C++ optimization library
    13.6 + *
    13.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    13.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    13.9 + *
   13.10 + * Permission to use, modify and distribute this software is granted
   13.11 + * provided that this copyright notice appears in all copies. For
   13.12 + * precise terms see the accompanying LICENSE file.
   13.13 + *
   13.14 + * This software is provided "AS IS" with no warranty of any kind,
   13.15 + * express or implied, and with no claim as to its suitability for any
   13.16 + * purpose.
   13.17 + *
   13.18 + */
   13.19 +
   13.20 +#ifndef LEMON_GRAPH_UTILS_H
   13.21 +#define LEMON_GRAPH_UTILS_H
   13.22 +
   13.23 +#include <iterator>
   13.24 +
   13.25 +#include <lemon/invalid.h>
   13.26 +
   13.27 +///\ingroup utils
   13.28 +///\file
   13.29 +///\brief Graph utils.
   13.30 +///
   13.31 +
   13.32 +
   13.33 +namespace lemon {
   13.34 +
   13.35 +  // counters in the graph
   13.36 +  /// \brief Function to count the items in the graph.
   13.37 +  ///
   13.38 +  /// This function counts the items in the graph.
   13.39 +  /// The complexity of the function is O(n) because
   13.40 +  /// it iterates on all of the items.
   13.41 +
   13.42 +  template <typename Graph, typename ItemIt>
   13.43 +  inline int countItems(const Graph& _g) {
   13.44 +    int num = 0;
   13.45 +    for (ItemIt it(_g); it != INVALID; ++it) {
   13.46 +      ++num;
   13.47 +    }
   13.48 +    return num;
   13.49 +  }
   13.50 +
   13.51 +  /// \brief Function to count the nodes in the graph.
   13.52 +  ///
   13.53 +  /// This function counts the nodes in the graph.
   13.54 +  /// The complexity of the function is O(n) but for some
   13.55 +  /// graph structure it is specialized to O(1).
   13.56 +
   13.57 +  template <typename Graph>
   13.58 +  inline int countNodes(const Graph& _g) {
   13.59 +    return countItems<Graph, typename Graph::NodeIt>(_g);
   13.60 +  }
   13.61 +
   13.62 +  /// \brief Function to count the edges in the graph.
   13.63 +  ///
   13.64 +  /// This function counts the edges in the graph.
   13.65 +  /// The complexity of the function is O(e) but for some
   13.66 +  /// graph structure it is specialized to O(1).
   13.67 +  template <typename Graph>
   13.68 +  inline int countEdges(const Graph& _g) {
   13.69 +    return countItems<Graph, typename Graph::EdgeIt>(_g);
   13.70 +  }
   13.71 +
   13.72 +  /// \brief Function to count the symmetric edges in the graph.
   13.73 +  ///
   13.74 +  /// This function counts the symmetric edges in the graph.
   13.75 +  /// The complexity of the function is O(e) but for some
   13.76 +  /// graph structure it is specialized to O(1).
   13.77 +  template <typename Graph>
   13.78 +  inline int countSymEdges(const Graph& _g) {
   13.79 +    return countItems<Graph, typename Graph::SymEdgeIt>(_g);
   13.80 +  }
   13.81 +
   13.82 +  template <typename Graph, typename DegIt>
   13.83 +  inline int countNodeDegree(const Graph& _g, const typename Graph::Node& _n) {
   13.84 +    int num = 0;
   13.85 +    for (DegIt it(_g, _n); it != INVALID; ++it) {
   13.86 +      ++num;
   13.87 +    }
   13.88 +    return num;
   13.89 +  }
   13.90 +
   13.91 +  template <typename Graph>
   13.92 +  inline int countOutEdges(const Graph& _g,  const typename Graph::Node& _n) {
   13.93 +    return countNodeDegree<Graph, typename Graph::OutEdgeIt>(_g, _n);
   13.94 +  }
   13.95 +
   13.96 +  template <typename Graph>
   13.97 +  inline int countInEdges(const Graph& _g,  const typename Graph::Node& _n) {
   13.98 +    return countNodeDegree<Graph, typename Graph::InEdgeIt>(_g, _n);
   13.99 +  }
  13.100 +
  13.101 +  // graph copy
  13.102 +
  13.103 +  template <
  13.104 +    typename DestinationGraph, 
  13.105 +    typename SourceGraph, 
  13.106 +    typename NodeBijection>
  13.107 +  void copyNodes(DestinationGraph& _d, const SourceGraph& _s, 
  13.108 +		 NodeBijection& _nb) {    
  13.109 +    for (typename SourceGraph::NodeIt it(_s); it != INVALID; ++it) {
  13.110 +      _nb[it] = _d.addNode();
  13.111 +    }
  13.112 +  }
  13.113 +
  13.114 +  template <
  13.115 +    typename DestinationGraph, 
  13.116 +    typename SourceGraph, 
  13.117 +    typename NodeBijection,
  13.118 +    typename EdgeBijection>
  13.119 +  void copyEdges(DestinationGraph& _d, const SourceGraph& _s,
  13.120 +		 const NodeBijection& _nb, EdgeBijection& _eb) {    
  13.121 +    for (typename SourceGraph::EdgeIt it(_s); it != INVALID; ++it) {
  13.122 +      _eb[it] = _d.addEdge(_nb[_s.tail(it)], _nb[_s.head(it)]);
  13.123 +    }
  13.124 +  }
  13.125 +
  13.126 +  template <
  13.127 +    typename DestinationGraph, 
  13.128 +    typename SourceGraph, 
  13.129 +    typename NodeBijection,
  13.130 +    typename EdgeBijection>
  13.131 +  void copyGraph(DestinationGraph& _d, const SourceGraph& _s, 
  13.132 +		 NodeBijection& _nb, EdgeBijection& _eb) {
  13.133 +    nodeCopy(_d, _s, _nb);
  13.134 +    edgeCopy(_d, _s, _nb, _eb);
  13.135 +  }
  13.136 + 
  13.137 +   template <
  13.138 +    typename _DestinationGraph, 
  13.139 +    typename _SourceGraph, 
  13.140 +    typename _NodeBijection 
  13.141 +    =typename _SourceGraph::template NodeMap<typename _DestinationGraph::Node>,
  13.142 +    typename _EdgeBijection 
  13.143 +    =typename _SourceGraph::template EdgeMap<typename _DestinationGraph::Edge>
  13.144 +   >
  13.145 +   class GraphCopy {
  13.146 +   public:
  13.147 +
  13.148 +     typedef _DestinationGraph DestinationGraph;
  13.149 +     typedef _SourceGraph SourceGraph;
  13.150 +
  13.151 +     typedef _NodeBijection NodeBijection;
  13.152 +     typedef _EdgeBijection EdgeBijection;
  13.153 +
  13.154 +   protected:          
  13.155 +
  13.156 +     NodeBijection node_bijection;
  13.157 +     EdgeBijection edge_bijection;     
  13.158 +
  13.159 +   public:
  13.160 +     
  13.161 +     GraphCopy(DestinationGraph& _d, const SourceGraph& _s) {
  13.162 +       copyGraph(_d, _s, node_bijection, edge_bijection);
  13.163 +     }
  13.164 +
  13.165 +     const NodeBijection& getNodeBijection() const {
  13.166 +       return node_bijection;
  13.167 +     }
  13.168 +
  13.169 +     const EdgeBijection& getEdgeBijection() const {
  13.170 +       return edge_bijection;
  13.171 +     }
  13.172 +     
  13.173 +   };
  13.174 +		   		  		 		
  13.175 +}
  13.176 +
  13.177 +#endif
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/lemon/idmappable_graph_extender.h	Wed Oct 27 22:38:50 2004 +0000
    14.3 @@ -0,0 +1,52 @@
    14.4 +// -*- c++ -*-
    14.5 +
    14.6 +#ifndef LEMON_IDMAPPABLE_GRAPH_EXTENDER_H
    14.7 +#define LEMON_IDMAPPABLE_GRAPH_EXTENDER_H
    14.8 +
    14.9 +
   14.10 +namespace lemon {
   14.11 +
   14.12 +  template <typename Base> 
   14.13 +  class IdMappableGraphExtender : public Base {
   14.14 +  public:
   14.15 +
   14.16 +    typedef IdMappableGraphExtender Graph;
   14.17 +    typedef Base Parent;
   14.18 + 
   14.19 +    typedef typename Parent::Node Node;
   14.20 +    typedef typename Parent::Edge Edge;
   14.21 +
   14.22 +
   14.23 +  public:
   14.24 +
   14.25 +    class NodeIdMap {
   14.26 +    private:
   14.27 +      const Graph* graph;
   14.28 +
   14.29 +    public:
   14.30 +      NodeIdMap(const Graph& g) : graph(&g) {}
   14.31 +
   14.32 +      int operator[](const Node& node) const { return graph->id(node); }
   14.33 +
   14.34 +      int maxId() const {return graph->maxNodeId(); }
   14.35 +
   14.36 +    };
   14.37 +
   14.38 +    class EdgeIdMap {
   14.39 +    private:
   14.40 +      const Graph* graph;
   14.41 +
   14.42 +    public:
   14.43 +      EdgeIdMap(const Graph& g) : graph(&g) {}
   14.44 +
   14.45 +      int operator[](const Edge& edge) const { return graph->id(edge); }
   14.46 +
   14.47 +      int maxId() const {return graph->maxEdgeId(); }
   14.48 +
   14.49 +    };
   14.50 +
   14.51 +  };
   14.52 +
   14.53 +}
   14.54 +
   14.55 +#endif
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/lemon/iterable_graph_extender.h	Wed Oct 27 22:38:50 2004 +0000
    15.3 @@ -0,0 +1,131 @@
    15.4 +// -*- c++ -*-
    15.5 +#ifndef LEMON_ITERABLE_GRAPH_EXTENDER_H
    15.6 +#define LEMON_ITERABLE_GRAPH_EXTENDER_H
    15.7 +
    15.8 +#include <lemon/invalid.h>
    15.9 +
   15.10 +namespace lemon {
   15.11 +  
   15.12 +  template <typename _Base>
   15.13 +  class IterableGraphExtender : public _Base {
   15.14 +
   15.15 +    typedef _Base Parent;
   15.16 +    typedef IterableGraphExtender<_Base> Graph;
   15.17 +
   15.18 +  public:
   15.19 +
   15.20 +    typedef typename Parent::Node Node;
   15.21 +    typedef typename Parent::Edge Edge;
   15.22 +
   15.23 +
   15.24 +    class NodeIt : public Node { 
   15.25 +      const Graph* graph;
   15.26 +    public:
   15.27 +
   15.28 +      NodeIt() {}
   15.29 +
   15.30 +      NodeIt(Invalid i) : Node(i) { }
   15.31 +
   15.32 +      explicit NodeIt(const Graph& _graph) : Node(), graph(&_graph) {
   15.33 +	_graph.first(*static_cast<Node*>(this));
   15.34 +      }
   15.35 +
   15.36 +      NodeIt(const Graph& _graph, const Node& node) 
   15.37 +	: Node(node), graph(&_graph) {}
   15.38 +
   15.39 +      NodeIt& operator++() { 
   15.40 +	graph->next(*this);
   15.41 +	return *this; 
   15.42 +      }
   15.43 +
   15.44 +    };
   15.45 +
   15.46 +
   15.47 +    class EdgeIt : public Edge { 
   15.48 +      const Graph* graph;
   15.49 +    public:
   15.50 +
   15.51 +      EdgeIt() { }
   15.52 +
   15.53 +      EdgeIt(Invalid i) : Edge(i) { }
   15.54 +
   15.55 +      explicit EdgeIt(const Graph& _graph) : Edge(), graph(&_graph) {
   15.56 +	_graph.first(*static_cast<Edge*>(this));
   15.57 +      }
   15.58 +
   15.59 +      EdgeIt(const Graph& _graph, const Edge& e) : 
   15.60 +	Edge(e), graph(&_graph) { }
   15.61 +
   15.62 +      EdgeIt& operator++() { 
   15.63 +	graph->next(*this);
   15.64 +	return *this; 
   15.65 +      }
   15.66 +
   15.67 +    };
   15.68 +
   15.69 +
   15.70 +    class OutEdgeIt : public Edge { 
   15.71 +      const Graph* graph;
   15.72 +    public:
   15.73 +
   15.74 +      OutEdgeIt() { }
   15.75 +
   15.76 +      OutEdgeIt(Invalid i) : Edge(i) { }
   15.77 +
   15.78 +      OutEdgeIt(const Graph& _graph, const Node& node) 
   15.79 +	: Edge(), graph(&_graph) {
   15.80 +	_graph.firstOut(*this, node);
   15.81 +      }
   15.82 +
   15.83 +      OutEdgeIt(const Graph& _graph, const Edge& edge) 
   15.84 +	: Edge(edge), graph(&_graph) {}
   15.85 +
   15.86 +      OutEdgeIt& operator++() { 
   15.87 +	graph->nextOut(*this);
   15.88 +	return *this; 
   15.89 +      }
   15.90 +
   15.91 +    };
   15.92 +
   15.93 +
   15.94 +    class InEdgeIt : public Edge { 
   15.95 +      const Graph* graph;
   15.96 +    public:
   15.97 +
   15.98 +      InEdgeIt() { }
   15.99 +
  15.100 +      InEdgeIt(Invalid i) : Edge(i) { }
  15.101 +
  15.102 +      InEdgeIt(const Graph& _graph, const Node& node) 
  15.103 +	: Edge(), graph(&_graph) {
  15.104 +	_graph.firstIn(*this, node);
  15.105 +      }
  15.106 +
  15.107 +      InEdgeIt(const Graph& _graph, const Edge& edge) : 
  15.108 +	Edge(edge), graph(&_graph) {}
  15.109 +
  15.110 +      InEdgeIt& operator++() { 
  15.111 +	graph->nextIn(*this);
  15.112 +	return *this; 
  15.113 +      }
  15.114 +
  15.115 +    };
  15.116 +
  15.117 +    using Parent::first;
  15.118 +
  15.119 +  private:
  15.120 +
  15.121 +    /// \todo When (and if) we change the iterators concept to use operator*,
  15.122 +    /// then the following shadowed methods will become superfluous.
  15.123 +    /// But for now these are important safety measures.
  15.124 +
  15.125 +    void first(NodeIt &) const;
  15.126 +    void first(EdgeIt &) const;
  15.127 +    void first(OutEdgeIt &) const;
  15.128 +    void first(InEdgeIt &) const;
  15.129 +
  15.130 +  };
  15.131 +  
  15.132 +}
  15.133 +
  15.134 +#endif // LEMON_GRAPH_EXTENDER_H
    16.1 --- a/src/lemon/list_graph.h	Mon Oct 25 13:29:46 2004 +0000
    16.2 +++ b/src/lemon/list_graph.h	Wed Oct 27 22:38:50 2004 +0000
    16.3 @@ -1,117 +1,87 @@
    16.4 -/* -*- C++ -*-
    16.5 - * src/lemon/list_graph.h - Part of LEMON, a generic C++ optimization library
    16.6 - *
    16.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    16.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    16.9 - *
   16.10 - * Permission to use, modify and distribute this software is granted
   16.11 - * provided that this copyright notice appears in all copies. For
   16.12 - * precise terms see the accompanying LICENSE file.
   16.13 - *
   16.14 - * This software is provided "AS IS" with no warranty of any kind,
   16.15 - * express or implied, and with no claim as to its suitability for any
   16.16 - * purpose.
   16.17 - *
   16.18 - */
   16.19 +// -*- c++ -*-
   16.20  
   16.21  #ifndef LEMON_LIST_GRAPH_H
   16.22  #define LEMON_LIST_GRAPH_H
   16.23  
   16.24 -///\ingroup graphs
   16.25 -///\file
   16.26 -///\brief ListGraph, SymListGraph, NodeSet and EdgeSet classes.
   16.27 +#include <lemon/erasable_graph_extender.h>
   16.28 +#include <lemon/clearable_graph_extender.h>
   16.29 +#include <lemon/extendable_graph_extender.h>
   16.30  
   16.31 -#include <vector>
   16.32 -#include <climits>
   16.33 +#include <lemon/idmappable_graph_extender.h>
   16.34  
   16.35 -#include <lemon/invalid.h>
   16.36 +#include <lemon/iterable_graph_extender.h>
   16.37  
   16.38 -#include <lemon/map_registry.h>
   16.39 -#include <lemon/array_map.h>
   16.40 +#include <lemon/alteration_observer_registry.h>
   16.41  
   16.42 -#include <lemon/map_defines.h>
   16.43 +#include <lemon/default_map.h>
   16.44  
   16.45  
   16.46  namespace lemon {
   16.47  
   16.48 -/// \addtogroup graphs
   16.49 -/// @{
   16.50 +  class ListGraphBase {
   16.51  
   16.52 -  ///A list graph class.
   16.53 -
   16.54 -  ///This is a simple and fast erasable graph implementation.
   16.55 -  ///
   16.56 -  ///It conforms to the
   16.57 -  ///\ref skeleton::ErasableGraph "ErasableGraph" concept.
   16.58 -  ///\sa skeleton::ErasableGraph.
   16.59 -  class ListGraph {
   16.60 -
   16.61 -    //Nodes are double linked.
   16.62 -    //The free nodes are only single linked using the "next" field.
   16.63 -    struct NodeT 
   16.64 -    {
   16.65 +    struct NodeT {
   16.66        int first_in,first_out;
   16.67        int prev, next;
   16.68      };
   16.69 -    //Edges are double linked.
   16.70 -    //The free edges are only single linked using the "next_in" field.
   16.71 -    struct EdgeT 
   16.72 -    {
   16.73 + 
   16.74 +    struct EdgeT {
   16.75        int head, tail;
   16.76        int prev_in, prev_out;
   16.77        int next_in, next_out;
   16.78      };
   16.79  
   16.80      std::vector<NodeT> nodes;
   16.81 -    //The first node
   16.82 +
   16.83      int first_node;
   16.84 -    //The first free node
   16.85 +
   16.86      int first_free_node;
   16.87 +
   16.88      std::vector<EdgeT> edges;
   16.89 -    //The first free edge
   16.90 +
   16.91      int first_free_edge;
   16.92      
   16.93    public:
   16.94      
   16.95 -    typedef ListGraph Graph;
   16.96 +    typedef ListGraphBase Graph;
   16.97      
   16.98 -    class Node;
   16.99 -    class Edge;
  16.100 +    class Node {
  16.101 +      friend class Graph;
  16.102 +    protected:
  16.103  
  16.104 -    
  16.105 -  public:
  16.106 +      int id;
  16.107 +      Node(int pid) { id = pid;}
  16.108  
  16.109 -    class NodeIt;
  16.110 -    class EdgeIt;
  16.111 -    class OutEdgeIt;
  16.112 -    class InEdgeIt;
  16.113 +    public:
  16.114 +      Node() {}
  16.115 +      Node (Invalid) { id = -1; }
  16.116 +      bool operator==(const Node& node) const {return id == node.id;}
  16.117 +      bool operator!=(const Node& node) const {return id != node.id;}
  16.118 +      bool operator<(const Node& node) const {return id < node.id;}
  16.119 +    };
  16.120  
  16.121 -    // Create map registries.
  16.122 -    CREATE_MAP_REGISTRIES;
  16.123 -    // Create node and edge maps.
  16.124 -    CREATE_MAPS(ArrayMap);
  16.125 +    class Edge {
  16.126 +      friend class Graph;
  16.127 +    protected:
  16.128  
  16.129 -  public:
  16.130 +      int id;
  16.131 +      Edge(int pid) { id = pid;}
  16.132  
  16.133 -    ListGraph() 
  16.134 +    public:
  16.135 +      Edge() {}
  16.136 +      Edge (Invalid) { id = -1; }
  16.137 +      bool operator==(const Edge& edge) const {return id == edge.id;}
  16.138 +      bool operator!=(const Edge& edge) const {return id != edge.id;}
  16.139 +      bool operator<(const Edge& edge) const {return id < edge.id;}
  16.140 +    };
  16.141 +
  16.142 +
  16.143 +
  16.144 +    ListGraphBase()
  16.145        : nodes(), first_node(-1),
  16.146  	first_free_node(-1), edges(), first_free_edge(-1) {}
  16.147  
  16.148 -    ListGraph(const ListGraph &_g) 
  16.149 -      : nodes(_g.nodes), first_node(_g.first_node),
  16.150 -	first_free_node(_g.first_free_node), edges(_g.edges),
  16.151 -	first_free_edge(_g.first_free_edge) {}
  16.152      
  16.153 -    /// \bug In the vector can be hole if a node is erased from the graph.
  16.154 -    ///Number of nodes.
  16.155 -    int nodeNum() const { return nodes.size(); }
  16.156 -    ///Number of edges.
  16.157 -    int edgeNum() const { return edges.size(); }
  16.158 -
  16.159 -    ///Set the expected maximum number of edges.
  16.160 -
  16.161 -    ///With this function, it is possible to set the expected number of edges.
  16.162 -    ///The use of this fasten the building of the graph and makes
  16.163      ///it possible to avoid the superfluous memory allocation.
  16.164      void reserveEdge(int n) { edges.reserve(n); };
  16.165      
  16.166 @@ -120,56 +90,75 @@
  16.167      /// Maximum node ID.
  16.168      ///\sa id(Node)
  16.169      int maxNodeId() const { return nodes.size()-1; } 
  16.170 +
  16.171      /// Maximum edge ID.
  16.172      
  16.173      /// Maximum edge ID.
  16.174      ///\sa id(Edge)
  16.175      int maxEdgeId() const { return edges.size()-1; }
  16.176  
  16.177 -    Node tail(Edge e) const { return edges[e.n].tail; }
  16.178 -    Node head(Edge e) const { return edges[e.n].head; }
  16.179 +    Node tail(Edge e) const { return edges[e.id].tail; }
  16.180 +    Node head(Edge e) const { return edges[e.id].head; }
  16.181  
  16.182 -    NodeIt& first(NodeIt& v) const { 
  16.183 -      v=NodeIt(*this); return v; }
  16.184 -    EdgeIt& first(EdgeIt& e) const { 
  16.185 -      e=EdgeIt(*this); return e; }
  16.186 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  16.187 -      e=OutEdgeIt(*this,v); return e; }
  16.188 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  16.189 -      e=InEdgeIt(*this,v); return e; }
  16.190  
  16.191 -    /// Node ID.
  16.192 +    void first(Node& node) const { 
  16.193 +      node.id = first_node;
  16.194 +    }
  16.195 +
  16.196 +    void next(Node& node) const {
  16.197 +      node.id = nodes[node.id].next;
  16.198 +    }
  16.199 +
  16.200 +
  16.201 +    void first(Edge& e) const { 
  16.202 +      int n;
  16.203 +      for(n = first_node; 
  16.204 +	  n!=-1 && nodes[n].first_in == -1; 
  16.205 +	  n = nodes[n].next);
  16.206 +      e.id = (n == -1) ? -1 : nodes[n].first_in;
  16.207 +    }
  16.208 +
  16.209 +    void next(Edge& edge) const {
  16.210 +      if (edges[edge.id].next_in != -1) {
  16.211 +	edge.id = edges[edge.id].next_in;
  16.212 +      } else {
  16.213 +	int n;
  16.214 +	for(n = nodes[edges[edge.id].head].next;
  16.215 +	  n!=-1 && nodes[n].first_in == -1; 
  16.216 +	  n = nodes[n].next);
  16.217 +	edge.id = (n == -1) ? -1 : nodes[n].first_in;
  16.218 +      }      
  16.219 +    }
  16.220 +
  16.221 +    void firstOut(Edge &e, const Node& v) const {
  16.222 +      e.id = nodes[v.id].first_out;
  16.223 +    }
  16.224 +    void nextOut(Edge &e) const {
  16.225 +      e.id=edges[e.id].next_out;
  16.226 +    }
  16.227 +
  16.228 +    void firstIn(Edge &e, const Node& v) const {
  16.229 +      e.id = nodes[v.id].first_in;
  16.230 +    }
  16.231 +    void nextIn(Edge &e) const {
  16.232 +      e.id=edges[e.id].next_in;
  16.233 +    }
  16.234 +
  16.235      
  16.236 -    /// The ID of a valid Node is a nonnegative integer not greater than
  16.237 -    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  16.238 -    /// and the greatest node ID can be actually less then \ref maxNodeId().
  16.239 -    ///
  16.240 -    /// The ID of the \ref INVALID node is -1.
  16.241 -    ///\return The ID of the node \c v. 
  16.242 -    static int id(Node v) { return v.n; }
  16.243 -    /// Edge ID.
  16.244 -    
  16.245 -    /// The ID of a valid Edge is a nonnegative integer not greater than
  16.246 -    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  16.247 -    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  16.248 -    ///
  16.249 -    /// The ID of the \ref INVALID edge is -1.
  16.250 -    ///\return The ID of the edge \c e. 
  16.251 -    static int id(Edge e) { return e.n; }
  16.252 +    static int id(Node v) { return v.id; }
  16.253 +    static int id(Edge e) { return e.id; }
  16.254  
  16.255      /// Adds a new node to the graph.
  16.256  
  16.257      /// \warning It adds the new node to the front of the list.
  16.258      /// (i.e. the lastly added node becomes the first.)
  16.259 -    Node addNode() {
  16.260 +    Node addNode() {     
  16.261        int n;
  16.262        
  16.263 -      if(first_free_node==-1)
  16.264 -	{
  16.265 -	  n = nodes.size();
  16.266 -	  nodes.push_back(NodeT());
  16.267 -	}
  16.268 -      else {
  16.269 +      if(first_free_node==-1) {
  16.270 +	n = nodes.size();
  16.271 +	nodes.push_back(NodeT());
  16.272 +      } else {
  16.273  	n = first_free_node;
  16.274  	first_free_node = nodes[n].next;
  16.275        }
  16.276 @@ -181,1319 +170,108 @@
  16.277        
  16.278        nodes[n].first_in = nodes[n].first_out = -1;
  16.279        
  16.280 -      Node nn; nn.n=n;
  16.281 -
  16.282 -      //Update dynamic maps
  16.283 -      node_maps.add(nn);
  16.284 -
  16.285 -      return nn;
  16.286 +      return Node(n);
  16.287      }
  16.288      
  16.289      Edge addEdge(Node u, Node v) {
  16.290 -      int n;
  16.291 -      
  16.292 -      if(first_free_edge==-1)
  16.293 -	{
  16.294 -	  n = edges.size();
  16.295 -	  edges.push_back(EdgeT());
  16.296 -	}
  16.297 -      else {
  16.298 +      int n;      
  16.299 +
  16.300 +      if (first_free_edge == -1) {
  16.301 +	n = edges.size();
  16.302 +	edges.push_back(EdgeT());
  16.303 +      } else {
  16.304  	n = first_free_edge;
  16.305  	first_free_edge = edges[n].next_in;
  16.306        }
  16.307        
  16.308 -      edges[n].tail = u.n; edges[n].head = v.n;
  16.309 +      edges[n].tail = u.id; 
  16.310 +      edges[n].head = v.id;
  16.311  
  16.312 -      edges[n].next_out = nodes[u.n].first_out;
  16.313 -      if(nodes[u.n].first_out != -1) edges[nodes[u.n].first_out].prev_out = n;
  16.314 -      edges[n].next_in = nodes[v.n].first_in;
  16.315 -      if(nodes[v.n].first_in != -1) edges[nodes[v.n].first_in].prev_in = n;
  16.316 +      edges[n].next_out = nodes[u.id].first_out;
  16.317 +      if(nodes[u.id].first_out != -1) {
  16.318 +	edges[nodes[u.id].first_out].prev_out = n;
  16.319 +      }
  16.320 +      
  16.321 +      edges[n].next_in = nodes[v.id].first_in;
  16.322 +      if(nodes[v.id].first_in != -1) {
  16.323 +	edges[nodes[v.id].first_in].prev_in = n;
  16.324 +      }
  16.325 +      
  16.326        edges[n].prev_in = edges[n].prev_out = -1;
  16.327  	
  16.328 -      nodes[u.n].first_out = nodes[v.n].first_in = n;
  16.329 +      nodes[u.id].first_out = nodes[v.id].first_in = n;
  16.330  
  16.331 -      Edge e; e.n=n;
  16.332 -
  16.333 -      //Update dynamic maps
  16.334 -      edge_maps.add(e);
  16.335 -
  16.336 -      return e;
  16.337 +      return Edge(n);
  16.338      }
  16.339      
  16.340 -    /// Finds an edge between two nodes.
  16.341 +    void erase(const Node& node) {
  16.342 +      int n = node.id;
  16.343 +      
  16.344 +      if(nodes[n].next != -1) {
  16.345 +	nodes[nodes[n].next].prev = nodes[n].prev;
  16.346 +      }
  16.347 +      
  16.348 +      if(nodes[n].prev != -1) {
  16.349 +	nodes[nodes[n].prev].next = nodes[n].next;
  16.350 +      } else {
  16.351 +	first_node = nodes[n].next;
  16.352 +      }
  16.353 +      
  16.354 +      nodes[n].next = first_free_node;
  16.355 +      first_free_node = n;
  16.356  
  16.357 -    /// Finds an edge from node \c u to node \c v.
  16.358 -    ///
  16.359 -    /// If \c prev is \ref INVALID (this is the default value), then
  16.360 -    /// It finds the first edge from \c u to \c v. Otherwise it looks for
  16.361 -    /// the next edge from \c u to \c v after \c prev.
  16.362 -    /// \return The found edge or INVALID if there is no such an edge.
  16.363 -    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  16.364 -    {
  16.365 -      int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out;
  16.366 -      while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out;
  16.367 -      prev.n=e;
  16.368 -      return prev;
  16.369      }
  16.370      
  16.371 -  private:
  16.372 -    void eraseEdge(int n) {
  16.373 +    void erase(const Edge& edge) {
  16.374 +      int n = edge.id;
  16.375        
  16.376 -      if(edges[n].next_in!=-1)
  16.377 +      if(edges[n].next_in!=-1) {
  16.378  	edges[edges[n].next_in].prev_in = edges[n].prev_in;
  16.379 -      if(edges[n].prev_in!=-1)
  16.380 +      }
  16.381 +
  16.382 +      if(edges[n].prev_in!=-1) {
  16.383  	edges[edges[n].prev_in].next_in = edges[n].next_in;
  16.384 -      else nodes[edges[n].head].first_in = edges[n].next_in;
  16.385 +      } else {
  16.386 +	nodes[edges[n].head].first_in = edges[n].next_in;
  16.387 +      }
  16.388 +
  16.389        
  16.390 -      if(edges[n].next_out!=-1)
  16.391 +      if(edges[n].next_out!=-1) {
  16.392  	edges[edges[n].next_out].prev_out = edges[n].prev_out;
  16.393 -      if(edges[n].prev_out!=-1)
  16.394 +      } 
  16.395 +
  16.396 +      if(edges[n].prev_out!=-1) {
  16.397  	edges[edges[n].prev_out].next_out = edges[n].next_out;
  16.398 -      else nodes[edges[n].tail].first_out = edges[n].next_out;
  16.399 +      } else {
  16.400 +	nodes[edges[n].tail].first_out = edges[n].next_out;
  16.401 +      }
  16.402        
  16.403        edges[n].next_in = first_free_edge;
  16.404        first_free_edge = n;      
  16.405  
  16.406 -      //Update dynamic maps
  16.407 -      Edge e; e.n=n;
  16.408 -      edge_maps.erase(e);
  16.409 -
  16.410      }
  16.411 -      
  16.412 -  public:
  16.413 -
  16.414 -    void erase(Node nn) {
  16.415 -      int n=nn.n;
  16.416 -      
  16.417 -      int m;
  16.418 -      while((m=nodes[n].first_in)!=-1) eraseEdge(m);
  16.419 -      while((m=nodes[n].first_out)!=-1) eraseEdge(m);
  16.420 -
  16.421 -      if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
  16.422 -      if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
  16.423 -      else first_node = nodes[n].next;
  16.424 -      
  16.425 -      nodes[n].next = first_free_node;
  16.426 -      first_free_node = n;
  16.427 -
  16.428 -      //Update dynamic maps
  16.429 -      node_maps.erase(nn);
  16.430 -
  16.431 -    }
  16.432 -    
  16.433 -    void erase(Edge e) { eraseEdge(e.n); }
  16.434  
  16.435      void clear() {
  16.436 -      edge_maps.clear();
  16.437        edges.clear();
  16.438 -      node_maps.clear();
  16.439        nodes.clear();
  16.440 -      first_node=first_free_node=first_free_edge=-1;
  16.441 -    }
  16.442 -
  16.443 -    class Node {
  16.444 -      friend class ListGraph;
  16.445 -      template <typename T> friend class NodeMap;
  16.446 -       
  16.447 -      friend class Edge;
  16.448 -      friend class OutEdgeIt;
  16.449 -      friend class InEdgeIt;
  16.450 -      friend class SymEdge;
  16.451 -
  16.452 -    protected:
  16.453 -      int n;
  16.454 -      friend int ListGraph::id(Node v); 
  16.455 -      Node(int nn) {n=nn;}
  16.456 -    public:
  16.457 -      Node() {}
  16.458 -      Node (Invalid) { n=-1; }
  16.459 -      bool operator==(const Node i) const {return n==i.n;}
  16.460 -      bool operator!=(const Node i) const {return n!=i.n;}
  16.461 -      bool operator<(const Node i) const {return n<i.n;}
  16.462 -      //      ///Validity check
  16.463 -      //      operator bool() { return n!=-1; }
  16.464 -    };
  16.465 -    
  16.466 -    class NodeIt : public Node {
  16.467 -      const ListGraph *G;
  16.468 -      friend class ListGraph;
  16.469 -    public:
  16.470 -      NodeIt() : Node() { }
  16.471 -      NodeIt(Invalid i) : Node(i) { }
  16.472 -      NodeIt(const ListGraph& _G) : Node(_G.first_node), G(&_G) { }
  16.473 -      NodeIt(const ListGraph& _G,Node n) : Node(n), G(&_G) { }
  16.474 -      NodeIt &operator++() {
  16.475 -	n=G->nodes[n].next; 
  16.476 -	return *this; 
  16.477 -      }
  16.478 -      //      ///Validity check
  16.479 -      //      operator bool() { return Node::operator bool(); }      
  16.480 -    };
  16.481 -
  16.482 -    class Edge {
  16.483 -      friend class ListGraph;
  16.484 -      template <typename T> friend class EdgeMap;
  16.485 -
  16.486 -      friend class SymListGraph;
  16.487 -      
  16.488 -      friend class Node;
  16.489 -      friend class NodeIt;
  16.490 -    protected:
  16.491 -      int n;
  16.492 -      friend int ListGraph::id(Edge e);
  16.493 -
  16.494 -    public:
  16.495 -      /// An Edge with id \c n.
  16.496 -
  16.497 -      /// \bug It should be
  16.498 -      /// obtained by a member function of the Graph.
  16.499 -      Edge(int nn) {n=nn;}
  16.500 -
  16.501 -      Edge() { }
  16.502 -      Edge (Invalid) { n=-1; }
  16.503 -      bool operator==(const Edge i) const {return n==i.n;}
  16.504 -      bool operator!=(const Edge i) const {return n!=i.n;}
  16.505 -      bool operator<(const Edge i) const {return n<i.n;}
  16.506 -      //      ///Validity check
  16.507 -      //      operator bool() { return n!=-1; }
  16.508 -   };
  16.509 -    
  16.510 -    class EdgeIt : public Edge {
  16.511 -      const ListGraph *G;
  16.512 -      friend class ListGraph;
  16.513 -    public:
  16.514 -      EdgeIt(const ListGraph& _G) : Edge(), G(&_G) {
  16.515 -      	int m;
  16.516 -	for(m=_G.first_node;
  16.517 -	    m!=-1 && _G.nodes[m].first_in == -1; m = _G.nodes[m].next);
  16.518 -	n = (m==-1)?-1:_G.nodes[m].first_in;
  16.519 -      }
  16.520 -      EdgeIt (Invalid i) : Edge(i) { }
  16.521 -      EdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
  16.522 -      EdgeIt() : Edge() { }
  16.523 -      EdgeIt &operator++() {
  16.524 -	if(G->edges[n].next_in!=-1) n=G->edges[n].next_in;
  16.525 -	else {
  16.526 -	  int nn;
  16.527 -	  for(nn=G->nodes[G->edges[n].head].next;
  16.528 -	      nn!=-1 && G->nodes[nn].first_in == -1;
  16.529 -	      nn = G->nodes[nn].next) ;
  16.530 -	  n = (nn==-1)?-1:G->nodes[nn].first_in;
  16.531 -	}
  16.532 -	return *this;
  16.533 -      }
  16.534 -      //      ///Validity check
  16.535 -      //      operator bool() { return Edge::operator bool(); }      
  16.536 -    };
  16.537 -    
  16.538 -    class OutEdgeIt : public Edge {
  16.539 -      const ListGraph *G;
  16.540 -      friend class ListGraph;
  16.541 -    public: 
  16.542 -      OutEdgeIt() : Edge() { }
  16.543 -      OutEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
  16.544 -      OutEdgeIt (Invalid i) : Edge(i) { }
  16.545 -
  16.546 -      OutEdgeIt(const ListGraph& _G,const Node v)
  16.547 -	: Edge(_G.nodes[v.n].first_out), G(&_G) {}
  16.548 -      OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
  16.549 -      //      ///Validity check
  16.550 -      //      operator bool() { return Edge::operator bool(); }      
  16.551 -    };
  16.552 -    
  16.553 -    class InEdgeIt : public Edge {
  16.554 -      const ListGraph *G;
  16.555 -      friend class ListGraph;
  16.556 -    public: 
  16.557 -      InEdgeIt() : Edge() { }
  16.558 -      InEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
  16.559 -      InEdgeIt (Invalid i) : Edge(i) { }
  16.560 -      InEdgeIt(const ListGraph& _G,Node v)
  16.561 -	: Edge(_G.nodes[v.n].first_in), G(&_G) { }
  16.562 -      InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
  16.563 -      //      ///Validity check
  16.564 -      //      operator bool() { return Edge::operator bool(); }      
  16.565 -    };
  16.566 -  };
  16.567 -
  16.568 -  ///Graph for bidirectional edges.
  16.569 -
  16.570 -  ///The purpose of this graph structure is to handle graphs
  16.571 -  ///having bidirectional edges. Here the function \c addEdge(u,v) adds a pair
  16.572 -  ///of oppositely directed edges.
  16.573 -  ///There is a new edge map type called
  16.574 -  ///\ref lemon::SymListGraph::SymEdgeMap "SymEdgeMap"
  16.575 -  ///that complements this
  16.576 -  ///feature by
  16.577 -  ///storing shared values for the edge pairs. The usual
  16.578 -  ///\ref lemon::skeleton::StaticGraph::EdgeMap "EdgeMap"
  16.579 -  ///can be used
  16.580 -  ///as well.
  16.581 -  ///
  16.582 -  ///The oppositely directed edge can also be obtained easily
  16.583 -  ///using \ref lemon::SymListGraph::opposite() "opposite()" member function.
  16.584 -  ///
  16.585 -  ///Here erase(Edge) deletes a pair of edges.
  16.586 -  ///
  16.587 -  ///\todo this date structure need some reconsiderations. Maybe it
  16.588 -  ///should be implemented independently from ListGraph.
  16.589 -  /*  
  16.590 -  class SymListGraph : public ListGraph
  16.591 -  {
  16.592 -  public:
  16.593 -
  16.594 -    typedef SymListGraph Graph;
  16.595 -
  16.596 -    // Create symmetric map registry.
  16.597 -    CREATE_SYM_EDGE_MAP_REGISTRY;
  16.598 -    // Create symmetric edge map.
  16.599 -    CREATE_SYM_EDGE_MAP(ArrayMap);
  16.600 -
  16.601 -    SymListGraph() : ListGraph() { }
  16.602 -    SymListGraph(const ListGraph &_g) : ListGraph(_g) { }
  16.603 -    ///Adds a pair of oppositely directed edges to the graph.
  16.604 -    Edge addEdge(Node u, Node v)
  16.605 -    {
  16.606 -      Edge e = ListGraph::addEdge(u,v);
  16.607 -      Edge f = ListGraph::addEdge(v,u);
  16.608 -      sym_edge_maps.add(e);
  16.609 -      sym_edge_maps.add(f);
  16.610 -      
  16.611 -      return e;
  16.612 -    }
  16.613 -
  16.614 -    void erase(Node n) { ListGraph::erase(n);}
  16.615 -    ///The oppositely directed edge.
  16.616 -
  16.617 -    ///Returns the oppositely directed
  16.618 -    ///pair of the edge \c e.
  16.619 -    static Edge opposite(Edge e)
  16.620 -    {
  16.621 -      Edge f;
  16.622 -      f.n = e.n - 2*(e.n%2) + 1;
  16.623 -      return f;
  16.624 -    }
  16.625 -    
  16.626 -    ///Removes a pair of oppositely directed edges to the graph.
  16.627 -    void erase(Edge e) {
  16.628 -      Edge f = opposite(e);
  16.629 -      sym_edge_maps.erase(e);
  16.630 -      sym_edge_maps.erase(f);
  16.631 -      ListGraph::erase(f);
  16.632 -      ListGraph::erase(e);
  16.633 -    }    
  16.634 -    };*/
  16.635 -
  16.636 -  class SymListGraph : public ListGraph {
  16.637 -    typedef ListGraph Parent;
  16.638 -  public:
  16.639 -
  16.640 -    typedef SymListGraph Graph;
  16.641 -
  16.642 -    typedef ListGraph::Node Node;
  16.643 -    typedef ListGraph::NodeIt NodeIt;
  16.644 -
  16.645 -    class SymEdge;
  16.646 -    class SymEdgeIt;
  16.647 -
  16.648 -    class Edge;
  16.649 -    class EdgeIt;
  16.650 -    class OutEdgeIt;
  16.651 -    class InEdgeIt;
  16.652 -
  16.653 -    template <typename Value>
  16.654 -    class NodeMap : public Parent::NodeMap<Value> {      
  16.655 -    public:
  16.656 -      NodeMap(const SymListGraph& g) 
  16.657 -	: SymListGraph::Parent::NodeMap<Value>(g) {}
  16.658 -      NodeMap(const SymListGraph& g, Value v) 
  16.659 -	: SymListGraph::Parent::NodeMap<Value>(g, v) {}
  16.660 -      template<typename TT> 
  16.661 -      NodeMap(const NodeMap<TT>& copy) 
  16.662 -	: SymListGraph::Parent::NodeMap<Value>(copy) { }            
  16.663 -    };
  16.664 -
  16.665 -    template <typename Value>
  16.666 -    class SymEdgeMap : public Parent::EdgeMap<Value> {
  16.667 -    public:
  16.668 -      typedef SymEdge KeyType;
  16.669 -
  16.670 -      SymEdgeMap(const SymListGraph& g) 
  16.671 -	: SymListGraph::Parent::EdgeMap<Value>(g) {}
  16.672 -      SymEdgeMap(const SymListGraph& g, Value v) 
  16.673 -	: SymListGraph::Parent::EdgeMap<Value>(g, v) {}
  16.674 -      template<typename TT> 
  16.675 -      SymEdgeMap(const SymEdgeMap<TT>& copy) 
  16.676 -	: SymListGraph::Parent::EdgeMap<Value>(copy) { }
  16.677 -      
  16.678 -    };
  16.679 -
  16.680 -    // Create edge map registry.
  16.681 -    CREATE_EDGE_MAP_REGISTRY;
  16.682 -    // Create edge maps.
  16.683 -    CREATE_EDGE_MAP(ArrayMap);
  16.684 -
  16.685 -    class Edge {
  16.686 -      friend class SymListGraph;
  16.687 -      friend class SymListGraph::EdgeIt;
  16.688 -      friend class SymListGraph::OutEdgeIt;
  16.689 -      friend class SymListGraph::InEdgeIt;
  16.690 -      
  16.691 -    protected:
  16.692 -      int id;
  16.693 -
  16.694 -      Edge(int pid) { id = pid; }
  16.695 -
  16.696 -    public:
  16.697 -      /// An Edge with id \c n.
  16.698 -
  16.699 -      Edge() { }
  16.700 -      Edge (Invalid) { id = -1; }
  16.701 -
  16.702 -      operator SymEdge(){ return SymEdge(id >> 1);}
  16.703 -      
  16.704 -      bool operator==(const Edge i) const {return id == i.id;}
  16.705 -      bool operator!=(const Edge i) const {return id != i.id;}
  16.706 -      bool operator<(const Edge i) const {return id < i.id;}
  16.707 -      //      ///Validity check
  16.708 -      //      operator bool() { return n!=-1; }
  16.709 -    };
  16.710 -
  16.711 -    class SymEdge : public ListGraph::Edge {
  16.712 -      friend class SymListGraph;
  16.713 -      friend class SymListGraph::Edge;
  16.714 -      typedef ListGraph::Edge Parent;
  16.715 -
  16.716 -    protected:      
  16.717 -      SymEdge(int pid) : Parent(pid) {}
  16.718 -    public:
  16.719 -
  16.720 -      SymEdge() { }
  16.721 -      SymEdge(const ListGraph::Edge& i) : Parent(i) {} 
  16.722 -      SymEdge (Invalid) : Parent(INVALID) {}
  16.723 -
  16.724 -    };
  16.725 -
  16.726 -    class OutEdgeIt {
  16.727 -      Parent::OutEdgeIt out;
  16.728 -      Parent::InEdgeIt in;      
  16.729 -    public: 
  16.730 -      OutEdgeIt() {}
  16.731 -      OutEdgeIt(const SymListGraph& g, Edge e) { 
  16.732 -	if ((e.id & 1) == 0) {	
  16.733 -	  out = Parent::OutEdgeIt(g, SymEdge(e));
  16.734 -	  in = Parent::InEdgeIt(g, g.tail(e));
  16.735 -	} else {
  16.736 -	  out = Parent::OutEdgeIt(INVALID);
  16.737 -	  in = Parent::InEdgeIt(g, SymEdge(e));
  16.738 -	}
  16.739 -      }
  16.740 -      OutEdgeIt (Invalid i) : out(INVALID), in(INVALID) { }
  16.741 -
  16.742 -      OutEdgeIt(const SymListGraph& g, const Node v)
  16.743 -	: out(g, v), in(g, v) {}
  16.744 -      OutEdgeIt &operator++() { 
  16.745 -	if (out != INVALID) {
  16.746 -	  ++out;
  16.747 -	} else {
  16.748 -	  ++in;
  16.749 -	}
  16.750 -	return *this; 
  16.751 -      }
  16.752 -
  16.753 -      operator Edge() const {
  16.754 -	if (out == INVALID && in == INVALID) return INVALID;
  16.755 -	return out != INVALID ? forward(out) : backward(in);
  16.756 -      }
  16.757 -
  16.758 -      bool operator==(const Edge i) const {return Edge(*this) == i;}
  16.759 -      bool operator!=(const Edge i) const {return Edge(*this) != i;}
  16.760 -      bool operator<(const Edge i) const {return Edge(*this) < i;}
  16.761 -    };
  16.762 -
  16.763 -    class InEdgeIt {
  16.764 -      Parent::OutEdgeIt out;
  16.765 -      Parent::InEdgeIt in;      
  16.766 -    public: 
  16.767 -      InEdgeIt() {}
  16.768 -      InEdgeIt(const SymListGraph& g, Edge e) { 
  16.769 -	if ((e.id & 1) == 0) {	
  16.770 -	  out = Parent::OutEdgeIt(g, SymEdge(e));
  16.771 -	  in = Parent::InEdgeIt(g, g.tail(e));
  16.772 -	} else {
  16.773 -	  out = Parent::OutEdgeIt(INVALID);
  16.774 -	  in = Parent::InEdgeIt(g, SymEdge(e));
  16.775 -	}
  16.776 -      }
  16.777 -      InEdgeIt (Invalid i) : out(INVALID), in(INVALID) { }
  16.778 -
  16.779 -      InEdgeIt(const SymListGraph& g, const Node v)
  16.780 -	: out(g, v), in(g, v) {}
  16.781 -
  16.782 -      InEdgeIt &operator++() { 
  16.783 -	if (out != INVALID) {
  16.784 -	  ++out;
  16.785 -	} else {
  16.786 -	  ++in;
  16.787 -	}
  16.788 -	return *this; 
  16.789 -      }
  16.790 -
  16.791 -      operator Edge() const {
  16.792 -	if (out == INVALID && in == INVALID) return INVALID;
  16.793 -	return out != INVALID ? backward(out) : forward(in);
  16.794 -      }
  16.795 -
  16.796 -      bool operator==(const Edge i) const {return Edge(*this) == i;}
  16.797 -      bool operator!=(const Edge i) const {return Edge(*this) != i;}
  16.798 -      bool operator<(const Edge i) const {return Edge(*this) < i;}
  16.799 -    };
  16.800 -
  16.801 -    class SymEdgeIt : public Parent::EdgeIt {
  16.802 -
  16.803 -    public:
  16.804 -      SymEdgeIt() {}
  16.805 -
  16.806 -      SymEdgeIt(const SymListGraph& g) 
  16.807 -	: SymListGraph::Parent::EdgeIt(g) {}
  16.808 -
  16.809 -      SymEdgeIt(const SymListGraph& g, SymEdge e) 
  16.810 -	: SymListGraph::Parent::EdgeIt(g, e) {}
  16.811 -
  16.812 -      SymEdgeIt(Invalid i) 
  16.813 -	: SymListGraph::Parent::EdgeIt(INVALID) {}
  16.814 -
  16.815 -      SymEdgeIt& operator++() {
  16.816 -	SymListGraph::Parent::EdgeIt::operator++();
  16.817 -	return *this;
  16.818 -      }
  16.819 -
  16.820 -      operator SymEdge() const {
  16.821 -	return SymEdge
  16.822 -	  (static_cast<const SymListGraph::Parent::EdgeIt&>(*this));
  16.823 -      }
  16.824 -      bool operator==(const SymEdge i) const {return SymEdge(*this) == i;}
  16.825 -      bool operator!=(const SymEdge i) const {return SymEdge(*this) != i;}
  16.826 -      bool operator<(const SymEdge i) const {return SymEdge(*this) < i;}
  16.827 -    };
  16.828 -
  16.829 -    class EdgeIt {
  16.830 -      SymEdgeIt it;
  16.831 -      bool fw;
  16.832 -    public:
  16.833 -      EdgeIt(const SymListGraph& g) : it(g), fw(true) {}
  16.834 -      EdgeIt (Invalid i) : it(i) { }
  16.835 -      EdgeIt(const SymListGraph& g, Edge e) 
  16.836 -	: it(g, SymEdge(e)), fw(id(e) & 1 == 0) { }
  16.837 -      EdgeIt() { }
  16.838 -      EdgeIt& operator++() {
  16.839 -	fw = !fw;
  16.840 -	if (fw) ++it;
  16.841 -	return *this;
  16.842 -      }
  16.843 -      operator Edge() const {
  16.844 -	if (it == INVALID) return INVALID;
  16.845 -	return fw ? forward(it) : backward(it);
  16.846 -      }
  16.847 -      bool operator==(const Edge i) const {return Edge(*this) == i;}
  16.848 -      bool operator!=(const Edge i) const {return Edge(*this) != i;}
  16.849 -      bool operator<(const Edge i) const {return Edge(*this) < i;}
  16.850 -
  16.851 -    };
  16.852 -
  16.853 -    ///Number of nodes.
  16.854 -    int nodeNum() const { return Parent::nodeNum(); }
  16.855 -    ///Number of edges.
  16.856 -    int edgeNum() const { return 2*Parent::edgeNum(); }
  16.857 -    ///Number of symmetric edges.
  16.858 -    int symEdgeNum() const { return Parent::edgeNum(); }
  16.859 -
  16.860 -    ///Set the expected maximum number of edges.
  16.861 -
  16.862 -    ///With this function, it is possible to set the expected number of edges.
  16.863 -    ///The use of this fasten the building of the graph and makes
  16.864 -    ///it possible to avoid the superfluous memory allocation.
  16.865 -    void reserveSymEdge(int n) { Parent::reserveEdge(n); };
  16.866 -    
  16.867 -    /// Maximum node ID.
  16.868 -    
  16.869 -    /// Maximum node ID.
  16.870 -    ///\sa id(Node)
  16.871 -    int maxNodeId() const { return Parent::maxNodeId(); } 
  16.872 -    /// Maximum edge ID.
  16.873 -    
  16.874 -    /// Maximum edge ID.
  16.875 -    ///\sa id(Edge)
  16.876 -    int maxEdgeId() const { return 2*Parent::maxEdgeId(); }
  16.877 -    /// Maximum symmetric edge ID.
  16.878 -    
  16.879 -    /// Maximum symmetric edge ID.
  16.880 -    ///\sa id(SymEdge)
  16.881 -    int maxSymEdgeId() const { return Parent::maxEdgeId(); }
  16.882 -
  16.883 -
  16.884 -    Node tail(Edge e) const { 
  16.885 -      return (e.id & 1) == 0 ? 
  16.886 -	Parent::tail(SymEdge(e)) : Parent::head(SymEdge(e)); 
  16.887 -    }
  16.888 -
  16.889 -    Node head(Edge e) const { 
  16.890 -      return (e.id & 1) == 0 ? 
  16.891 -	Parent::head(SymEdge(e)) : Parent::tail(SymEdge(e)); 
  16.892 -    }
  16.893 -
  16.894 -    Node tail(SymEdge e) const { 
  16.895 -      return Parent::tail(e); 
  16.896 -    }
  16.897 -
  16.898 -    Node head(SymEdge e) const { 
  16.899 -      return Parent::head(e); 
  16.900 -    }
  16.901 -
  16.902 -    NodeIt& first(NodeIt& v) const { 
  16.903 -      v=NodeIt(*this); return v; }
  16.904 -    EdgeIt& first(EdgeIt& e) const { 
  16.905 -      e=EdgeIt(*this); return e; }
  16.906 -    SymEdgeIt& first(SymEdgeIt& e) const {
  16.907 -      e=SymEdgeIt(*this); return e; }
  16.908 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  16.909 -      e=OutEdgeIt(*this,v); return e; }
  16.910 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  16.911 -      e=InEdgeIt(*this,v); return e; }
  16.912 -
  16.913 -    /// Node ID.
  16.914 -    
  16.915 -    /// The ID of a valid Node is a nonnegative integer not greater than
  16.916 -    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  16.917 -    /// and the greatest node ID can be actually less then \ref maxNodeId().
  16.918 -    ///
  16.919 -    /// The ID of the \ref INVALID node is -1.
  16.920 -    ///\return The ID of the node \c v. 
  16.921 -    static int id(Node v) { return Parent::id(v); }
  16.922 -    /// Edge ID.
  16.923 -    
  16.924 -    /// The ID of a valid Edge is a nonnegative integer not greater than
  16.925 -    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  16.926 -    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  16.927 -    ///
  16.928 -    /// The ID of the \ref INVALID edge is -1.
  16.929 -    ///\return The ID of the edge \c e. 
  16.930 -    static int id(Edge e) { return e.id; }
  16.931 -
  16.932 -    /// The ID of a valid SymEdge is a nonnegative integer not greater than
  16.933 -    /// \ref maxSymEdgeId(). The range of the ID's is not surely continuous
  16.934 -    /// and the greatest edge ID can be actually less then \ref maxSymEdgeId().
  16.935 -    ///
  16.936 -    /// The ID of the \ref INVALID symmetric edge is -1.
  16.937 -    ///\return The ID of the edge \c e. 
  16.938 -    static int id(SymEdge e) { return Parent::id(e); }
  16.939 -
  16.940 -    /// Adds a new node to the graph.
  16.941 -
  16.942 -    /// \warning It adds the new node to the front of the list.
  16.943 -    /// (i.e. the lastly added node becomes the first.)
  16.944 -    Node addNode() {
  16.945 -      return Parent::addNode();
  16.946 -    }
  16.947 -    
  16.948 -    SymEdge addEdge(Node u, Node v) {
  16.949 -      SymEdge se = Parent::addEdge(u, v);
  16.950 -      edge_maps.add(forward(se));
  16.951 -      edge_maps.add(backward(se));
  16.952 -      return se;
  16.953 -    }
  16.954 -    
  16.955 -    /// Finds an edge between two nodes.
  16.956 -
  16.957 -    /// Finds an edge from node \c u to node \c v.
  16.958 -    ///
  16.959 -    /// If \c prev is \ref INVALID (this is the default value), then
  16.960 -    /// It finds the first edge from \c u to \c v. Otherwise it looks for
  16.961 -    /// the next edge from \c u to \c v after \c prev.
  16.962 -    /// \return The found edge or INVALID if there is no such an edge.
  16.963 -    Edge findEdge(Node u, Node v, Edge prev = INVALID) 
  16.964 -    {     
  16.965 -      if (prev == INVALID || id(prev) & 1 == 0) {
  16.966 -	SymEdge se = Parent::findEdge(u, v, SymEdge(prev));
  16.967 -	if (se != INVALID) return forward(se);
  16.968 -      } else {
  16.969 -	SymEdge se = Parent::findEdge(v, u, SymEdge(prev));
  16.970 -	if (se != INVALID) return backward(se);	
  16.971 -      }
  16.972 -      return INVALID;
  16.973 -    }
  16.974 -
  16.975 -//     /// Finds an symmetric edge between two nodes.
  16.976 -
  16.977 -//     /// Finds an symmetric edge from node \c u to node \c v.
  16.978 -//     ///
  16.979 -//     /// If \c prev is \ref INVALID (this is the default value), then
  16.980 -//     /// It finds the first edge from \c u to \c v. Otherwise it looks for
  16.981 -//     /// the next edge from \c u to \c v after \c prev.
  16.982 -//     /// \return The found edge or INVALID if there is no such an edge.
  16.983 -
  16.984 -//     SymEdge findEdge(Node u, Node v, SymEdge prev = INVALID) 
  16.985 -//     {     
  16.986 -//       if (prev == INVALID || id(prev) & 1 == 0) {
  16.987 -// 	SymEdge se = Parent::findEdge(u, v, SymEdge(prev));
  16.988 -// 	if (se != INVALID) return se;
  16.989 -//       } else {
  16.990 -// 	SymEdge se = Parent::findEdge(v, u, SymEdge(prev));
  16.991 -// 	if (se != INVALID) return se;	
  16.992 -//       }
  16.993 -//       return INVALID;
  16.994 -//     }
  16.995 -    
  16.996 -  public:
  16.997 -
  16.998 -    void erase(Node n) {      
  16.999 -      for (OutEdgeIt it(*this, n); it != INVALID; ++it) {
 16.1000 -	edge_maps.erase(it);
 16.1001 -	edge_maps.erase(opposite(it));
 16.1002 -      }
 16.1003 -      Parent::erase(n);
 16.1004 -    }
 16.1005 -    
 16.1006 -    void erase(SymEdge e) { 
 16.1007 -      edge_maps.erase(forward(e));
 16.1008 -      edge_maps.erase(backward(e));
 16.1009 -      Parent::erase(e); 
 16.1010 -    };
 16.1011 -
 16.1012 -    void clear() {
 16.1013 -      edge_maps.clear();
 16.1014 -      Parent::clear();
 16.1015 -    }
 16.1016 -
 16.1017 -    static Edge opposite(Edge e) {
 16.1018 -      return Edge(id(e) ^ 1);
 16.1019 -    }
 16.1020 -
 16.1021 -    static Edge forward(SymEdge e) {
 16.1022 -      return Edge(id(e) << 1);
 16.1023 -    }
 16.1024 -
 16.1025 -    static Edge backward(SymEdge e) {
 16.1026 -      return Edge((id(e) << 1) | 1);
 16.1027 +      first_node = first_free_node = first_free_edge = -1;
 16.1028      }
 16.1029  
 16.1030    };
 16.1031  
 16.1032 -  ///A graph class containing only nodes.
 16.1033 +  typedef AlterableGraphExtender<ListGraphBase> AlterableListGraphBase;
 16.1034 +  typedef IterableGraphExtender<AlterableListGraphBase> IterableListGraphBase;
 16.1035 +  typedef IdMappableGraphExtender<IterableListGraphBase> IdMappableListGraphBase;
 16.1036 +  typedef DefaultMappableGraphExtender<IdMappableListGraphBase> MappableListGraphBase;
 16.1037 +  typedef ExtendableGraphExtender<MappableListGraphBase> ExtendableListGraphBase;
 16.1038 +  typedef ClearableGraphExtender<ExtendableListGraphBase> ClearableListGraphBase;
 16.1039 +  typedef ErasableGraphExtender<ClearableListGraphBase> ErasableListGraphBase;
 16.1040  
 16.1041 -  ///This class implements a graph structure without edges.
 16.1042 -  ///The most useful application of this class is to be the node set of an
 16.1043 -  ///\ref EdgeSet class.
 16.1044 -  ///
 16.1045 -  ///It conforms to 
 16.1046 -  ///the \ref skeleton::ExtendableGraph "ExtendableGraph" concept
 16.1047 -  ///with the exception that you cannot
 16.1048 -  ///add (or delete) edges. The usual edge iterators are exists, but they are
 16.1049 -  ///always \ref INVALID.
 16.1050 -  ///\sa skeleton::ExtendableGraph
 16.1051 -  ///\sa EdgeSet
 16.1052 -  class NodeSet {
 16.1053 +  typedef ErasableListGraphBase ListGraph;
 16.1054  
 16.1055 -    //Nodes are double linked.
 16.1056 -    //The free nodes are only single linked using the "next" field.
 16.1057 -    struct NodeT 
 16.1058 -    {
 16.1059 -      int first_in,first_out;
 16.1060 -      int prev, next;
 16.1061 -      //      NodeT() {}
 16.1062 -    };
 16.1063 +}
 16.1064  
 16.1065 -    std::vector<NodeT> nodes;
 16.1066 -    //The first node
 16.1067 -    int first_node;
 16.1068 -    //The first free node
 16.1069 -    int first_free_node;
 16.1070 -    
 16.1071 -  public:
 16.1072  
 16.1073 -    typedef NodeSet Graph;
 16.1074 -    
 16.1075 -    class Node;
 16.1076 -    class Edge;
 16.1077 +  
 16.1078  
 16.1079 -  public:
 16.1080 -
 16.1081 -    class NodeIt;
 16.1082 -    class EdgeIt;
 16.1083 -    class OutEdgeIt;
 16.1084 -    class InEdgeIt;
 16.1085 -    
 16.1086 -    // Create node map registry.
 16.1087 -    CREATE_NODE_MAP_REGISTRY;
 16.1088 -    // Create node maps.
 16.1089 -    CREATE_NODE_MAP(ArrayMap);
 16.1090 -
 16.1091 -    /// Creating empty map structure for edges.
 16.1092 -    template <typename Value>
 16.1093 -    class EdgeMap {
 16.1094 -    public:
 16.1095 -      EdgeMap(const Graph&) {}
 16.1096 -      EdgeMap(const Graph&, const Value&) {}
 16.1097 -
 16.1098 -      EdgeMap(const EdgeMap&) {}
 16.1099 -      template <typename CMap> EdgeMap(const CMap&) {}
 16.1100 -
 16.1101 -      EdgeMap& operator=(const EdgeMap&) {}
 16.1102 -      template <typename CMap> EdgeMap& operator=(const CMap&) {}
 16.1103 -      
 16.1104 -      class ConstIterator {
 16.1105 -      public:
 16.1106 -	bool operator==(const ConstIterator&) {return true;}
 16.1107 -	bool operator!=(const ConstIterator&) {return false;}
 16.1108 -      };
 16.1109 -
 16.1110 -      typedef ConstIterator Iterator;
 16.1111 -      
 16.1112 -      Iterator begin() { return Iterator();}
 16.1113 -      Iterator end() { return Iterator();}
 16.1114 -
 16.1115 -      ConstIterator begin() const { return ConstIterator();}
 16.1116 -      ConstIterator end() const { return ConstIterator();}
 16.1117 -
 16.1118 -    };
 16.1119 -    
 16.1120 -  public:
 16.1121 -
 16.1122 -    ///Default constructor
 16.1123 -    NodeSet() 
 16.1124 -      : nodes(), first_node(-1), first_free_node(-1) {}
 16.1125 -    ///Copy constructor
 16.1126 -    NodeSet(const NodeSet &_g) 
 16.1127 -      : nodes(_g.nodes), first_node(_g.first_node),
 16.1128 -	first_free_node(_g.first_free_node) {}
 16.1129 -    
 16.1130 -    ///Number of nodes.
 16.1131 -    int nodeNum() const { return nodes.size(); }
 16.1132 -    ///Number of edges.
 16.1133 -    int edgeNum() const { return 0; }
 16.1134 -
 16.1135 -    /// Maximum node ID.
 16.1136 -    
 16.1137 -    /// Maximum node ID.
 16.1138 -    ///\sa id(Node)
 16.1139 -    int maxNodeId() const { return nodes.size()-1; }
 16.1140 -    /// Maximum edge ID.
 16.1141 -    
 16.1142 -    /// Maximum edge ID.
 16.1143 -    ///\sa id(Edge)
 16.1144 -    int maxEdgeId() const { return 0; }
 16.1145 -
 16.1146 -    Node tail(Edge e) const { return INVALID; }
 16.1147 -    Node head(Edge e) const { return INVALID; }
 16.1148 -
 16.1149 -    NodeIt& first(NodeIt& v) const { 
 16.1150 -      v=NodeIt(*this); return v; }
 16.1151 -    EdgeIt& first(EdgeIt& e) const { 
 16.1152 -      e=EdgeIt(*this); return e; }
 16.1153 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
 16.1154 -      e=OutEdgeIt(*this,v); return e; }
 16.1155 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
 16.1156 -      e=InEdgeIt(*this,v); return e; }
 16.1157 -
 16.1158 -    /// Node ID.
 16.1159 -    
 16.1160 -    /// The ID of a valid Node is a nonnegative integer not greater than
 16.1161 -    /// \ref maxNodeId(). The range of the ID's is not surely continuous
 16.1162 -    /// and the greatest node ID can be actually less then \ref maxNodeId().
 16.1163 -    ///
 16.1164 -    /// The ID of the \ref INVALID node is -1.
 16.1165 -    ///\return The ID of the node \c v. 
 16.1166 -    static int id(Node v) { return v.n; }
 16.1167 -    /// Edge ID.
 16.1168 -    
 16.1169 -    /// The ID of a valid Edge is a nonnegative integer not greater than
 16.1170 -    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
 16.1171 -    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
 16.1172 -    ///
 16.1173 -    /// The ID of the \ref INVALID edge is -1.
 16.1174 -    ///\return The ID of the edge \c e. 
 16.1175 -    static int id(Edge e) { return -1; }
 16.1176 -
 16.1177 -    /// Adds a new node to the graph.
 16.1178 -
 16.1179 -    /// \warning It adds the new node to the front of the list.
 16.1180 -    /// (i.e. the lastly added node becomes the first.)
 16.1181 -    Node addNode() {
 16.1182 -      int n;
 16.1183 -      
 16.1184 -      if(first_free_node==-1)
 16.1185 -	{
 16.1186 -	  n = nodes.size();
 16.1187 -	  nodes.push_back(NodeT());
 16.1188 -	}
 16.1189 -      else {
 16.1190 -	n = first_free_node;
 16.1191 -	first_free_node = nodes[n].next;
 16.1192 -      }
 16.1193 -      
 16.1194 -      nodes[n].next = first_node;
 16.1195 -      if(first_node != -1) nodes[first_node].prev = n;
 16.1196 -      first_node = n;
 16.1197 -      nodes[n].prev = -1;
 16.1198 -      
 16.1199 -      nodes[n].first_in = nodes[n].first_out = -1;
 16.1200 -      
 16.1201 -      Node nn; nn.n=n;
 16.1202 -
 16.1203 -      //Update dynamic maps
 16.1204 -      node_maps.add(nn);
 16.1205 -
 16.1206 -      return nn;
 16.1207 -    }
 16.1208 -    
 16.1209 -    void erase(Node nn) {
 16.1210 -      int n=nn.n;
 16.1211 -      
 16.1212 -      if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
 16.1213 -      if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
 16.1214 -      else first_node = nodes[n].next;
 16.1215 -      
 16.1216 -      nodes[n].next = first_free_node;
 16.1217 -      first_free_node = n;
 16.1218 -
 16.1219 -      //Update dynamic maps
 16.1220 -      node_maps.erase(nn);
 16.1221 -    }
 16.1222 -    
 16.1223 -        
 16.1224 -    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
 16.1225 -    {
 16.1226 -      return INVALID;
 16.1227 -    }
 16.1228 -    
 16.1229 -    void clear() {
 16.1230 -      node_maps.clear();
 16.1231 -      nodes.clear();
 16.1232 -      first_node = first_free_node = -1;
 16.1233 -    }
 16.1234 -
 16.1235 -    class Node {
 16.1236 -      friend class NodeSet;
 16.1237 -      template <typename T> friend class NodeMap;
 16.1238 -      
 16.1239 -      friend class Edge;
 16.1240 -      friend class OutEdgeIt;
 16.1241 -      friend class InEdgeIt;
 16.1242 -
 16.1243 -    protected:
 16.1244 -      int n;
 16.1245 -      friend int NodeSet::id(Node v); 
 16.1246 -      Node(int nn) {n=nn;}
 16.1247 -    public:
 16.1248 -      Node() {}
 16.1249 -      Node (Invalid i) { n=-1; }
 16.1250 -      bool operator==(const Node i) const {return n==i.n;}
 16.1251 -      bool operator!=(const Node i) const {return n!=i.n;}
 16.1252 -      bool operator<(const Node i) const {return n<i.n;}
 16.1253 -    };
 16.1254 -    
 16.1255 -    class NodeIt : public Node {
 16.1256 -      const NodeSet *G;
 16.1257 -      friend class NodeSet;
 16.1258 -    public:
 16.1259 -      NodeIt() : Node() { }
 16.1260 -      NodeIt(const NodeSet& _G,Node n) : Node(n), G(&_G) { }
 16.1261 -      NodeIt(Invalid i) : Node(i) { }
 16.1262 -      NodeIt(const NodeSet& _G) : Node(_G.first_node), G(&_G) { }
 16.1263 -      NodeIt &operator++() {
 16.1264 -	n=G->nodes[n].next; 
 16.1265 -	return *this; 
 16.1266 -      }
 16.1267 -    };
 16.1268 -
 16.1269 -    class Edge {
 16.1270 -    public:
 16.1271 -      Edge() { }
 16.1272 -      Edge (Invalid) { }
 16.1273 -      bool operator==(const Edge i) const {return true;}
 16.1274 -      bool operator!=(const Edge i) const {return false;}
 16.1275 -      bool operator<(const Edge i) const {return false;}
 16.1276 -    };
 16.1277 -    
 16.1278 -    class EdgeIt : public Edge {
 16.1279 -    public:
 16.1280 -      EdgeIt(const NodeSet& G) : Edge() { }
 16.1281 -      EdgeIt(const NodeSet&, Edge) : Edge() { }
 16.1282 -      EdgeIt (Invalid i) : Edge(i) { }
 16.1283 -      EdgeIt() : Edge() { }
 16.1284 -      EdgeIt operator++() { return INVALID; }
 16.1285 -    };
 16.1286 -    
 16.1287 -    class OutEdgeIt : public Edge {
 16.1288 -      friend class NodeSet;
 16.1289 -    public: 
 16.1290 -      OutEdgeIt() : Edge() { }
 16.1291 -      OutEdgeIt(const NodeSet&, Edge) : Edge() { }
 16.1292 -      OutEdgeIt (Invalid i) : Edge(i) { }
 16.1293 -      OutEdgeIt(const NodeSet& G,const Node v)	: Edge() {}
 16.1294 -      OutEdgeIt operator++() { return INVALID; }
 16.1295 -    };
 16.1296 -    
 16.1297 -    class InEdgeIt : public Edge {
 16.1298 -      friend class NodeSet;
 16.1299 -    public: 
 16.1300 -      InEdgeIt() : Edge() { }
 16.1301 -      InEdgeIt(const NodeSet&, Edge) : Edge() { }
 16.1302 -      InEdgeIt (Invalid i) : Edge(i) { }
 16.1303 -      InEdgeIt(const NodeSet& G,Node v) :Edge() {}
 16.1304 -      InEdgeIt operator++() { return INVALID; }
 16.1305 -    };
 16.1306 -
 16.1307 -  };
 16.1308 -
 16.1309 -
 16.1310 -
 16.1311 -  ///Graph structure using a node set of another graph.
 16.1312 -
 16.1313 -  ///This structure can be used to establish another graph over a node set
 16.1314 -  /// of an existing one. The node iterator will go through the nodes of the
 16.1315 -  /// original graph, and the NodeMap's of both graphs will convert to
 16.1316 -  /// each other.
 16.1317 -  ///
 16.1318 -  ///\warning Adding or deleting nodes from the graph is not safe if an
 16.1319 -  ///\ref EdgeSet is currently attached to it!
 16.1320 -  ///
 16.1321 -  ///\todo Make it possible to add/delete edges from the base graph
 16.1322 -  ///(and from \ref EdgeSet, as well)
 16.1323 -  ///
 16.1324 -  ///\param GG The type of the graph which shares its node set with this class.
 16.1325 -  ///Its interface must conform to the
 16.1326 -  ///\ref skeleton::StaticGraph "StaticGraph" concept.
 16.1327 -  ///
 16.1328 -  ///It conforms to the 
 16.1329 -  ///\ref skeleton::ExtendableGraph "ExtendableGraph" concept.
 16.1330 -  ///\sa skeleton::ExtendableGraph.
 16.1331 -  ///\sa NodeSet.
 16.1332 -  template<typename GG>
 16.1333 -  class EdgeSet {
 16.1334 -
 16.1335 -    typedef GG NodeGraphType;
 16.1336 -
 16.1337 -    NodeGraphType &G;
 16.1338 -
 16.1339 -  public:
 16.1340 -
 16.1341 -    class Node;
 16.1342 -    class Edge;
 16.1343 -    class OutEdgeIt;
 16.1344 -    class InEdgeIt;
 16.1345 -    class SymEdge;
 16.1346 -
 16.1347 -    typedef EdgeSet Graph;
 16.1348 -
 16.1349 -    int id(Node v) const; 
 16.1350 -
 16.1351 -    class Node : public NodeGraphType::Node {
 16.1352 -      friend class EdgeSet;
 16.1353 -      
 16.1354 -      friend class Edge;
 16.1355 -      friend class OutEdgeIt;
 16.1356 -      friend class InEdgeIt;
 16.1357 -      friend class SymEdge;
 16.1358 -
 16.1359 -    public:
 16.1360 -      friend int EdgeSet::id(Node v) const; 
 16.1361 -    public:
 16.1362 -      Node() : NodeGraphType::Node() {}
 16.1363 -      Node (Invalid i) : NodeGraphType::Node(i) {}
 16.1364 -      Node(const typename NodeGraphType::Node &n) : NodeGraphType::Node(n) {}
 16.1365 -    };
 16.1366 -    
 16.1367 -    class NodeIt : public NodeGraphType::NodeIt {
 16.1368 -      friend class EdgeSet;
 16.1369 -    public:
 16.1370 -      NodeIt() : NodeGraphType::NodeIt() { }
 16.1371 -      NodeIt(const EdgeSet& _G,Node n) : NodeGraphType::NodeIt(_G.G,n) { }
 16.1372 -      NodeIt (Invalid i) : NodeGraphType::NodeIt(i) {}
 16.1373 -      NodeIt(const EdgeSet& _G) : NodeGraphType::NodeIt(_G.G) { }
 16.1374 -      NodeIt(const typename NodeGraphType::NodeIt &n)
 16.1375 -	: NodeGraphType::NodeIt(n) {}
 16.1376 -
 16.1377 -      operator Node() { return Node(*this);}
 16.1378 -      NodeIt &operator++()
 16.1379 -      { this->NodeGraphType::NodeIt::operator++(); return *this;} 
 16.1380 -    };
 16.1381 -
 16.1382 -  private:
 16.1383 -    //Edges are double linked.
 16.1384 -    //The free edges are only single linked using the "next_in" field.
 16.1385 -    struct NodeT 
 16.1386 -    {
 16.1387 -      int first_in,first_out;
 16.1388 -      NodeT() : first_in(-1), first_out(-1) { }
 16.1389 -    };
 16.1390 -
 16.1391 -    struct EdgeT 
 16.1392 -    {
 16.1393 -      Node head, tail;
 16.1394 -      int prev_in, prev_out;
 16.1395 -      int next_in, next_out;
 16.1396 -    };
 16.1397 -
 16.1398 -    
 16.1399 -    typename NodeGraphType::template NodeMap<NodeT> nodes;
 16.1400 -    
 16.1401 -    std::vector<EdgeT> edges;
 16.1402 -    //The first free edge
 16.1403 -    int first_free_edge;
 16.1404 -    
 16.1405 -  public:
 16.1406 -    
 16.1407 -    class Node;
 16.1408 -    class Edge;
 16.1409 -
 16.1410 -    class NodeIt;
 16.1411 -    class EdgeIt;
 16.1412 -    class OutEdgeIt;
 16.1413 -    class InEdgeIt;
 16.1414 -
 16.1415 -
 16.1416 -    // Create edge map registry.
 16.1417 -    CREATE_EDGE_MAP_REGISTRY;
 16.1418 -    // Create edge maps.
 16.1419 -    CREATE_EDGE_MAP(ArrayMap);
 16.1420 -
 16.1421 -    // Import node maps from the NodeGraphType.
 16.1422 -    IMPORT_NODE_MAP(NodeGraphType, graph.G, EdgeSet, graph);
 16.1423 -    
 16.1424 -    
 16.1425 -  public:
 16.1426 -
 16.1427 -    ///Constructor
 16.1428 -    
 16.1429 -    ///Construates a new graph based on the nodeset of an existing one.
 16.1430 -    ///\param _G the base graph.
 16.1431 -    explicit EdgeSet(NodeGraphType &_G) 
 16.1432 -      : G(_G), nodes(_G), edges(),
 16.1433 -	first_free_edge(-1) {}
 16.1434 -    ///Copy constructor
 16.1435 -
 16.1436 -    ///Makes a copy of an EdgeSet.
 16.1437 -    ///It will be based on the same graph.
 16.1438 -    explicit EdgeSet(const EdgeSet &_g) 
 16.1439 -      : G(_g.G), nodes(_g.G), edges(_g.edges),
 16.1440 -	first_free_edge(_g.first_free_edge) {}
 16.1441 -    
 16.1442 -    ///Number of nodes.
 16.1443 -    int nodeNum() const { return G.nodeNum(); }
 16.1444 -    ///Number of edges.
 16.1445 -    int edgeNum() const { return edges.size(); }
 16.1446 -
 16.1447 -    /// Maximum node ID.
 16.1448 -    
 16.1449 -    /// Maximum node ID.
 16.1450 -    ///\sa id(Node)
 16.1451 -    int maxNodeId() const { return G.maxNodeId(); }
 16.1452 -    /// Maximum edge ID.
 16.1453 -    
 16.1454 -    /// Maximum edge ID.
 16.1455 -    ///\sa id(Edge)
 16.1456 -    int maxEdgeId() const { return edges.size()-1; }
 16.1457 -
 16.1458 -    Node tail(Edge e) const { return edges[e.n].tail; }
 16.1459 -    Node head(Edge e) const { return edges[e.n].head; }
 16.1460 -
 16.1461 -    NodeIt& first(NodeIt& v) const { 
 16.1462 -      v=NodeIt(*this); return v; }
 16.1463 -    EdgeIt& first(EdgeIt& e) const { 
 16.1464 -      e=EdgeIt(*this); return e; }
 16.1465 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
 16.1466 -      e=OutEdgeIt(*this,v); return e; }
 16.1467 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
 16.1468 -      e=InEdgeIt(*this,v); return e; }
 16.1469 -
 16.1470 -    /// Node ID.
 16.1471 -    
 16.1472 -    /// The ID of a valid Node is a nonnegative integer not greater than
 16.1473 -    /// \ref maxNodeId(). The range of the ID's is not surely continuous
 16.1474 -    /// and the greatest node ID can be actually less then \ref maxNodeId().
 16.1475 -    ///
 16.1476 -    /// The ID of the \ref INVALID node is -1.
 16.1477 -    ///\return The ID of the node \c v. 
 16.1478 -    int id(Node v) { return G.id(v); }
 16.1479 -    /// Edge ID.
 16.1480 -    
 16.1481 -    /// The ID of a valid Edge is a nonnegative integer not greater than
 16.1482 -    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
 16.1483 -    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
 16.1484 -    ///
 16.1485 -    /// The ID of the \ref INVALID edge is -1.
 16.1486 -    ///\return The ID of the edge \c e. 
 16.1487 -    static int id(Edge e) { return e.n; }
 16.1488 -
 16.1489 -    /// Adds a new node to the graph.
 16.1490 -    Node addNode() { return G.addNode(); }
 16.1491 -    
 16.1492 -    Edge addEdge(Node u, Node v) {
 16.1493 -      int n;
 16.1494 -      
 16.1495 -      if(first_free_edge==-1)
 16.1496 -	{
 16.1497 -	  n = edges.size();
 16.1498 -	  edges.push_back(EdgeT());
 16.1499 -	}
 16.1500 -      else {
 16.1501 -	n = first_free_edge;
 16.1502 -	first_free_edge = edges[n].next_in;
 16.1503 -      }
 16.1504 -      
 16.1505 -      edges[n].tail = u; edges[n].head = v;
 16.1506 -
 16.1507 -      edges[n].next_out = nodes[u].first_out;
 16.1508 -      if(nodes[u].first_out != -1) edges[nodes[u].first_out].prev_out = n;
 16.1509 -      edges[n].next_in = nodes[v].first_in;
 16.1510 -      if(nodes[v].first_in != -1) edges[nodes[v].first_in].prev_in = n;
 16.1511 -      edges[n].prev_in = edges[n].prev_out = -1;
 16.1512 -	
 16.1513 -      nodes[u].first_out = nodes[v].first_in = n;
 16.1514 -
 16.1515 -      Edge e; e.n=n;
 16.1516 -
 16.1517 -      //Update dynamic maps
 16.1518 -      edge_maps.add(e);
 16.1519 -
 16.1520 -      return e;
 16.1521 -    }
 16.1522 -
 16.1523 -    /// Finds an edge between two nodes.
 16.1524 -
 16.1525 -    /// Finds an edge from node \c u to node \c v.
 16.1526 -    ///
 16.1527 -    /// If \c prev is \ref INVALID (this is the default value), then
 16.1528 -    /// It finds the first edge from \c u to \c v. Otherwise it looks for
 16.1529 -    /// the next edge from \c u to \c v after \c prev.
 16.1530 -    /// \return The found edge or INVALID if there is no such an edge.
 16.1531 -    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
 16.1532 -    {
 16.1533 -      int e = (prev.n==-1)? nodes[u].first_out : edges[prev.n].next_out;
 16.1534 -      while(e!=-1 && edges[e].tail!=v) e = edges[e].next_out;
 16.1535 -      prev.n=e;
 16.1536 -      return prev;
 16.1537 -    }
 16.1538 -    
 16.1539 -  private:
 16.1540 -    void eraseEdge(int n) {
 16.1541 -      
 16.1542 -      if(edges[n].next_in!=-1)
 16.1543 -	edges[edges[n].next_in].prev_in = edges[n].prev_in;
 16.1544 -      if(edges[n].prev_in!=-1)
 16.1545 -	edges[edges[n].prev_in].next_in = edges[n].next_in;
 16.1546 -      else nodes[edges[n].head].first_in = edges[n].next_in;
 16.1547 -      
 16.1548 -      if(edges[n].next_out!=-1)
 16.1549 -	edges[edges[n].next_out].prev_out = edges[n].prev_out;
 16.1550 -      if(edges[n].prev_out!=-1)
 16.1551 -	edges[edges[n].prev_out].next_out = edges[n].next_out;
 16.1552 -      else nodes[edges[n].tail].first_out = edges[n].next_out;
 16.1553 -      
 16.1554 -      edges[n].next_in = first_free_edge;
 16.1555 -      first_free_edge = -1;      
 16.1556 -
 16.1557 -      //Update dynamic maps
 16.1558 -      Edge e; e.n = n;
 16.1559 -      edge_maps.erase(e);
 16.1560 -    }
 16.1561 -      
 16.1562 -  public:
 16.1563 -
 16.1564 -    void erase(Edge e) { eraseEdge(e.n); }
 16.1565 -
 16.1566 -    ///Clear all edges. (Doesn't clear the nodes!)
 16.1567 -    void clear() {
 16.1568 -      edge_maps.clear();
 16.1569 -      edges.clear();
 16.1570 -      first_free_edge=-1;
 16.1571 -    }
 16.1572 -
 16.1573 -
 16.1574 -    class Edge {
 16.1575 -    public:
 16.1576 -      friend class EdgeSet;
 16.1577 -      template <typename T> friend class EdgeMap;
 16.1578 -
 16.1579 -      friend class Node;
 16.1580 -      friend class NodeIt;
 16.1581 -    protected:
 16.1582 -      int n;
 16.1583 -      friend int EdgeSet::id(Edge e) const;
 16.1584 -
 16.1585 -      Edge(int nn) {n=nn;}
 16.1586 -    public:
 16.1587 -      Edge() { }
 16.1588 -      Edge (Invalid) { n=-1; }
 16.1589 -      bool operator==(const Edge i) const {return n==i.n;}
 16.1590 -      bool operator!=(const Edge i) const {return n!=i.n;}
 16.1591 -      bool operator<(const Edge i) const {return n<i.n;}
 16.1592 -    };
 16.1593 -    
 16.1594 -    class EdgeIt : public Edge {
 16.1595 -      friend class EdgeSet;
 16.1596 -      template <typename T> friend class EdgeMap;
 16.1597 -    
 16.1598 -      const EdgeSet *G;
 16.1599 -    public:
 16.1600 -      EdgeIt(const EdgeSet& _G) : Edge(), G(&_G) {
 16.1601 -        NodeIt m;
 16.1602 -	for(G->first(m);
 16.1603 -	    m!=INVALID && G->nodes[m].first_in == -1;  ++m);
 16.1604 -	///\bug AJJAJ! This is a non sense!!!!!!!
 16.1605 -	this->n = m!=INVALID?-1:G->nodes[m].first_in;
 16.1606 -      }
 16.1607 -      EdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
 16.1608 -      EdgeIt (Invalid i) : Edge(i) { }
 16.1609 -      EdgeIt() : Edge() { }
 16.1610 -      ///.
 16.1611 -      
 16.1612 -      ///\bug UNIMPLEMENTED!!!!!
 16.1613 -      //
 16.1614 -      EdgeIt &operator++() {
 16.1615 -	return *this;
 16.1616 -      }
 16.1617 -    };
 16.1618 -    
 16.1619 -    class OutEdgeIt : public Edge {
 16.1620 -      const EdgeSet *G;
 16.1621 -      friend class EdgeSet;
 16.1622 -    public: 
 16.1623 -      OutEdgeIt() : Edge() { }
 16.1624 -      OutEdgeIt (Invalid i) : Edge(i) { }
 16.1625 -      OutEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
 16.1626 -
 16.1627 -      OutEdgeIt(const EdgeSet& _G,const Node v) :
 16.1628 -	Edge(_G.nodes[v].first_out), G(&_G) { }
 16.1629 -      OutEdgeIt &operator++() { 
 16.1630 -	Edge::n = G->edges[Edge::n].next_out;
 16.1631 -	return *this; 
 16.1632 -      }
 16.1633 -    };
 16.1634 -    
 16.1635 -    class InEdgeIt : public Edge {
 16.1636 -      const EdgeSet *G;
 16.1637 -      friend class EdgeSet;
 16.1638 -    public: 
 16.1639 -      InEdgeIt() : Edge() { }
 16.1640 -      InEdgeIt (Invalid i) : Edge(i) { }
 16.1641 -      InEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
 16.1642 -      InEdgeIt(const EdgeSet& _G,Node v)
 16.1643 -	: Edge(_G.nodes[v].first_in), G(&_G) { }
 16.1644 -      InEdgeIt &operator++() { 
 16.1645 -	Edge::n = G->edges[Edge::n].next_in; 
 16.1646 -	return *this; 
 16.1647 -      }
 16.1648 -    };
 16.1649 -    
 16.1650 -  };
 16.1651 -
 16.1652 -  template<typename GG>
 16.1653 -  inline int EdgeSet<GG>::id(Node v) const { return G.id(v); }
 16.1654 -
 16.1655 -/// @}  
 16.1656 -
 16.1657 -} //namespace lemon
 16.1658 -
 16.1659 -#endif //LEMON_LIST_GRAPH_H
 16.1660 +#endif
    17.1 --- a/src/lemon/map_registry.h	Mon Oct 25 13:29:46 2004 +0000
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,359 +0,0 @@
    17.4 -/* -*- C++ -*-
    17.5 - * src/lemon/map_registry.h - Part of LEMON, a generic C++ optimization library
    17.6 - *
    17.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    17.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    17.9 - *
   17.10 - * Permission to use, modify and distribute this software is granted
   17.11 - * provided that this copyright notice appears in all copies. For
   17.12 - * precise terms see the accompanying LICENSE file.
   17.13 - *
   17.14 - * This software is provided "AS IS" with no warranty of any kind,
   17.15 - * express or implied, and with no claim as to its suitability for any
   17.16 - * purpose.
   17.17 - *
   17.18 - */
   17.19 -
   17.20 -#ifndef LEMON_MAP_REGISTRY_H
   17.21 -#define LEMON_MAP_REGISTRY_H
   17.22 -
   17.23 -#include <vector>
   17.24 -
   17.25 -///\ingroup graphmapfactory
   17.26 -///\file
   17.27 -///\brief Map registry for graph maps.
   17.28 -
   17.29 -namespace lemon {
   17.30 -
   17.31 -  /// \addtogroup graphmapfactory
   17.32 -  /// @{
   17.33 -
   17.34 -  /// Map registry for graph maps.
   17.35 -
   17.36 -  /** 
   17.37 -   * Registry class to register edge or node maps into the graph. The
   17.38 -   * registry helps you to implement an observer pattern. If you add
   17.39 -   * or erase an edge or node you must notify all the maps about the
   17.40 -   * event.
   17.41 -   *
   17.42 -   * \param G The graph type to register maps.
   17.43 -   * \param K The key type of the maps registered into the registry.
   17.44 -   * \param KIt The key iterator type iterates on the keys.
   17.45 -   *
   17.46 -   * \author Balazs Dezso
   17.47 -   */
   17.48 -
   17.49 -  template <typename G, typename K, typename KIt>
   17.50 -  class MapRegistry {
   17.51 -  public:
   17.52 -    typedef G Graph;
   17.53 -    typedef K KeyType;
   17.54 -    typedef KIt KeyIt;
   17.55 -
   17.56 -    /// MapBase is the base class of the dynamic maps.
   17.57 -	
   17.58 -    /**
   17.59 -     * MapBase is the base class of the dynamic maps.
   17.60 -     * It defines the core modification operations on the maps and
   17.61 -     * implements some helper functions. 
   17.62 -     */
   17.63 -    class MapBase {
   17.64 -    public:
   17.65 -      typedef G Graph;
   17.66 -      typedef K KeyType;
   17.67 -      typedef KIt KeyIt;
   17.68 -
   17.69 -      typedef MapRegistry<G, K, KIt> Registry;
   17.70 -	
   17.71 -      friend class MapRegistry<G, K, KIt>;
   17.72 -
   17.73 -      /// Default constructor.
   17.74 -
   17.75 -      /**
   17.76 -       * Default constructor for MapBase.
   17.77 -       */
   17.78 -
   17.79 -      MapBase() : graph(0), registry(0) {}
   17.80 -
   17.81 -      /// Constructor to register map into a graph registry.
   17.82 -		
   17.83 -      /** 
   17.84 -       * Simple constructor to register dynamic map into a graph registry.
   17.85 -      */
   17.86 -	
   17.87 -      MapBase(const Graph& g, Registry& r) : graph(&g), registry(0) {
   17.88 -	r.attach(*this);
   17.89 -      }
   17.90 -
   17.91 -      /// Copy constructor.
   17.92 -
   17.93 -      /** 
   17.94 -       * Copy constructor to register into the registry.
   17.95 -       * If the copiable map is registered into a registry
   17.96 -       * the construated map will be registered to the same registry.
   17.97 -      */	
   17.98 -	
   17.99 -      MapBase(const MapBase& copy) : graph(copy.graph), registry(0) {
  17.100 -	if (copy.registry) {
  17.101 -	  copy.registry->attach(*this);
  17.102 -	}
  17.103 -      } 
  17.104 -
  17.105 -      /// Assign operator.
  17.106 -	
  17.107 -      /** 
  17.108 -       * Assign operator. This member detach first the map
  17.109 -       * from the current registry and then it attach to the
  17.110 -       * copiable map's registry if it exists.
  17.111 -      */	
  17.112 -      const MapBase& operator=(const MapBase& copy) {
  17.113 -	if (registry) {
  17.114 -	  registry->detach(*this);
  17.115 -	}
  17.116 -	graph = copy.graph;
  17.117 -	if (copy.registry) {
  17.118 -	  copy.registry->attach(*this);
  17.119 -	}
  17.120 -	return *this;
  17.121 -      }
  17.122 -	
  17.123 -      /// Destructor
  17.124 -
  17.125 -      /** 
  17.126 -       * This member detach the map from the its registry if the
  17.127 -       * registry exists.
  17.128 -      */		
  17.129 -
  17.130 -      virtual ~MapBase() {
  17.131 -	if (registry) {
  17.132 -	  registry->detach(*this);
  17.133 -	}
  17.134 -      }
  17.135 -
  17.136 -      /// The graph of the map.
  17.137 -
  17.138 -      /*
  17.139 -       * Returns the graph that the map belongs to.
  17.140 -      */
  17.141 -
  17.142 -      const Graph* getGraph() const { return graph; }
  17.143 -	
  17.144 -    protected:
  17.145 -		
  17.146 -      const Graph* graph;     
  17.147 -      Registry* registry;
  17.148 -
  17.149 -      int registry_index;
  17.150 -
  17.151 -    protected:
  17.152 -
  17.153 -      /// Helper function to implement constructors in the subclasses.
  17.154 -	
  17.155 -      /**
  17.156 -       * Helper function to implement constructors in the subclasses.
  17.157 -       * It adds all of the nodes or edges to the map via the 
  17.158 -       * \ref MapRegistry::MapBase::add add
  17.159 -       * member function.
  17.160 -      */
  17.161 -	
  17.162 -      virtual void init() {
  17.163 -	for (KeyIt it(*graph); it != INVALID; ++it) {
  17.164 -	  add(it);
  17.165 -	}
  17.166 -      }
  17.167 -	
  17.168 -
  17.169 -      /// Helper function to implement destructors in the subclasses.
  17.170 -	
  17.171 -      /**
  17.172 -       * Helper function to implement destructors in the subclasses.
  17.173 -       * It erases all of the nodes or edges of the map via the 
  17.174 -       * \ref MapRegistry::MapBase::erase erase
  17.175 -       * member function. It can be used by the clear function also.
  17.176 -      */
  17.177 -	
  17.178 -      virtual void destroy() {
  17.179 -	for (KeyIt it(*getGraph()); it != INVALID; ++it) {
  17.180 -	  erase(it);
  17.181 -	}
  17.182 -      }
  17.183 -
  17.184 -      /// The member function to add new node or edge to the map.
  17.185 -	
  17.186 -      /** 
  17.187 -	  The add member function should be overloaded in the subclasses.
  17.188 -	  \e Add extends the map with the new node or edge.
  17.189 -      */
  17.190 -	
  17.191 -      virtual void add(const KeyType&) = 0;	
  17.192 -
  17.193 -
  17.194 -      /// The member function to erase a node or edge from the map.
  17.195 -
  17.196 -      /** 
  17.197 -	  The erase member function should be overloaded in the subclasses.
  17.198 -	  \e Erase removes the node or edge from the map.
  17.199 -      */
  17.200 -	
  17.201 -      virtual void erase(const KeyType&) = 0;
  17.202 -
  17.203 -      /**
  17.204 -       *  The clear member function should be overloaded in the subclasses.
  17.205 -       *  \e Clear makes empty the data structure.
  17.206 -       */
  17.207 -
  17.208 -      virtual void clear() = 0;
  17.209 -
  17.210 -      /// Exception class to throw at unsupported operation.
  17.211 -	
  17.212 -      /**
  17.213 -       * Exception class to throw at unsupported operation.
  17.214 -       * If the map does not support erasing or adding new
  17.215 -       * node or key it must be throwed.
  17.216 -      */
  17.217 -	
  17.218 -      class NotSupportedOperationException {};
  17.219 -
  17.220 -    };
  17.221 -	
  17.222 -  protected:
  17.223 -	
  17.224 -
  17.225 -    typedef std::vector<MapBase*> Container; 
  17.226 -
  17.227 -    Container container;
  17.228 -
  17.229 -		
  17.230 -  public:
  17.231 -
  17.232 -    /// Default constructor.
  17.233 -	
  17.234 -    /**
  17.235 -     * Default constructor of the \e MapRegistry. 
  17.236 -     * It creates an empty registry.
  17.237 -     */
  17.238 -    MapRegistry() {}
  17.239 -
  17.240 -    /// Copy Constructor of the MapRegistry. 
  17.241 -	
  17.242 -    /**
  17.243 -     * Copy constructor of the \e MapRegistry. 
  17.244 -     * The new registry does not steal
  17.245 -     * the maps from the copiable registry. 
  17.246 -     * The new registry will be empty.
  17.247 -     */
  17.248 -    MapRegistry(const MapRegistry&) {}
  17.249 -
  17.250 -    /// Assign operator.
  17.251 -		
  17.252 -    /**
  17.253 -     * Assign operator. This registry does not steal the maps 
  17.254 -     * from the copiable registry. This registry will be an empty registry.
  17.255 -     * This operator will be called when a graph is assigned.
  17.256 -     */
  17.257 -    MapRegistry& operator=(const MapRegistry&) {
  17.258 -      typename Container::iterator it;
  17.259 -      for (it = container.begin(); it != container.end(); ++it) {
  17.260 -	(*it)->clear();
  17.261 -	(*it)->graph = 0;
  17.262 -	(*it)->registry = 0;
  17.263 -      }
  17.264 -    }
  17.265 -
  17.266 -    /// Destructor.
  17.267 -				
  17.268 -    /**
  17.269 -     * Destructor of the MapRegistry. It makes empty the attached map
  17.270 -     * first then detachs them.
  17.271 -     */
  17.272 -    ~MapRegistry() {
  17.273 -      typename Container::iterator it;
  17.274 -      for (it = container.begin(); it != container.end(); ++it) {
  17.275 -	(*it)->clear();
  17.276 -	(*it)->registry = 0;
  17.277 -	(*it)->graph = 0;
  17.278 -      }
  17.279 -    }
  17.280 -	
  17.281 -	
  17.282 -    public:
  17.283 -
  17.284 -    /// Attachs a map to the \e MapRegistry.
  17.285 -	
  17.286 -    /**
  17.287 -     * Attachs a map into thr registry. If the map has been attached
  17.288 -     * into an other registry it is detached from that automaticly.
  17.289 -     */
  17.290 -    void attach(MapBase& map) {
  17.291 -      if (map.registry) {
  17.292 -	map.registry->detach(map);
  17.293 -      }
  17.294 -      container.push_back(&map);
  17.295 -      map.registry = this;
  17.296 -      map.registry_index = container.size()-1;
  17.297 -    } 
  17.298 -
  17.299 -    /// Detachs a map from the \e MapRegistry.
  17.300 -	
  17.301 -    /**
  17.302 -     * Detachs a map from the \e MapRegistry.
  17.303 -     */
  17.304 -    void detach(MapBase& map) {
  17.305 -      container.back()->registry_index = map.registry_index; 
  17.306 -      container[map.registry_index] = container.back();
  17.307 -      container.pop_back();
  17.308 -      map.registry = 0;
  17.309 -      map.graph = 0;
  17.310 -    }
  17.311 -	
  17.312 -    /// Notify all the registered maps about a Key added.
  17.313 -		
  17.314 -    /**
  17.315 -     * Notify all the registered maps about a Key added.
  17.316 -     * This member should be called whenever a node or edge
  17.317 -     * is added to the graph.
  17.318 -     */
  17.319 -    void add(const KeyType& key) {
  17.320 -      typename Container::iterator it;
  17.321 -      for (it = container.begin(); it != container.end(); ++it) {
  17.322 -	(*it)->add(key);
  17.323 -      }
  17.324 -    }	
  17.325 -
  17.326 -    /// Notify all the registered maps about a Key erased.
  17.327 -		
  17.328 -    /**
  17.329 -     * Notify all the registered maps about a Key erased.
  17.330 -     * This member should be called whenever a node or edge
  17.331 -     * is erased from the graph.
  17.332 -     */ 
  17.333 -    void erase(const KeyType& key) {
  17.334 -      typename Container::iterator it;
  17.335 -      for (it = container.begin(); it != container.end(); ++it) {
  17.336 -	(*it)->erase(key);
  17.337 -      }
  17.338 -    }
  17.339 -
  17.340 -
  17.341 -    /// Notify all the registered maps about all the Keys are erased.
  17.342 -
  17.343 -    /**
  17.344 -     * Notify all the registered maps about the map should be cleared.
  17.345 -     * This member should be called whenever all of the nodes or edges
  17.346 -     * are erased from the graph.
  17.347 -     */ 
  17.348 -    void clear() {
  17.349 -      typename Container::iterator it;
  17.350 -      for (it = container.begin(); it != container.end(); ++it) {
  17.351 -	(*it)->clear();
  17.352 -      }
  17.353 -    }
  17.354 -  };
  17.355 -
  17.356 -  
  17.357 -/// @}
  17.358 -  
  17.359 -
  17.360 -}
  17.361 -
  17.362 -#endif
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/lemon/mappable_graph_extender.h	Wed Oct 27 22:38:50 2004 +0000
    18.3 @@ -0,0 +1,97 @@
    18.4 +// -*- c++ -*-
    18.5 +
    18.6 +#ifndef LEMON_MAPPABLE_GRAPH_EXTENDER_H
    18.7 +#define LEMON_MAPPABLE_GRAPH_EXTENDER_H
    18.8 +
    18.9 +namespace lemon {
   18.10 +
   18.11 +  template <typename Base, template <class,class,class,class,class,class> class DynMap> 
   18.12 +  class MappableGraphExtender : public Base {
   18.13 +  public:
   18.14 +
   18.15 +    typedef MappableGraphExtender Graph;
   18.16 +    typedef Base Parent;
   18.17 +
   18.18 +    typedef typename Parent::Node Node;
   18.19 +    typedef typename Parent::NodeIt NodeIt;
   18.20 +    typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
   18.21 +
   18.22 +    typedef typename Parent::Edge Edge;
   18.23 +    typedef typename Parent::EdgeIt EdgeIt;
   18.24 +    typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
   18.25 +
   18.26 +  public:
   18.27 +
   18.28 +    class NodeIdMap {
   18.29 +    private:
   18.30 +      const Graph* graph;
   18.31 +
   18.32 +    public:
   18.33 +      NodeIdMap(const Graph& g) : graph(&g) {}
   18.34 +
   18.35 +      int operator[](const Node& node) { return graph->id(node); }
   18.36 +
   18.37 +      int maxId() const {return graph->maxNodeId(); }
   18.38 +
   18.39 +    };
   18.40 +
   18.41 +    //    template <typename Value>
   18.42 +    //    friend class DynMap<NodeObserverRegistry, Graph, Node, NodeIt,
   18.43 +    //		NodeIdMap, Value>;
   18.44 +
   18.45 +    class EdgeIdMap {
   18.46 +    private:
   18.47 +      const Graph* graph;
   18.48 +
   18.49 +    public:
   18.50 +      EdgeIdMap(const Graph& g) : graph(&g) {}
   18.51 +
   18.52 +      int operator[](const Edge& edge) const { return graph->id(edge); }
   18.53 +
   18.54 +      int maxId() const {return graph->maxEdgeId(); }
   18.55 +
   18.56 +    };
   18.57 +
   18.58 +    //    template <typename Value>
   18.59 +    //    friend class DynMap<EdgeObserverRegistry, Graph, Edge, EdgeIt,
   18.60 +    //		EdgeIdMap, Value>;
   18.61 +
   18.62 +  public:
   18.63 +    
   18.64 +    template <typename Value>
   18.65 +    class NodeMap 
   18.66 +      : public DynMap<NodeObserverRegistry, Graph, Node, NodeIt,
   18.67 +		      NodeIdMap, Value> {
   18.68 +    public:
   18.69 +      typedef DynMap<NodeObserverRegistry, Graph, Node, NodeIt,
   18.70 +		     NodeIdMap, Value> Parent;
   18.71 +
   18.72 +      NodeMap(const Graph& g) 
   18.73 +	: Parent(g, g.Graph::Parent::getNodeObserverRegistry()) {}
   18.74 +      NodeMap(const Graph& g, const Value& v) 
   18.75 +	: Parent(g, g.Graph::Parent::getNodeObserverRegistry(), v) {}
   18.76 +
   18.77 +    };
   18.78 +
   18.79 +    template <typename Value>
   18.80 +    class EdgeMap 
   18.81 +      : public DynMap<EdgeObserverRegistry, Graph, Edge, EdgeIt,
   18.82 +		      EdgeIdMap, Value> {
   18.83 +    public:
   18.84 +      typedef DynMap<EdgeObserverRegistry, Graph, Edge, EdgeIt,
   18.85 +		     EdgeIdMap, Value> Parent;
   18.86 +
   18.87 +      EdgeMap(const Graph& g) 
   18.88 +	: Parent(g, g.Graph::Parent::getEdgeObserverRegistry()) {}
   18.89 +      EdgeMap(const Graph& g, const Value& v) 
   18.90 +	: Parent(g, g.Graph::Parent::getEdgeObserverRegistry(), v) {}
   18.91 +
   18.92 +    };
   18.93 +
   18.94 +    
   18.95 +  };
   18.96 +
   18.97 +}
   18.98 +
   18.99 +#endif
  18.100 +
    19.1 --- a/src/lemon/preflow.h	Mon Oct 25 13:29:46 2004 +0000
    19.2 +++ b/src/lemon/preflow.h	Wed Oct 27 22:38:50 2004 +0000
    19.3 @@ -140,7 +140,7 @@
    19.4        Preflow(const Graph& _G, Node _s, Node _t, 
    19.5  	      const CapMap& _capacity, FlowMap& _flow) :
    19.6  	g(&_G), s(_s), t(_t), capacity(&_capacity),
    19.7 -	flow(&_flow), n(_G.nodeNum()), level(_G), excess(_G,0), 
    19.8 +	flow(&_flow), n(countNodes(_G)), level(_G), excess(_G,0), 
    19.9  	flow_prop(NO_FLOW), status(AFTER_NOTHING) { }
   19.10  
   19.11  
    20.1 --- a/src/lemon/skeletons/graph.h	Mon Oct 25 13:29:46 2004 +0000
    20.2 +++ b/src/lemon/skeletons/graph.h	Wed Oct 27 22:38:50 2004 +0000
    20.3 @@ -23,6 +23,8 @@
    20.4  
    20.5  #include <lemon/invalid.h>
    20.6  #include <lemon/skeletons/maps.h>
    20.7 +#include <lemon/concept_check.h>
    20.8 +#include <lemon/skeletons/graph_component.h>
    20.9  
   20.10  namespace lemon {
   20.11    namespace skeleton {
   20.12 @@ -30,734 +32,883 @@
   20.13      /// \addtogroup skeletons
   20.14      /// @{
   20.15  
   20.16 -    /// An empty static graph class.
   20.17 +//     /// An empty static graph class.
   20.18    
   20.19 -    /// This class provides all the common features of a graph structure,
   20.20 -    /// however completely without implementations and real data structures
   20.21 -    /// behind the interface.
   20.22 -    /// All graph algorithms should compile with this class, but it will not
   20.23 -    /// run properly, of course.
   20.24 -    ///
   20.25 -    /// It can be used for checking the interface compatibility,
   20.26 -    /// or it can serve as a skeleton of a new graph structure.
   20.27 -    /// 
   20.28 -    /// Also, you will find here the full documentation of a certain graph
   20.29 -    /// feature, the documentation of a real graph imlementation
   20.30 -    /// like @ref ListGraph or
   20.31 -    /// @ref SmartGraph will just refer to this structure.
   20.32 -    ///
   20.33 -    /// \todo A pages describing the concept of concept description would
   20.34 -    /// be nice.
   20.35 -    class StaticGraph
   20.36 -    {
   20.37 +//     /// This class provides all the common features of a graph structure,
   20.38 +//     /// however completely without implementations and real data structures
   20.39 +//     /// behind the interface.
   20.40 +//     /// All graph algorithms should compile with this class, but it will not
   20.41 +//     /// run properly, of course.
   20.42 +//     ///
   20.43 +//     /// It can be used for checking the interface compatibility,
   20.44 +//     /// or it can serve as a skeleton of a new graph structure.
   20.45 +//     /// 
   20.46 +//     /// Also, you will find here the full documentation of a certain graph
   20.47 +//     /// feature, the documentation of a real graph imlementation
   20.48 +//     /// like @ref ListGraph or
   20.49 +//     /// @ref SmartGraph will just refer to this structure.
   20.50 +//     ///
   20.51 +//     /// \todo A pages describing the concept of concept description would
   20.52 +//     /// be nice.
   20.53 +//     class StaticGraph
   20.54 +//     {
   20.55 +//     public:
   20.56 +//       /// Defalult constructor.
   20.57 +
   20.58 +//       /// Defalult constructor.
   20.59 +//       ///
   20.60 +//       StaticGraph() { }
   20.61 +//       ///Copy consructor.
   20.62 +
   20.63 +// //       ///\todo It is not clear, what we expect from a copy constructor.
   20.64 +// //       ///E.g. How to assign the nodes/edges to each other? What about maps?
   20.65 +// //       StaticGraph(const StaticGraph& g) { }
   20.66 +
   20.67 +//       /// The base type of node iterators, 
   20.68 +//       /// or in other words, the trivial node iterator.
   20.69 +
   20.70 +//       /// This is the base type of each node iterator,
   20.71 +//       /// thus each kind of node iterator converts to this.
   20.72 +//       /// More precisely each kind of node iterator should be inherited 
   20.73 +//       /// from the trivial node iterator.
   20.74 +//       class Node {
   20.75 +//       public:
   20.76 +// 	/// Default constructor
   20.77 +
   20.78 +// 	/// @warning The default constructor sets the iterator
   20.79 +// 	/// to an undefined value.
   20.80 +// 	Node() { }
   20.81 +// 	/// Copy constructor.
   20.82 +
   20.83 +// 	/// Copy constructor.
   20.84 +// 	///
   20.85 +// 	Node(const Node&) { }
   20.86 +
   20.87 +// 	/// Invalid constructor \& conversion.
   20.88 +
   20.89 +// 	/// This constructor initializes the iterator to be invalid.
   20.90 +// 	/// \sa Invalid for more details.
   20.91 +// 	Node(Invalid) { }
   20.92 +// 	/// Equality operator
   20.93 +
   20.94 +// 	/// Two iterators are equal if and only if they point to the
   20.95 +// 	/// same object or both are invalid.
   20.96 +// 	bool operator==(Node) const { return true; }
   20.97 +
   20.98 +// 	/// Inequality operator
   20.99 +	
  20.100 +// 	/// \sa operator==(Node n)
  20.101 +// 	///
  20.102 +// 	bool operator!=(Node) const { return true; }
  20.103 +
  20.104 +//  	///Comparison operator.
  20.105 +
  20.106 +// 	///This is a strict ordering between the nodes.
  20.107 +// 	///
  20.108 +// 	///This ordering can be different from the order in which NodeIt
  20.109 +// 	///goes through the nodes.
  20.110 +// 	///\todo Possibly we don't need it.
  20.111 +// 	bool operator<(Node) const { return true; }
  20.112 +//       };
  20.113 +    
  20.114 +//       /// This iterator goes through each node.
  20.115 +
  20.116 +//       /// This iterator goes through each node.
  20.117 +//       /// Its usage is quite simple, for example you can count the number
  20.118 +//       /// of nodes in graph \c g of type \c Graph like this:
  20.119 +//       /// \code
  20.120 +//       /// int count=0;
  20.121 +//       /// for (Graph::NodeIt n(g); n!=INVALID ++n) ++count;
  20.122 +//       /// \endcode
  20.123 +//       class NodeIt : public Node {
  20.124 +//       public:
  20.125 +// 	/// Default constructor
  20.126 +
  20.127 +// 	/// @warning The default constructor sets the iterator
  20.128 +// 	/// to an undefined value.
  20.129 +// 	NodeIt() { }
  20.130 +// 	/// Copy constructor.
  20.131 +	
  20.132 +// 	/// Copy constructor.
  20.133 +// 	///
  20.134 +// 	NodeIt(const NodeIt&) { }
  20.135 +// 	/// Invalid constructor \& conversion.
  20.136 +
  20.137 +// 	/// Initialize the iterator to be invalid.
  20.138 +// 	/// \sa Invalid for more details.
  20.139 +// 	NodeIt(Invalid) { }
  20.140 +// 	/// Sets the iterator to the first node.
  20.141 +
  20.142 +// 	/// Sets the iterator to the first node of \c g.
  20.143 +// 	///
  20.144 +// 	NodeIt(const StaticGraph& g) { }
  20.145 +// 	/// Node -> NodeIt conversion.
  20.146 +
  20.147 +// 	/// Sets the iterator to the node of \c g pointed by the trivial 
  20.148 +// 	/// iterator n.
  20.149 +// 	/// This feature necessitates that each time we 
  20.150 +// 	/// iterate the edge-set, the iteration order is the same.
  20.151 +// 	NodeIt(const StaticGraph& g, const Node& n) { }
  20.152 +// 	/// Next node.
  20.153 +
  20.154 +// 	/// Assign the iterator to the next node.
  20.155 +// 	///
  20.156 +// 	NodeIt& operator++() { return *this; }
  20.157 +//       };
  20.158 +    
  20.159 +    
  20.160 +//       /// The base type of the edge iterators.
  20.161 +
  20.162 +//       /// The base type of the edge iterators.
  20.163 +//       ///
  20.164 +//       class Edge {
  20.165 +//       public:
  20.166 +// 	/// Default constructor
  20.167 +
  20.168 +// 	/// @warning The default constructor sets the iterator
  20.169 +// 	/// to an undefined value.
  20.170 +// 	Edge() { }
  20.171 +// 	/// Copy constructor.
  20.172 +
  20.173 +// 	/// Copy constructor.
  20.174 +// 	///
  20.175 +// 	Edge(const Edge&) { }
  20.176 +// 	/// Initialize the iterator to be invalid.
  20.177 +
  20.178 +// 	/// Initialize the iterator to be invalid.
  20.179 +// 	///
  20.180 +// 	Edge(Invalid) { }
  20.181 +// 	/// Equality operator
  20.182 +
  20.183 +// 	/// Two iterators are equal if and only if they point to the
  20.184 +// 	/// same object or both are invalid.
  20.185 +// 	bool operator==(Edge) const { return true; }
  20.186 +// 	/// Inequality operator
  20.187 +
  20.188 +// 	/// \sa operator==(Node n)
  20.189 +// 	///
  20.190 +// 	bool operator!=(Edge) const { return true; }
  20.191 +//  	///Comparison operator.
  20.192 +
  20.193 +// 	///This is a strict ordering between the nodes.
  20.194 +// 	///
  20.195 +// 	///This ordering can be different from the order in which NodeIt
  20.196 +// 	///goes through the nodes.
  20.197 +// 	///\todo Possibly we don't need it.
  20.198 +//  	bool operator<(Edge) const { return true; }
  20.199 +//       };
  20.200 +    
  20.201 +//       /// This iterator goes trough the outgoing edges of a node.
  20.202 +
  20.203 +//       /// This iterator goes trough the \e outgoing edges of a certain node
  20.204 +//       /// of a graph.
  20.205 +//       /// Its usage is quite simple, for example you can count the number
  20.206 +//       /// of outgoing edges of a node \c n
  20.207 +//       /// in graph \c g of type \c Graph as follows.
  20.208 +//       /// \code
  20.209 +//       /// int count=0;
  20.210 +//       /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
  20.211 +//       /// \endcode
  20.212 +    
  20.213 +//       class OutEdgeIt : public Edge {
  20.214 +//       public:
  20.215 +// 	/// Default constructor
  20.216 +
  20.217 +// 	/// @warning The default constructor sets the iterator
  20.218 +// 	/// to an undefined value.
  20.219 +// 	OutEdgeIt() { }
  20.220 +// 	/// Copy constructor.
  20.221 +
  20.222 +// 	/// Copy constructor.
  20.223 +// 	///
  20.224 +// 	OutEdgeIt(const OutEdgeIt&) { }
  20.225 +// 	/// Initialize the iterator to be invalid.
  20.226 +
  20.227 +// 	/// Initialize the iterator to be invalid.
  20.228 +// 	///
  20.229 +// 	OutEdgeIt(Invalid) { }
  20.230 +// 	/// This constructor sets the iterator to first outgoing edge.
  20.231 +    
  20.232 +// 	/// This constructor set the iterator to the first outgoing edge of
  20.233 +// 	/// node
  20.234 +// 	///@param n the node
  20.235 +// 	///@param g the graph
  20.236 +// 	OutEdgeIt(const StaticGraph& g, const Node& n) { }
  20.237 +// 	/// Edge -> OutEdgeIt conversion
  20.238 +
  20.239 +// 	/// Sets the iterator to the value of the trivial iterator \c e.
  20.240 +// 	/// This feature necessitates that each time we 
  20.241 +// 	/// iterate the edge-set, the iteration order is the same.
  20.242 +// 	OutEdgeIt(const StaticGraph& g, const Edge& e) { }
  20.243 +// 	///Next outgoing edge
  20.244 +	
  20.245 +// 	/// Assign the iterator to the next 
  20.246 +// 	/// outgoing edge of the corresponding node.
  20.247 +// 	OutEdgeIt& operator++() { return *this; }
  20.248 +//       };
  20.249 +
  20.250 +//       /// This iterator goes trough the incoming edges of a node.
  20.251 +
  20.252 +//       /// This iterator goes trough the \e incoming edges of a certain node
  20.253 +//       /// of a graph.
  20.254 +//       /// Its usage is quite simple, for example you can count the number
  20.255 +//       /// of outgoing edges of a node \c n
  20.256 +//       /// in graph \c g of type \c Graph as follows.
  20.257 +//       /// \code
  20.258 +//       /// int count=0;
  20.259 +//       /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
  20.260 +//       /// \endcode
  20.261 +
  20.262 +//       class InEdgeIt : public Edge {
  20.263 +//       public:
  20.264 +// 	/// Default constructor
  20.265 +
  20.266 +// 	/// @warning The default constructor sets the iterator
  20.267 +// 	/// to an undefined value.
  20.268 +// 	InEdgeIt() { }
  20.269 +// 	/// Copy constructor.
  20.270 +
  20.271 +// 	/// Copy constructor.
  20.272 +// 	///
  20.273 +// 	InEdgeIt(const InEdgeIt&) { }
  20.274 +// 	/// Initialize the iterator to be invalid.
  20.275 +
  20.276 +// 	/// Initialize the iterator to be invalid.
  20.277 +// 	///
  20.278 +// 	InEdgeIt(Invalid) { }
  20.279 +// 	/// This constructor sets the iterator to first incoming edge.
  20.280 +    
  20.281 +// 	/// This constructor set the iterator to the first incoming edge of
  20.282 +// 	/// node
  20.283 +// 	///@param n the node
  20.284 +// 	///@param g the graph
  20.285 +// 	InEdgeIt(const StaticGraph& g, const Node& n) { }
  20.286 +// 	/// Edge -> InEdgeIt conversion
  20.287 +
  20.288 +// 	/// Sets the iterator to the value of the trivial iterator \c e.
  20.289 +// 	/// This feature necessitates that each time we 
  20.290 +// 	/// iterate the edge-set, the iteration order is the same.
  20.291 +// 	InEdgeIt(const StaticGraph& g, const Edge& n) { }
  20.292 +// 	/// Next incoming edge
  20.293 +
  20.294 +// 	/// Assign the iterator to the next inedge of the corresponding node.
  20.295 +// 	///
  20.296 +// 	InEdgeIt& operator++() { return *this; }
  20.297 +//       };
  20.298 +//       /// This iterator goes through each edge.
  20.299 +
  20.300 +//       /// This iterator goes through each edge of a graph.
  20.301 +//       /// Its usage is quite simple, for example you can count the number
  20.302 +//       /// of edges in a graph \c g of type \c Graph as follows:
  20.303 +//       /// \code
  20.304 +//       /// int count=0;
  20.305 +//       /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
  20.306 +//       /// \endcode
  20.307 +//       class EdgeIt : public Edge {
  20.308 +//       public:
  20.309 +// 	/// Default constructor
  20.310 +
  20.311 +// 	/// @warning The default constructor sets the iterator
  20.312 +// 	/// to an undefined value.
  20.313 +// 	EdgeIt() { }
  20.314 +// 	/// Copy constructor.
  20.315 +
  20.316 +// 	/// Copy constructor.
  20.317 +// 	///
  20.318 +// 	EdgeIt(const EdgeIt&) { }
  20.319 +// 	/// Initialize the iterator to be invalid.
  20.320 +
  20.321 +// 	/// Initialize the iterator to be invalid.
  20.322 +// 	///
  20.323 +// 	EdgeIt(Invalid) { }
  20.324 +// 	/// This constructor sets the iterator to first edge.
  20.325 +    
  20.326 +// 	/// This constructor set the iterator to the first edge of
  20.327 +// 	/// node
  20.328 +// 	///@param g the graph
  20.329 +// 	EdgeIt(const StaticGraph& g) { }
  20.330 +// 	/// Edge -> EdgeIt conversion
  20.331 +
  20.332 +// 	/// Sets the iterator to the value of the trivial iterator \c e.
  20.333 +// 	/// This feature necessitates that each time we 
  20.334 +// 	/// iterate the edge-set, the iteration order is the same.
  20.335 +// 	EdgeIt(const StaticGraph&, const Edge&) { } 
  20.336 +//     	///Next edge
  20.337 +	
  20.338 +// 	/// Assign the iterator to the next 
  20.339 +// 	/// edge of the corresponding node.
  20.340 +// 	EdgeIt& operator++() { return *this; }
  20.341 +//       };
  20.342 +
  20.343 +//       /// First node of the graph.
  20.344 +
  20.345 +//       /// \retval i the first node.
  20.346 +//       /// \return the first node.
  20.347 +//       ///
  20.348 +//       NodeIt& first(NodeIt& i) const { return i; }
  20.349 +
  20.350 +//       /// The first incoming edge.
  20.351 +
  20.352 +//       /// The first incoming edge.
  20.353 +//       ///
  20.354 +//       InEdgeIt& first(InEdgeIt &i, Node) const { return i; }
  20.355 +//       /// The first outgoing edge.
  20.356 +
  20.357 +//       /// The first outgoing edge.
  20.358 +//       ///
  20.359 +//       OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; }
  20.360 +//       /// The first edge of the Graph.
  20.361 +
  20.362 +//       /// The first edge of the Graph.
  20.363 +//       ///
  20.364 +//       EdgeIt& first(EdgeIt& i) const { return i; }
  20.365 +
  20.366 +//       ///Gives back the head node of an edge.
  20.367 +
  20.368 +//       ///Gives back the head node of an edge.
  20.369 +//       ///
  20.370 +//       Node head(Edge) const { return INVALID; }
  20.371 +//       ///Gives back the tail node of an edge.
  20.372 +
  20.373 +//       ///Gives back the tail node of an edge.
  20.374 +//       ///
  20.375 +//       Node tail(Edge) const { return INVALID; }
  20.376 +  
  20.377 +//       ///Gives back the \e id of a node.
  20.378 +
  20.379 +//       ///\warning Not all graph structures provide this feature.
  20.380 +//       ///
  20.381 +//       ///\todo Should each graph provide \c id?
  20.382 +//       int id(const Node&) const { return 0; }
  20.383 +//       ///Gives back the \e id of an edge.
  20.384 +
  20.385 +//       ///\warning Not all graph structures provide this feature.
  20.386 +//       ///
  20.387 +//       ///\todo Should each graph provide \c id?
  20.388 +//       int id(const Edge&) const { return 0; }
  20.389 +
  20.390 +//       ///\e
  20.391 +      
  20.392 +//       ///\todo Should it be in the concept?
  20.393 +//       ///
  20.394 +//       int nodeNum() const { return 0; }
  20.395 +//       ///\e
  20.396 +
  20.397 +//       ///\todo Should it be in the concept?
  20.398 +//       ///
  20.399 +//       int edgeNum() const { return 0; }
  20.400 +
  20.401 +
  20.402 +//       ///Reference map of the nodes to type \c T.
  20.403 +
  20.404 +//       /// \ingroup skeletons
  20.405 +//       ///Reference map of the nodes to type \c T.
  20.406 +//       /// \sa Reference
  20.407 +//       /// \warning Making maps that can handle bool type (NodeMap<bool>)
  20.408 +//       /// needs some extra attention!
  20.409 +//       template<class T> class NodeMap : public ReferenceMap< Node, T >
  20.410 +//       {
  20.411 +//       public:
  20.412 +
  20.413 +// 	///\e
  20.414 +// 	NodeMap(const StaticGraph&) { }
  20.415 +// 	///\e
  20.416 +// 	NodeMap(const StaticGraph&, T) { }
  20.417 +
  20.418 +// 	///Copy constructor
  20.419 +// 	template<typename TT> NodeMap(const NodeMap<TT>&) { }
  20.420 +// 	///Assignment operator
  20.421 +// 	template<typename TT> NodeMap& operator=(const NodeMap<TT>&)
  20.422 +// 	{ return *this; }
  20.423 +//       };
  20.424 +
  20.425 +//       ///Reference map of the edges to type \c T.
  20.426 +
  20.427 +//       /// \ingroup skeletons
  20.428 +//       ///Reference map of the edges to type \c T.
  20.429 +//       /// \sa Reference
  20.430 +//       /// \warning Making maps that can handle bool type (EdgeMap<bool>)
  20.431 +//       /// needs some extra attention!
  20.432 +//       template<class T> class EdgeMap
  20.433 +// 	: public ReferenceMap<Edge,T>
  20.434 +//       {
  20.435 +//       public:
  20.436 +
  20.437 +// 	///\e
  20.438 +// 	EdgeMap(const StaticGraph&) { }
  20.439 +// 	///\e
  20.440 +// 	EdgeMap(const StaticGraph&, T) { }
  20.441 +    
  20.442 +// 	///Copy constructor
  20.443 +// 	template<typename TT> EdgeMap(const EdgeMap<TT>&) { }
  20.444 +// 	///Assignment operator
  20.445 +// 	template<typename TT> EdgeMap &operator=(const EdgeMap<TT>&)
  20.446 +// 	{ return *this; }
  20.447 +//       };
  20.448 +//     };
  20.449 +
  20.450 +//     struct DummyType {
  20.451 +//       int value;
  20.452 +//       DummyType() {}
  20.453 +//       DummyType(int p) : value(p) {}
  20.454 +//       DummyType& operator=(int p) { value = p; return *this;}
  20.455 +//     };
  20.456 +    
  20.457 +//     ///\brief Checks whether \c G meets the
  20.458 +//     ///\ref lemon::skeleton::StaticGraph "StaticGraph" concept
  20.459 +//     template<class Graph> void checkCompileStaticGraph(Graph &G) 
  20.460 +//     {
  20.461 +//       typedef typename Graph::Node Node;
  20.462 +//       typedef typename Graph::NodeIt NodeIt;
  20.463 +//       typedef typename Graph::Edge Edge;
  20.464 +//       typedef typename Graph::EdgeIt EdgeIt;
  20.465 +//       typedef typename Graph::InEdgeIt InEdgeIt;
  20.466 +//       typedef typename Graph::OutEdgeIt OutEdgeIt;
  20.467 +  
  20.468 +//       {
  20.469 +// 	Node i; Node j(i); Node k(INVALID);
  20.470 +// 	i=j;
  20.471 +// 	bool b; b=true;
  20.472 +// 	b=(i==INVALID); b=(i!=INVALID);
  20.473 +// 	b=(i==j); b=(i!=j); b=(i<j);
  20.474 +//       }
  20.475 +//       {
  20.476 +// 	NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
  20.477 +// 	i=j;
  20.478 +// 	j=G.first(i);
  20.479 +// 	j=++i;
  20.480 +// 	bool b; b=true;
  20.481 +// 	b=(i==INVALID); b=(i!=INVALID);
  20.482 +// 	Node n(i);
  20.483 +// 	n=i;
  20.484 +// 	b=(i==j); b=(i!=j); b=(i<j);
  20.485 +// 	//Node ->NodeIt conversion
  20.486 +// 	NodeIt ni(G,n);
  20.487 +//       }
  20.488 +//       {
  20.489 +// 	Edge i; Edge j(i); Edge k(INVALID);
  20.490 +// 	i=j;
  20.491 +// 	bool b; b=true;
  20.492 +// 	b=(i==INVALID); b=(i!=INVALID);
  20.493 +// 	b=(i==j); b=(i!=j); b=(i<j);
  20.494 +//       }
  20.495 +//       {
  20.496 +// 	EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
  20.497 +// 	i=j;
  20.498 +// 	j=G.first(i);
  20.499 +// 	j=++i;
  20.500 +// 	bool b; b=true;
  20.501 +// 	b=(i==INVALID); b=(i!=INVALID);
  20.502 +// 	Edge e(i);
  20.503 +// 	e=i;
  20.504 +// 	b=(i==j); b=(i!=j); b=(i<j);
  20.505 +// 	//Edge ->EdgeIt conversion
  20.506 +// 	EdgeIt ei(G,e);
  20.507 +//       }
  20.508 +//       {
  20.509 +// 	Node n;
  20.510 +// 	InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
  20.511 +// 	i=j;
  20.512 +// 	j=G.first(i,n);
  20.513 +// 	j=++i;
  20.514 +// 	bool b; b=true;
  20.515 +// 	b=(i==INVALID); b=(i!=INVALID);
  20.516 +// 	Edge e(i);
  20.517 +// 	e=i;
  20.518 +// 	b=(i==j); b=(i!=j); b=(i<j);
  20.519 +// 	//Edge ->InEdgeIt conversion
  20.520 +// 	InEdgeIt ei(G,e);
  20.521 +//       }
  20.522 +//       {
  20.523 +// 	Node n;
  20.524 +// 	OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
  20.525 +// 	i=j;
  20.526 +// 	j=G.first(i,n);
  20.527 +// 	j=++i;
  20.528 +// 	bool b; b=true;
  20.529 +// 	b=(i==INVALID); b=(i!=INVALID);
  20.530 +// 	Edge e(i);
  20.531 +// 	e=i;
  20.532 +// 	b=(i==j); b=(i!=j); b=(i<j);
  20.533 +// 	//Edge ->OutEdgeIt conversion
  20.534 +// 	OutEdgeIt ei(G,e);
  20.535 +//       }
  20.536 +//       {
  20.537 +// 	Node n,m;
  20.538 +// 	n=m=INVALID;
  20.539 +// 	Edge e;
  20.540 +// 	e=INVALID;
  20.541 +// 	n=G.tail(e);
  20.542 +// 	n=G.head(e);
  20.543 +//       }
  20.544 +//       // id tests
  20.545 +//       { Node n; int i=G.id(n); i=i; }
  20.546 +//       { Edge e; int i=G.id(e); i=i; }
  20.547 +//       //NodeMap tests
  20.548 +//       {
  20.549 +// 	Node k;
  20.550 +// 	typename Graph::template NodeMap<int> m(G);
  20.551 +// 	//Const map
  20.552 +// 	typename Graph::template NodeMap<int> const &cm = m;
  20.553 +// 	//Inicialize with default value
  20.554 +// 	typename Graph::template NodeMap<int> mdef(G,12);
  20.555 +// 	//Copy
  20.556 +// 	typename Graph::template NodeMap<int> mm(cm);
  20.557 +// 	//Copy from another type
  20.558 +// 	typename Graph::template NodeMap<double> dm(cm);
  20.559 +// 	//Copy to more complex type
  20.560 +// 	typename Graph::template NodeMap<DummyType> em(cm);
  20.561 +// 	int v;
  20.562 +// 	v=m[k]; m[k]=v; m.set(k,v);
  20.563 +// 	v=cm[k];
  20.564 +    
  20.565 +// 	m=cm;  
  20.566 +// 	dm=cm; //Copy from another type  
  20.567 +// 	em=cm; //Copy to more complex type
  20.568 +// 	{
  20.569 +// 	  //Check the typedef's
  20.570 +// 	  typename Graph::template NodeMap<int>::ValueType val;
  20.571 +// 	  val=1;
  20.572 +// 	  typename Graph::template NodeMap<int>::KeyType key;
  20.573 +// 	  key = typename Graph::NodeIt(G);
  20.574 +// 	}
  20.575 +//       }  
  20.576 +//       { //bool NodeMap
  20.577 +// 	Node k;
  20.578 +// 	typename Graph::template NodeMap<bool> m(G);
  20.579 +// 	typename Graph::template NodeMap<bool> const &cm = m;  //Const map
  20.580 +// 	//Inicialize with default value
  20.581 +// 	typename Graph::template NodeMap<bool> mdef(G,12);
  20.582 +// 	typename Graph::template NodeMap<bool> mm(cm);   //Copy
  20.583 +// 	typename Graph::template NodeMap<int> dm(cm); //Copy from another type
  20.584 +// 	bool v;
  20.585 +// 	v=m[k]; m[k]=v; m.set(k,v);
  20.586 +// 	v=cm[k];
  20.587 +    
  20.588 +// 	m=cm;  
  20.589 +// 	dm=cm; //Copy from another type
  20.590 +// 	m=dm; //Copy to another type
  20.591 +
  20.592 +// 	{
  20.593 +// 	  //Check the typedef's
  20.594 +// 	  typename Graph::template NodeMap<bool>::ValueType val;
  20.595 +// 	  val=true;
  20.596 +// 	  typename Graph::template NodeMap<bool>::KeyType key;
  20.597 +// 	  key= typename Graph::NodeIt(G);
  20.598 +// 	}
  20.599 +//       }
  20.600 +//       //EdgeMap tests
  20.601 +//       {
  20.602 +// 	Edge k;
  20.603 +// 	typename Graph::template EdgeMap<int> m(G);
  20.604 +// 	typename Graph::template EdgeMap<int> const &cm = m;  //Const map
  20.605 +// 	//Inicialize with default value
  20.606 +// 	typename Graph::template EdgeMap<int> mdef(G,12);
  20.607 +// 	typename Graph::template EdgeMap<int> mm(cm);   //Copy
  20.608 +// 	typename Graph::template EdgeMap<double> dm(cm);//Copy from another type
  20.609 +// 	int v;
  20.610 +// 	v=m[k]; m[k]=v; m.set(k,v);
  20.611 +// 	v=cm[k];
  20.612 +    
  20.613 +// 	m=cm;  
  20.614 +// 	dm=cm; //Copy from another type
  20.615 +// 	{
  20.616 +// 	  //Check the typedef's
  20.617 +// 	  typename Graph::template EdgeMap<int>::ValueType val;
  20.618 +// 	  val=1;
  20.619 +// 	  typename Graph::template EdgeMap<int>::KeyType key;
  20.620 +// 	  key= typename Graph::EdgeIt(G);
  20.621 +// 	}
  20.622 +//       }  
  20.623 +//       { //bool EdgeMap
  20.624 +// 	Edge k;
  20.625 +// 	typename Graph::template EdgeMap<bool> m(G);
  20.626 +// 	typename Graph::template EdgeMap<bool> const &cm = m;  //Const map
  20.627 +// 	//Inicialize with default value
  20.628 +// 	typename Graph::template EdgeMap<bool> mdef(G,12);
  20.629 +// 	typename Graph::template EdgeMap<bool> mm(cm);   //Copy
  20.630 +// 	typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
  20.631 +// 	bool v;
  20.632 +// 	v=m[k]; m[k]=v; m.set(k,v);
  20.633 +// 	v=cm[k];
  20.634 +    
  20.635 +// 	m=cm;  
  20.636 +// 	dm=cm; //Copy from another type
  20.637 +// 	m=dm; //Copy to another type
  20.638 +// 	{
  20.639 +// 	  //Check the typedef's
  20.640 +// 	  typename Graph::template EdgeMap<bool>::ValueType val;
  20.641 +// 	  val=true;
  20.642 +// 	  typename Graph::template EdgeMap<bool>::KeyType key;
  20.643 +// 	  key= typename Graph::EdgeIt(G);
  20.644 +// 	}
  20.645 +//       }
  20.646 +//     }
  20.647 +    
  20.648 +//     /// An empty non-static graph class.
  20.649 +    
  20.650 +//     /// This class provides everything that \ref StaticGraph
  20.651 +//     /// with additional functionality which enables to build a
  20.652 +//     /// graph from scratch.
  20.653 +//     class ExtendableGraph : public StaticGraph
  20.654 +//     {
  20.655 +//     public:
  20.656 +//       /// Defalult constructor.
  20.657 +
  20.658 +//       /// Defalult constructor.
  20.659 +//       ///
  20.660 +//       ExtendableGraph() { }
  20.661 +//       ///Add a new node to the graph.
  20.662 +
  20.663 +//       /// \return the new node.
  20.664 +//       ///
  20.665 +//       Node addNode() { return INVALID; }
  20.666 +//       ///Add a new edge to the graph.
  20.667 +
  20.668 +//       ///Add a new edge to the graph with tail node \c t
  20.669 +//       ///and head node \c h.
  20.670 +//       ///\return the new edge.
  20.671 +//       Edge addEdge(Node h, Node t) { return INVALID; }
  20.672 +    
  20.673 +//       /// Resets the graph.
  20.674 +
  20.675 +//       /// This function deletes all edges and nodes of the graph.
  20.676 +//       /// It also frees the memory allocated to store them.
  20.677 +//       /// \todo It might belong to \ref ErasableGraph.
  20.678 +//       void clear() { }
  20.679 +//     };
  20.680 +
  20.681 +    
  20.682 +//     ///\brief Checks whether \c G meets the
  20.683 +//     ///\ref lemon::skeleton::ExtendableGraph "ExtendableGraph" concept
  20.684 +//     template<class Graph> void checkCompileExtendableGraph(Graph &G) 
  20.685 +//     {
  20.686 +//       checkCompileStaticGraph(G);
  20.687 +
  20.688 +//       typedef typename Graph::Node Node;
  20.689 +//       typedef typename Graph::NodeIt NodeIt;
  20.690 +//       typedef typename Graph::Edge Edge;
  20.691 +//       typedef typename Graph::EdgeIt EdgeIt;
  20.692 +//       typedef typename Graph::InEdgeIt InEdgeIt;
  20.693 +//       typedef typename Graph::OutEdgeIt OutEdgeIt;
  20.694 +  
  20.695 +//       Node n,m;
  20.696 +//       n=G.addNode();
  20.697 +//       m=G.addNode();
  20.698 +//       Edge e;
  20.699 +//       e=G.addEdge(n,m); 
  20.700 +  
  20.701 +//       //  G.clear();
  20.702 +//     }
  20.703 +
  20.704 +
  20.705 +//     /// An empty erasable graph class.
  20.706 +  
  20.707 +//     /// This class is an extension of \ref ExtendableGraph. It also makes it
  20.708 +//     /// possible to erase edges or nodes.
  20.709 +//     class ErasableGraph : public ExtendableGraph
  20.710 +//     {
  20.711 +//     public:
  20.712 +//       /// Defalult constructor.
  20.713 +
  20.714 +//       /// Defalult constructor.
  20.715 +//       ///
  20.716 +//       ErasableGraph() { }
  20.717 +//       /// Deletes a node.
  20.718 +
  20.719 +//       /// Deletes node \c n node.
  20.720 +//       ///
  20.721 +//       void erase(Node n) { }
  20.722 +//       /// Deletes an edge.
  20.723 +
  20.724 +//       /// Deletes edge \c e edge.
  20.725 +//       ///
  20.726 +//       void erase(Edge e) { }
  20.727 +//     };
  20.728 +    
  20.729 +//     template<class Graph> void checkCompileGraphEraseEdge(Graph &G) 
  20.730 +//     {
  20.731 +//       typename Graph::Edge e;
  20.732 +//       G.erase(e);
  20.733 +//     }
  20.734 +
  20.735 +//     template<class Graph> void checkCompileGraphEraseNode(Graph &G) 
  20.736 +//     {
  20.737 +//       typename Graph::Node n;
  20.738 +//       G.erase(n);
  20.739 +//     }
  20.740 +
  20.741 +//     ///\brief Checks whether \c G meets the
  20.742 +//     ///\ref lemon::skeleton::EresableGraph "EresableGraph" concept
  20.743 +//     template<class Graph> void checkCompileErasableGraph(Graph &G) 
  20.744 +//     {
  20.745 +//       checkCompileExtendableGraph(G);
  20.746 +//       checkCompileGraphEraseNode(G);
  20.747 +//       checkCompileGraphEraseEdge(G);
  20.748 +//     }
  20.749 +
  20.750 +//     ///Checks whether a graph has findEdge() member function.
  20.751 +    
  20.752 +//     ///\todo findEdge() might be a global function.
  20.753 +//     ///
  20.754 +//     template<class Graph> void checkCompileGraphFindEdge(Graph &G) 
  20.755 +//     {
  20.756 +//       typedef typename Graph::NodeIt Node;
  20.757 +//       typedef typename Graph::NodeIt NodeIt;
  20.758 +
  20.759 +//       G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
  20.760 +//       G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));  
  20.761 +//     }
  20.762 +
  20.763 +
  20.764 +
  20.765 +    /************* New GraphBase stuff **************/
  20.766 +
  20.767 +
  20.768 +    /// \bug The nodes and edges are not allowed to inherit from the
  20.769 +    /// same baseclass.
  20.770 +
  20.771 +    class BaseGraphItem {
  20.772      public:
  20.773 -      /// Defalult constructor.
  20.774 +      BaseGraphItem() {}
  20.775 +      BaseGraphItem(Invalid) {}
  20.776  
  20.777 -      /// Defalult constructor.
  20.778 -      ///
  20.779 -      StaticGraph() { }
  20.780 -      ///Copy consructor.
  20.781 +      // We explicitely list these:
  20.782 +      BaseGraphItem(BaseGraphItem const&) {}
  20.783 +      BaseGraphItem& operator=(BaseGraphItem const&) { return *this; }
  20.784  
  20.785 -//       ///\todo It is not clear, what we expect from a copy constructor.
  20.786 -//       ///E.g. How to assign the nodes/edges to each other? What about maps?
  20.787 -//       StaticGraph(const StaticGraph& g) { }
  20.788 +      bool operator==(BaseGraphItem) const { return false; }
  20.789 +      bool operator!=(BaseGraphItem) const { return false; }
  20.790  
  20.791 -      /// The base type of node iterators, 
  20.792 -      /// or in other words, the trivial node iterator.
  20.793 -
  20.794 -      /// This is the base type of each node iterator,
  20.795 -      /// thus each kind of node iterator converts to this.
  20.796 -      /// More precisely each kind of node iterator should be inherited 
  20.797 -      /// from the trivial node iterator.
  20.798 -      class Node {
  20.799 -      public:
  20.800 -	/// Default constructor
  20.801 -
  20.802 -	/// @warning The default constructor sets the iterator
  20.803 -	/// to an undefined value.
  20.804 -	Node() { }
  20.805 -	/// Copy constructor.
  20.806 -
  20.807 -	/// Copy constructor.
  20.808 -	///
  20.809 -	Node(const Node&) { }
  20.810 -
  20.811 -	/// Invalid constructor \& conversion.
  20.812 -
  20.813 -	/// This constructor initializes the iterator to be invalid.
  20.814 -	/// \sa Invalid for more details.
  20.815 -	Node(Invalid) { }
  20.816 -	/// Equality operator
  20.817 -
  20.818 -	/// Two iterators are equal if and only if they point to the
  20.819 -	/// same object or both are invalid.
  20.820 -	bool operator==(Node) const { return true; }
  20.821 -
  20.822 -	/// Inequality operator
  20.823 -	
  20.824 -	/// \sa operator==(Node n)
  20.825 -	///
  20.826 -	bool operator!=(Node) const { return true; }
  20.827 -
  20.828 - 	///Comparison operator.
  20.829 -
  20.830 -	///This is a strict ordering between the nodes.
  20.831 -	///
  20.832 -	///This ordering can be different from the order in which NodeIt
  20.833 -	///goes through the nodes.
  20.834 -	///\todo Possibly we don't need it.
  20.835 -	bool operator<(Node) const { return true; }
  20.836 -      };
  20.837 -    
  20.838 -      /// This iterator goes through each node.
  20.839 -
  20.840 -      /// This iterator goes through each node.
  20.841 -      /// Its usage is quite simple, for example you can count the number
  20.842 -      /// of nodes in graph \c g of type \c Graph like this:
  20.843 -      /// \code
  20.844 -      /// int count=0;
  20.845 -      /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
  20.846 -      /// \endcode
  20.847 -      class NodeIt : public Node {
  20.848 -      public:
  20.849 -	/// Default constructor
  20.850 -
  20.851 -	/// @warning The default constructor sets the iterator
  20.852 -	/// to an undefined value.
  20.853 -	NodeIt() { }
  20.854 -	/// Copy constructor.
  20.855 -	
  20.856 -	/// Copy constructor.
  20.857 -	///
  20.858 -	NodeIt(const NodeIt&) { }
  20.859 -	/// Invalid constructor \& conversion.
  20.860 -
  20.861 -	/// Initialize the iterator to be invalid.
  20.862 -	/// \sa Invalid for more details.
  20.863 -	NodeIt(Invalid) { }
  20.864 -	/// Sets the iterator to the first node.
  20.865 -
  20.866 -	/// Sets the iterator to the first node of \c g.
  20.867 -	///
  20.868 -	NodeIt(const StaticGraph& g) { }
  20.869 -	/// Node -> NodeIt conversion.
  20.870 -
  20.871 -	/// Sets the iterator to the node of \c g pointed by the trivial 
  20.872 -	/// iterator n.
  20.873 -	/// This feature necessitates that each time we 
  20.874 -	/// iterate the edge-set, the iteration order is the same.
  20.875 -	NodeIt(const StaticGraph& g, const Node& n) { }
  20.876 -	/// Next node.
  20.877 -
  20.878 -	/// Assign the iterator to the next node.
  20.879 -	///
  20.880 -	NodeIt& operator++() { return *this; }
  20.881 -      };
  20.882 -    
  20.883 -    
  20.884 -      /// The base type of the edge iterators.
  20.885 -
  20.886 -      /// The base type of the edge iterators.
  20.887 -      ///
  20.888 -      class Edge {
  20.889 -      public:
  20.890 -	/// Default constructor
  20.891 -
  20.892 -	/// @warning The default constructor sets the iterator
  20.893 -	/// to an undefined value.
  20.894 -	Edge() { }
  20.895 -	/// Copy constructor.
  20.896 -
  20.897 -	/// Copy constructor.
  20.898 -	///
  20.899 -	Edge(const Edge&) { }
  20.900 -	/// Initialize the iterator to be invalid.
  20.901 -
  20.902 -	/// Initialize the iterator to be invalid.
  20.903 -	///
  20.904 -	Edge(Invalid) { }
  20.905 -	/// Equality operator
  20.906 -
  20.907 -	/// Two iterators are equal if and only if they point to the
  20.908 -	/// same object or both are invalid.
  20.909 -	bool operator==(Edge) const { return true; }
  20.910 -	/// Inequality operator
  20.911 -
  20.912 -	/// \sa operator==(Node n)
  20.913 -	///
  20.914 -	bool operator!=(Edge) const { return true; }
  20.915 - 	///Comparison operator.
  20.916 -
  20.917 -	///This is a strict ordering between the nodes.
  20.918 -	///
  20.919 -	///This ordering can be different from the order in which NodeIt
  20.920 -	///goes through the nodes.
  20.921 -	///\todo Possibly we don't need it.
  20.922 - 	bool operator<(Edge) const { return true; }
  20.923 -      };
  20.924 -    
  20.925 -      /// This iterator goes trough the outgoing edges of a node.
  20.926 -
  20.927 -      /// This iterator goes trough the \e outgoing edges of a certain node
  20.928 -      /// of a graph.
  20.929 -      /// Its usage is quite simple, for example you can count the number
  20.930 -      /// of outgoing edges of a node \c n
  20.931 -      /// in graph \c g of type \c Graph as follows.
  20.932 -      /// \code
  20.933 -      /// int count=0;
  20.934 -      /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
  20.935 -      /// \endcode
  20.936 -    
  20.937 -      class OutEdgeIt : public Edge {
  20.938 -      public:
  20.939 -	/// Default constructor
  20.940 -
  20.941 -	/// @warning The default constructor sets the iterator
  20.942 -	/// to an undefined value.
  20.943 -	OutEdgeIt() { }
  20.944 -	/// Copy constructor.
  20.945 -
  20.946 -	/// Copy constructor.
  20.947 -	///
  20.948 -	OutEdgeIt(const OutEdgeIt&) { }
  20.949 -	/// Initialize the iterator to be invalid.
  20.950 -
  20.951 -	/// Initialize the iterator to be invalid.
  20.952 -	///
  20.953 -	OutEdgeIt(Invalid) { }
  20.954 -	/// This constructor sets the iterator to first outgoing edge.
  20.955 -    
  20.956 -	/// This constructor set the iterator to the first outgoing edge of
  20.957 -	/// node
  20.958 -	///@param n the node
  20.959 -	///@param g the graph
  20.960 -	OutEdgeIt(const StaticGraph& g, const Node& n) { }
  20.961 -	/// Edge -> OutEdgeIt conversion
  20.962 -
  20.963 -	/// Sets the iterator to the value of the trivial iterator \c e.
  20.964 -	/// This feature necessitates that each time we 
  20.965 -	/// iterate the edge-set, the iteration order is the same.
  20.966 -	OutEdgeIt(const StaticGraph& g, const Edge& e) { }
  20.967 -	///Next outgoing edge
  20.968 -	
  20.969 -	/// Assign the iterator to the next 
  20.970 -	/// outgoing edge of the corresponding node.
  20.971 -	OutEdgeIt& operator++() { return *this; }
  20.972 -      };
  20.973 -
  20.974 -      /// This iterator goes trough the incoming edges of a node.
  20.975 -
  20.976 -      /// This iterator goes trough the \e incoming edges of a certain node
  20.977 -      /// of a graph.
  20.978 -      /// Its usage is quite simple, for example you can count the number
  20.979 -      /// of outgoing edges of a node \c n
  20.980 -      /// in graph \c g of type \c Graph as follows.
  20.981 -      /// \code
  20.982 -      /// int count=0;
  20.983 -      /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
  20.984 -      /// \endcode
  20.985 -
  20.986 -      class InEdgeIt : public Edge {
  20.987 -      public:
  20.988 -	/// Default constructor
  20.989 -
  20.990 -	/// @warning The default constructor sets the iterator
  20.991 -	/// to an undefined value.
  20.992 -	InEdgeIt() { }
  20.993 -	/// Copy constructor.
  20.994 -
  20.995 -	/// Copy constructor.
  20.996 -	///
  20.997 -	InEdgeIt(const InEdgeIt&) { }
  20.998 -	/// Initialize the iterator to be invalid.
  20.999 -
 20.1000 -	/// Initialize the iterator to be invalid.
 20.1001 -	///
 20.1002 -	InEdgeIt(Invalid) { }
 20.1003 -	/// This constructor sets the iterator to first incoming edge.
 20.1004 -    
 20.1005 -	/// This constructor set the iterator to the first incoming edge of
 20.1006 -	/// node
 20.1007 -	///@param n the node
 20.1008 -	///@param g the graph
 20.1009 -	InEdgeIt(const StaticGraph& g, const Node& n) { }
 20.1010 -	/// Edge -> InEdgeIt conversion
 20.1011 -
 20.1012 -	/// Sets the iterator to the value of the trivial iterator \c e.
 20.1013 -	/// This feature necessitates that each time we 
 20.1014 -	/// iterate the edge-set, the iteration order is the same.
 20.1015 -	InEdgeIt(const StaticGraph& g, const Edge& n) { }
 20.1016 -	/// Next incoming edge
 20.1017 -
 20.1018 -	/// Assign the iterator to the next inedge of the corresponding node.
 20.1019 -	///
 20.1020 -	InEdgeIt& operator++() { return *this; }
 20.1021 -      };
 20.1022 -      /// This iterator goes through each edge.
 20.1023 -
 20.1024 -      /// This iterator goes through each edge of a graph.
 20.1025 -      /// Its usage is quite simple, for example you can count the number
 20.1026 -      /// of edges in a graph \c g of type \c Graph as follows:
 20.1027 -      /// \code
 20.1028 -      /// int count=0;
 20.1029 -      /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
 20.1030 -      /// \endcode
 20.1031 -      class EdgeIt : public Edge {
 20.1032 -      public:
 20.1033 -	/// Default constructor
 20.1034 -
 20.1035 -	/// @warning The default constructor sets the iterator
 20.1036 -	/// to an undefined value.
 20.1037 -	EdgeIt() { }
 20.1038 -	/// Copy constructor.
 20.1039 -
 20.1040 -	/// Copy constructor.
 20.1041 -	///
 20.1042 -	EdgeIt(const EdgeIt&) { }
 20.1043 -	/// Initialize the iterator to be invalid.
 20.1044 -
 20.1045 -	/// Initialize the iterator to be invalid.
 20.1046 -	///
 20.1047 -	EdgeIt(Invalid) { }
 20.1048 -	/// This constructor sets the iterator to first edge.
 20.1049 -    
 20.1050 -	/// This constructor set the iterator to the first edge of
 20.1051 -	/// node
 20.1052 -	///@param g the graph
 20.1053 -	EdgeIt(const StaticGraph& g) { }
 20.1054 -	/// Edge -> EdgeIt conversion
 20.1055 -
 20.1056 -	/// Sets the iterator to the value of the trivial iterator \c e.
 20.1057 -	/// This feature necessitates that each time we 
 20.1058 -	/// iterate the edge-set, the iteration order is the same.
 20.1059 -	EdgeIt(const StaticGraph&, const Edge&) { } 
 20.1060 -    	///Next edge
 20.1061 -	
 20.1062 -	/// Assign the iterator to the next 
 20.1063 -	/// edge of the corresponding node.
 20.1064 -	EdgeIt& operator++() { return *this; }
 20.1065 -      };
 20.1066 -
 20.1067 -      /// First node of the graph.
 20.1068 -
 20.1069 -      /// \retval i the first node.
 20.1070 -      /// \return the first node.
 20.1071 -      ///
 20.1072 -      NodeIt& first(NodeIt& i) const { return i; }
 20.1073 -
 20.1074 -      /// The first incoming edge.
 20.1075 -
 20.1076 -      /// The first incoming edge.
 20.1077 -      ///
 20.1078 -      InEdgeIt& first(InEdgeIt &i, Node) const { return i; }
 20.1079 -      /// The first outgoing edge.
 20.1080 -
 20.1081 -      /// The first outgoing edge.
 20.1082 -      ///
 20.1083 -      OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; }
 20.1084 -      /// The first edge of the Graph.
 20.1085 -
 20.1086 -      /// The first edge of the Graph.
 20.1087 -      ///
 20.1088 -      EdgeIt& first(EdgeIt& i) const { return i; }
 20.1089 -
 20.1090 -      ///Gives back the head node of an edge.
 20.1091 -
 20.1092 -      ///Gives back the head node of an edge.
 20.1093 -      ///
 20.1094 -      Node head(Edge) const { return INVALID; }
 20.1095 -      ///Gives back the tail node of an edge.
 20.1096 -
 20.1097 -      ///Gives back the tail node of an edge.
 20.1098 -      ///
 20.1099 -      Node tail(Edge) const { return INVALID; }
 20.1100 -  
 20.1101 -      ///Gives back the \e id of a node.
 20.1102 -
 20.1103 -      ///\warning Not all graph structures provide this feature.
 20.1104 -      ///
 20.1105 -      ///\todo Should each graph provide \c id?
 20.1106 -      int id(const Node&) const { return 0; }
 20.1107 -      ///Gives back the \e id of an edge.
 20.1108 -
 20.1109 -      ///\warning Not all graph structures provide this feature.
 20.1110 -      ///
 20.1111 -      ///\todo Should each graph provide \c id?
 20.1112 -      int id(const Edge&) const { return 0; }
 20.1113 -
 20.1114 -      ///\e
 20.1115 -      
 20.1116 -      ///\todo Should it be in the concept?
 20.1117 -      ///
 20.1118 -      int nodeNum() const { return 0; }
 20.1119 -      ///\e
 20.1120 -
 20.1121 -      ///\todo Should it be in the concept?
 20.1122 -      ///
 20.1123 -      int edgeNum() const { return 0; }
 20.1124 -
 20.1125 -
 20.1126 -      ///Reference map of the nodes to type \c T.
 20.1127 -
 20.1128 -      /// \ingroup skeletons
 20.1129 -      ///Reference map of the nodes to type \c T.
 20.1130 -      /// \sa Reference
 20.1131 -      /// \warning Making maps that can handle bool type (NodeMap<bool>)
 20.1132 -      /// needs some extra attention!
 20.1133 -      template<class T> class NodeMap : public ReferenceMap< Node, T >
 20.1134 -      {
 20.1135 -      public:
 20.1136 -
 20.1137 -	///\e
 20.1138 -	NodeMap(const StaticGraph&) { }
 20.1139 -	///\e
 20.1140 -	NodeMap(const StaticGraph&, T) { }
 20.1141 -
 20.1142 -	///Copy constructor
 20.1143 -	template<typename TT> NodeMap(const NodeMap<TT>&) { }
 20.1144 -	///Assignment operator
 20.1145 -	template<typename TT> NodeMap& operator=(const NodeMap<TT>&)
 20.1146 -	{ return *this; }
 20.1147 -      };
 20.1148 -
 20.1149 -      ///Reference map of the edges to type \c T.
 20.1150 -
 20.1151 -      /// \ingroup skeletons
 20.1152 -      ///Reference map of the edges to type \c T.
 20.1153 -      /// \sa Reference
 20.1154 -      /// \warning Making maps that can handle bool type (EdgeMap<bool>)
 20.1155 -      /// needs some extra attention!
 20.1156 -      template<class T> class EdgeMap
 20.1157 -	: public ReferenceMap<Edge,T>
 20.1158 -      {
 20.1159 -      public:
 20.1160 -
 20.1161 -	///\e
 20.1162 -	EdgeMap(const StaticGraph&) { }
 20.1163 -	///\e
 20.1164 -	EdgeMap(const StaticGraph&, T) { }
 20.1165 -    
 20.1166 -	///Copy constructor
 20.1167 -	template<typename TT> EdgeMap(const EdgeMap<TT>&) { }
 20.1168 -	///Assignment operator
 20.1169 -	template<typename TT> EdgeMap &operator=(const EdgeMap<TT>&)
 20.1170 -	{ return *this; }
 20.1171 -      };
 20.1172 +      // Technical requirement. Do we really need this?
 20.1173 +      bool operator<(BaseGraphItem) const { return false; }
 20.1174      };
 20.1175  
 20.1176 -    struct DummyType {
 20.1177 -      int value;
 20.1178 -      DummyType() {}
 20.1179 -      DummyType(int p) : value(p) {}
 20.1180 -      DummyType& operator=(int p) { value = p; return *this;}
 20.1181 +
 20.1182 +    /// A minimal GraphBase concept
 20.1183 +
 20.1184 +    /// This class describes a minimal concept which can be extended to a
 20.1185 +    /// full-featured graph with \ref GraphFactory.
 20.1186 +    class GraphBase {
 20.1187 +    public:
 20.1188 +
 20.1189 +      GraphBase() {}
 20.1190 +
 20.1191 +
 20.1192 +      /// \bug Nodes and Edges are comparable each other
 20.1193 +      
 20.1194 +      class Node : public BaseGraphItem {};
 20.1195 +      class Edge : public BaseGraphItem {};
 20.1196 +
 20.1197 +      // Graph operation
 20.1198 +      void firstNode(Node &n) const { }
 20.1199 +      void firstEdge(Edge &e) const { }
 20.1200 +
 20.1201 +      void firstOutEdge(Edge &e, Node) const { }
 20.1202 +      void firstInEdge(Edge &e, Node) const { }
 20.1203 +
 20.1204 +      void nextNode(Node &n) const { }
 20.1205 +      void nextEdge(Edge &e) const { }
 20.1206 +
 20.1207 +
 20.1208 +      // Question: isn't it reasonable if this methods have a Node
 20.1209 +      // parameter? Like this:
 20.1210 +      // Edge& nextOut(Edge &e, Node) const { return e; }
 20.1211 +      void nextOutEdge(Edge &e) const { }
 20.1212 +      void nextInEdge(Edge &e) const { }
 20.1213 +
 20.1214 +      Node head(Edge) const { return Node(); }
 20.1215 +      Node tail(Edge) const { return Node(); }
 20.1216 +      
 20.1217 +
 20.1218 +      // Do we need id, nodeNum, edgeNum and co. in this basic graphbase
 20.1219 +      // concept?
 20.1220 +
 20.1221 +
 20.1222 +      // Maps.
 20.1223 +      //
 20.1224 +      // We need a special slimer concept which does not provide maps (it
 20.1225 +      // wouldn't be strictly slimer, cause for map-factory id() & friends
 20.1226 +      // a required...)
 20.1227 +
 20.1228 +      template<typename T>
 20.1229 +      class NodeMap : public GraphMap<Node, T, GraphBase> {};
 20.1230 +
 20.1231 +      template<typename T>
 20.1232 +      class EdgeMap : public GraphMap<Edge, T, GraphBase> {};
 20.1233      };
 20.1234 -    
 20.1235 -    ///\brief Checks whether \c G meets the
 20.1236 -    ///\ref lemon::skeleton::StaticGraph "StaticGraph" concept
 20.1237 -    template<class Graph> void checkCompileStaticGraph(Graph &G) 
 20.1238 -    {
 20.1239 -      typedef typename Graph::Node Node;
 20.1240 -      typedef typename Graph::NodeIt NodeIt;
 20.1241 -      typedef typename Graph::Edge Edge;
 20.1242 -      typedef typename Graph::EdgeIt EdgeIt;
 20.1243 -      typedef typename Graph::InEdgeIt InEdgeIt;
 20.1244 -      typedef typename Graph::OutEdgeIt OutEdgeIt;
 20.1245 -  
 20.1246 -      {
 20.1247 -	Node i; Node j(i); Node k(INVALID);
 20.1248 -	i=j;
 20.1249 -	bool b; b=true;
 20.1250 -	b=(i==INVALID); b=(i!=INVALID);
 20.1251 -	b=(i==j); b=(i!=j); b=(i<j);
 20.1252 -      }
 20.1253 -      {
 20.1254 -	NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
 20.1255 -	i=j;
 20.1256 -	j=G.first(i);
 20.1257 -	j=++i;
 20.1258 -	bool b; b=true;
 20.1259 -	b=(i==INVALID); b=(i!=INVALID);
 20.1260 -	Node n(i);
 20.1261 -	n=i;
 20.1262 -	b=(i==j); b=(i!=j); b=(i<j);
 20.1263 -	//Node ->NodeIt conversion
 20.1264 -	NodeIt ni(G,n);
 20.1265 -      }
 20.1266 -      {
 20.1267 -	Edge i; Edge j(i); Edge k(INVALID);
 20.1268 -	i=j;
 20.1269 -	bool b; b=true;
 20.1270 -	b=(i==INVALID); b=(i!=INVALID);
 20.1271 -	b=(i==j); b=(i!=j); b=(i<j);
 20.1272 -      }
 20.1273 -      {
 20.1274 -	EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
 20.1275 -	i=j;
 20.1276 -	j=G.first(i);
 20.1277 -	j=++i;
 20.1278 -	bool b; b=true;
 20.1279 -	b=(i==INVALID); b=(i!=INVALID);
 20.1280 -	Edge e(i);
 20.1281 -	e=i;
 20.1282 -	b=(i==j); b=(i!=j); b=(i<j);
 20.1283 -	//Edge ->EdgeIt conversion
 20.1284 -	EdgeIt ei(G,e);
 20.1285 -      }
 20.1286 -      {
 20.1287 -	Node n;
 20.1288 -	InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
 20.1289 -	i=j;
 20.1290 -	j=G.first(i,n);
 20.1291 -	j=++i;
 20.1292 -	bool b; b=true;
 20.1293 -	b=(i==INVALID); b=(i!=INVALID);
 20.1294 -	Edge e(i);
 20.1295 -	e=i;
 20.1296 -	b=(i==j); b=(i!=j); b=(i<j);
 20.1297 -	//Edge ->InEdgeIt conversion
 20.1298 -	InEdgeIt ei(G,e);
 20.1299 -      }
 20.1300 -      {
 20.1301 -	Node n;
 20.1302 -	OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
 20.1303 -	i=j;
 20.1304 -	j=G.first(i,n);
 20.1305 -	j=++i;
 20.1306 -	bool b; b=true;
 20.1307 -	b=(i==INVALID); b=(i!=INVALID);
 20.1308 -	Edge e(i);
 20.1309 -	e=i;
 20.1310 -	b=(i==j); b=(i!=j); b=(i<j);
 20.1311 -	//Edge ->OutEdgeIt conversion
 20.1312 -	OutEdgeIt ei(G,e);
 20.1313 -      }
 20.1314 -      {
 20.1315 -	Node n,m;
 20.1316 -	n=m=INVALID;
 20.1317 -	Edge e;
 20.1318 -	e=INVALID;
 20.1319 -	n=G.tail(e);
 20.1320 -	n=G.head(e);
 20.1321 -      }
 20.1322 -      // id tests
 20.1323 -      { Node n; int i=G.id(n); i=i; }
 20.1324 -      { Edge e; int i=G.id(e); i=i; }
 20.1325 -      //NodeMap tests
 20.1326 -      {
 20.1327 -	Node k;
 20.1328 -	typename Graph::template NodeMap<int> m(G);
 20.1329 -	//Const map
 20.1330 -	typename Graph::template NodeMap<int> const &cm = m;
 20.1331 -	//Inicialize with default value
 20.1332 -	typename Graph::template NodeMap<int> mdef(G,12);
 20.1333 -	//Copy
 20.1334 -	typename Graph::template NodeMap<int> mm(cm);
 20.1335 -	//Copy from another type
 20.1336 -	typename Graph::template NodeMap<double> dm(cm);
 20.1337 -	//Copy to more complex type
 20.1338 -	typename Graph::template NodeMap<DummyType> em(cm);
 20.1339 -	int v;
 20.1340 -	v=m[k]; m[k]=v; m.set(k,v);
 20.1341 -	v=cm[k];
 20.1342 -    
 20.1343 -	m=cm;  
 20.1344 -	dm=cm; //Copy from another type  
 20.1345 -	em=cm; //Copy to more complex type
 20.1346 -	{
 20.1347 -	  //Check the typedef's
 20.1348 -	  typename Graph::template NodeMap<int>::ValueType val;
 20.1349 -	  val=1;
 20.1350 -	  typename Graph::template NodeMap<int>::KeyType key;
 20.1351 -	  key = typename Graph::NodeIt(G);
 20.1352 -	}
 20.1353 -      }  
 20.1354 -      { //bool NodeMap
 20.1355 -	Node k;
 20.1356 -	typename Graph::template NodeMap<bool> m(G);
 20.1357 -	typename Graph::template NodeMap<bool> const &cm = m;  //Const map
 20.1358 -	//Inicialize with default value
 20.1359 -	typename Graph::template NodeMap<bool> mdef(G,12);
 20.1360 -	typename Graph::template NodeMap<bool> mm(cm);   //Copy
 20.1361 -	typename Graph::template NodeMap<int> dm(cm); //Copy from another type
 20.1362 -	bool v;
 20.1363 -	v=m[k]; m[k]=v; m.set(k,v);
 20.1364 -	v=cm[k];
 20.1365 -    
 20.1366 -	m=cm;  
 20.1367 -	dm=cm; //Copy from another type
 20.1368 -	m=dm; //Copy to another type
 20.1369  
 20.1370 -	{
 20.1371 -	  //Check the typedef's
 20.1372 -	  typename Graph::template NodeMap<bool>::ValueType val;
 20.1373 -	  val=true;
 20.1374 -	  typename Graph::template NodeMap<bool>::KeyType key;
 20.1375 -	  key= typename Graph::NodeIt(G);
 20.1376 +
 20.1377 +
 20.1378 +    /**************** Concept checking classes ****************/
 20.1379 +
 20.1380 +    template<typename BGI>
 20.1381 +    struct BaseGraphItemConcept {
 20.1382 +      void constraints() {
 20.1383 +	BGI i1;
 20.1384 +	BGI i2 = i1;
 20.1385 +	BGI i3 = INVALID;
 20.1386 +	
 20.1387 +	i1 = i3;
 20.1388 +	if( i1 == i3 ) {
 20.1389 +	  if ( i2 != i3 && i3 < i2 )
 20.1390 +	    return;
 20.1391  	}
 20.1392        }
 20.1393 -      //EdgeMap tests
 20.1394 -      {
 20.1395 -	Edge k;
 20.1396 -	typename Graph::template EdgeMap<int> m(G);
 20.1397 -	typename Graph::template EdgeMap<int> const &cm = m;  //Const map
 20.1398 -	//Inicialize with default value
 20.1399 -	typename Graph::template EdgeMap<int> mdef(G,12);
 20.1400 -	typename Graph::template EdgeMap<int> mm(cm);   //Copy
 20.1401 -	typename Graph::template EdgeMap<double> dm(cm);//Copy from another type
 20.1402 -	int v;
 20.1403 -	v=m[k]; m[k]=v; m.set(k,v);
 20.1404 -	v=cm[k];
 20.1405 -    
 20.1406 -	m=cm;  
 20.1407 -	dm=cm; //Copy from another type
 20.1408 -	{
 20.1409 -	  //Check the typedef's
 20.1410 -	  typename Graph::template EdgeMap<int>::ValueType val;
 20.1411 -	  val=1;
 20.1412 -	  typename Graph::template EdgeMap<int>::KeyType key;
 20.1413 -	  key= typename Graph::EdgeIt(G);
 20.1414 -	}
 20.1415 -      }  
 20.1416 -      { //bool EdgeMap
 20.1417 -	Edge k;
 20.1418 -	typename Graph::template EdgeMap<bool> m(G);
 20.1419 -	typename Graph::template EdgeMap<bool> const &cm = m;  //Const map
 20.1420 -	//Inicialize with default value
 20.1421 -	typename Graph::template EdgeMap<bool> mdef(G,12);
 20.1422 -	typename Graph::template EdgeMap<bool> mm(cm);   //Copy
 20.1423 -	typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
 20.1424 -	bool v;
 20.1425 -	v=m[k]; m[k]=v; m.set(k,v);
 20.1426 -	v=cm[k];
 20.1427 -    
 20.1428 -	m=cm;  
 20.1429 -	dm=cm; //Copy from another type
 20.1430 -	m=dm; //Copy to another type
 20.1431 -	{
 20.1432 -	  //Check the typedef's
 20.1433 -	  typename Graph::template EdgeMap<bool>::ValueType val;
 20.1434 -	  val=true;
 20.1435 -	  typename Graph::template EdgeMap<bool>::KeyType key;
 20.1436 -	  key= typename Graph::EdgeIt(G);
 20.1437 -	}
 20.1438 -      }
 20.1439 -    }
 20.1440 -    
 20.1441 -    /// An empty non-static graph class.
 20.1442 -    
 20.1443 -    /// This class provides everything that \ref StaticGraph
 20.1444 -    /// with additional functionality which enables to build a
 20.1445 -    /// graph from scratch.
 20.1446 -    class ExtendableGraph : public StaticGraph
 20.1447 -    {
 20.1448 -    public:
 20.1449 -      /// Defalult constructor.
 20.1450 -
 20.1451 -      /// Defalult constructor.
 20.1452 -      ///
 20.1453 -      ExtendableGraph() { }
 20.1454 -      ///Add a new node to the graph.
 20.1455 -
 20.1456 -      /// \return the new node.
 20.1457 -      ///
 20.1458 -      Node addNode() { return INVALID; }
 20.1459 -      ///Add a new edge to the graph.
 20.1460 -
 20.1461 -      ///Add a new edge to the graph with tail node \c t
 20.1462 -      ///and head node \c h.
 20.1463 -      ///\return the new edge.
 20.1464 -      Edge addEdge(Node h, Node t) { return INVALID; }
 20.1465 -    
 20.1466 -      /// Resets the graph.
 20.1467 -
 20.1468 -      /// This function deletes all edges and nodes of the graph.
 20.1469 -      /// It also frees the memory allocated to store them.
 20.1470 -      /// \todo It might belong to \ref ErasableGraph.
 20.1471 -      void clear() { }
 20.1472      };
 20.1473  
 20.1474      
 20.1475 -    ///\brief Checks whether \c G meets the
 20.1476 -    ///\ref lemon::skeleton::ExtendableGraph "ExtendableGraph" concept
 20.1477 -    template<class Graph> void checkCompileExtendableGraph(Graph &G) 
 20.1478 -    {
 20.1479 -      checkCompileStaticGraph(G);
 20.1480 +    
 20.1481 +    class StaticGraph 
 20.1482 +      :  virtual public BaseGraphComponent, public IterableGraphComponent, public MappableGraphComponent {
 20.1483 +    public:
 20.1484 +      typedef BaseGraphComponent::Node Node;
 20.1485 +      typedef BaseGraphComponent::Edge Edge;
 20.1486 +    };
 20.1487  
 20.1488 -      typedef typename Graph::Node Node;
 20.1489 -      typedef typename Graph::NodeIt NodeIt;
 20.1490 -      typedef typename Graph::Edge Edge;
 20.1491 -      typedef typename Graph::EdgeIt EdgeIt;
 20.1492 -      typedef typename Graph::InEdgeIt InEdgeIt;
 20.1493 -      typedef typename Graph::OutEdgeIt OutEdgeIt;
 20.1494 -  
 20.1495 -      Node n,m;
 20.1496 -      n=G.addNode();
 20.1497 -      m=G.addNode();
 20.1498 -      Edge e;
 20.1499 -      e=G.addEdge(n,m); 
 20.1500 -  
 20.1501 -      //  G.clear();
 20.1502 -    }
 20.1503 +    template <typename Graph>
 20.1504 +    struct StaticGraphConcept {
 20.1505 +      void constraints() {
 20.1506 +	function_requires<BaseGraphComponentConcept<Graph> >();
 20.1507 +	function_requires<IterableGraphComponentConcept<Graph> >();
 20.1508 +	function_requires<MappableGraphComponentConcept<Graph> >();
 20.1509 +      }
 20.1510 +      Graph& graph;
 20.1511 +    };
 20.1512  
 20.1513 +    class ExtendableGraph 
 20.1514 +      :  virtual public BaseGraphComponent, public StaticGraph, public ExtendableGraphComponent, public ClearableGraphComponent {
 20.1515 +    public:
 20.1516 +      typedef BaseGraphComponent::Node Node;
 20.1517 +      typedef BaseGraphComponent::Edge Edge;
 20.1518 +    };
 20.1519  
 20.1520 -    /// An empty erasable graph class.
 20.1521 -  
 20.1522 -    /// This class is an extension of \ref ExtendableGraph. It also makes it
 20.1523 -    /// possible to erase edges or nodes.
 20.1524 -    class ErasableGraph : public ExtendableGraph
 20.1525 -    {
 20.1526 +    template <typename Graph>
 20.1527 +    struct ExtendableGraphConcept {
 20.1528 +      void constraints() {
 20.1529 +	function_requires<StaticGraphConcept<Graph> >();
 20.1530 +	function_requires<ExtendableGraphComponentConcept<Graph> >();
 20.1531 +	function_requires<ClearableGraphComponentConcept<Graph> >();
 20.1532 +      }
 20.1533 +      Graph& graph;
 20.1534 +    };
 20.1535 +
 20.1536 +    class ErasableGraph 
 20.1537 +      :  virtual public BaseGraphComponent, public ExtendableGraph, public ErasableGraphComponent {
 20.1538      public:
 20.1539 -      /// Defalult constructor.
 20.1540 +      typedef BaseGraphComponent::Node Node;
 20.1541 +      typedef BaseGraphComponent::Edge Edge;
 20.1542 +    };
 20.1543  
 20.1544 -      /// Defalult constructor.
 20.1545 -      ///
 20.1546 -      ErasableGraph() { }
 20.1547 -      /// Deletes a node.
 20.1548 +    template <typename Graph>
 20.1549 +    struct ErasableGraphConcept {
 20.1550 +      void constraints() {
 20.1551 +	function_requires<ExtendableGraphConcept<Graph> >();
 20.1552 +	function_requires<ErasableGraphComponentConcept<Graph> >();
 20.1553 +      }
 20.1554 +      Graph& graph;
 20.1555 +    };
 20.1556  
 20.1557 -      /// Deletes node \c n node.
 20.1558 -      ///
 20.1559 -      void erase(Node n) { }
 20.1560 -      /// Deletes an edge.
 20.1561 -
 20.1562 -      /// Deletes edge \c e edge.
 20.1563 -      ///
 20.1564 -      void erase(Edge e) { }
 20.1565 -    };
 20.1566 -    
 20.1567 -    template<class Graph> void checkCompileGraphEraseEdge(Graph &G) 
 20.1568 -    {
 20.1569 -      typename Graph::Edge e;
 20.1570 -      G.erase(e);
 20.1571 -    }
 20.1572 -
 20.1573 -    template<class Graph> void checkCompileGraphEraseNode(Graph &G) 
 20.1574 -    {
 20.1575 -      typename Graph::Node n;
 20.1576 -      G.erase(n);
 20.1577 -    }
 20.1578 -
 20.1579 -    ///\brief Checks whether \c G meets the
 20.1580 -    ///\ref lemon::skeleton::EresableGraph "EresableGraph" concept
 20.1581 -    template<class Graph> void checkCompileErasableGraph(Graph &G) 
 20.1582 -    {
 20.1583 -      checkCompileExtendableGraph(G);
 20.1584 -      checkCompileGraphEraseNode(G);
 20.1585 -      checkCompileGraphEraseEdge(G);
 20.1586 -    }
 20.1587 -
 20.1588 -    ///Checks whether a graph has findEdge() member function.
 20.1589 -    
 20.1590 -    ///\todo findEdge() might be a global function.
 20.1591 -    ///
 20.1592 -    template<class Graph> void checkCompileGraphFindEdge(Graph &G) 
 20.1593 -    {
 20.1594 -      typedef typename Graph::NodeIt Node;
 20.1595 -      typedef typename Graph::NodeIt NodeIt;
 20.1596 -
 20.1597 -      G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
 20.1598 -      G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));  
 20.1599 -    }
 20.1600 - 
 20.1601      // @}
 20.1602    } //namespace skeleton  
 20.1603  } //namespace lemon
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/lemon/skeletons/graph_component.h	Wed Oct 27 22:38:50 2004 +0000
    21.3 @@ -0,0 +1,827 @@
    21.4 +/* -*- C++ -*-
    21.5 + * src/lemon/skeletons/graph_component.h - Part of LEMON, a generic C++ optimization library
    21.6 + *
    21.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    21.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    21.9 + *
   21.10 + * Permission to use, modify and distribute this software is granted
   21.11 + * provided that this copyright notice appears in all copies. For
   21.12 + * precise terms see the accompanying LICENSE file.
   21.13 + *
   21.14 + * This software is provided "AS IS" with no warranty of any kind,
   21.15 + * express or implied, and with no claim as to its suitability for any
   21.16 + * purpose.
   21.17 + *
   21.18 + */
   21.19 +
   21.20 +///\ingroup skeletons
   21.21 +///\file
   21.22 +///\brief The graph components.
   21.23 +
   21.24 +
   21.25 +#ifndef LEMON_SKELETON_GRAPH_COMPONENT_H
   21.26 +#define LEMON_SKELETON_GRAPH_COMPONENT_H
   21.27 +
   21.28 +#include <lemon/invalid.h>
   21.29 +#include <lemon/skeletons/maps.h>
   21.30 +
   21.31 +namespace lemon {
   21.32 +  namespace skeleton {
   21.33 +
   21.34 +    /// An empty base graph class.
   21.35 +  
   21.36 +    /// This class provides the most minimal features of a graph structure.
   21.37 +    /// All the graph concepts have to be conform to this base graph.
   21.38 +
   21.39 +    class BaseGraphComponent {
   21.40 +    public:
   21.41 +
   21.42 +      typedef BaseGraphComponent Graph;
   21.43 +      
   21.44 +      /// Node class of the graph.
   21.45 +
   21.46 +      /// This class represents the Nodes of the graph. 
   21.47 +      ///
   21.48 +      class Node {
   21.49 +      public:
   21.50 +
   21.51 +	/// Default constructor.
   21.52 +
   21.53 +	/// @warning The default constructor sets the iterator
   21.54 +	/// to an undefined value.
   21.55 +
   21.56 +	Node() {}
   21.57 +	/// Copy constructor.
   21.58 +
   21.59 +	/// Copy constructor.
   21.60 +	///
   21.61 +	Node(const Node&) {}
   21.62 +
   21.63 +	/// Invalid constructor \& conversion.
   21.64 +
   21.65 +	/// This constructor initializes the iterator to be invalid.
   21.66 +	/// \sa Invalid for more details.
   21.67 +	Node(Invalid) {}
   21.68 +
   21.69 +
   21.70 +	Node& operator=(const Node&) { return *this;}
   21.71 +
   21.72 +	/// Equality operator.
   21.73 +
   21.74 +	/// Two iterators are equal if and only if they represents the
   21.75 +	/// same node in the graph or both are invalid.
   21.76 +	bool operator==(const Node&) { return true;}
   21.77 +
   21.78 +
   21.79 +	/// Inequality operator.
   21.80 +	
   21.81 +	/// \sa operator==(const Node& n)
   21.82 +	///
   21.83 +	bool operator!=(const Node&) { return true;}
   21.84 +
   21.85 + 	/// Comparison operator.
   21.86 +
   21.87 +	/// This is a strict ordering between the nodes.
   21.88 +	///
   21.89 +	/// This ordering can be different from the iterating order of nodes.
   21.90 +	/// \todo Possibly we don't need it.
   21.91 +	bool operator<(const Node&) { return true;}
   21.92 +      };
   21.93 +
   21.94 +      /// Edge class of the graph.
   21.95 +
   21.96 +      /// This class represents the Edges of the graph. 
   21.97 +      ///
   21.98 +      class Edge {
   21.99 +      public:
  21.100 +
  21.101 +	/// Default constructor.
  21.102 +
  21.103 +	/// @warning The default constructor sets the iterator
  21.104 +	/// to an undefined value.
  21.105 +
  21.106 +	Edge() {}
  21.107 +	/// Copy constructor.
  21.108 +
  21.109 +	/// Copy constructor.
  21.110 +	///
  21.111 +	Edge(const Edge&) {}
  21.112 +
  21.113 +	/// Invalid constructor \& conversion.
  21.114 +
  21.115 +	/// This constructor initializes the iterator to be invalid.
  21.116 +	/// \sa Invalid for more details.
  21.117 +	Edge(Invalid) {}
  21.118 +
  21.119 +
  21.120 +	Edge& operator=(const Edge&) { return *this;}
  21.121 +
  21.122 +	/// Equality operator.
  21.123 +
  21.124 +	/// Two iterators are equal if and only if they represents the
  21.125 +	/// same edge in the graph or both are invalid.
  21.126 +	bool operator==(const Edge&) { return true;}
  21.127 +
  21.128 +
  21.129 +	/// Inequality operator.
  21.130 +	
  21.131 +	/// \sa operator==(const Edge& n)
  21.132 +	///
  21.133 +	bool operator!=(const Edge&) { return true;}
  21.134 +
  21.135 + 	/// Comparison operator.
  21.136 +
  21.137 +	/// This is a strict ordering between the edges.
  21.138 +	///
  21.139 +	/// This ordering can be different from the iterating order of edges.
  21.140 +	/// \todo Possibly we don't need it.
  21.141 +	bool operator<(const Edge&) { return true;}
  21.142 +      };
  21.143 +
  21.144 +      ///Gives back the head node of an edge.
  21.145 +
  21.146 +      ///Gives back the head node of an edge.
  21.147 +      ///
  21.148 +      Node head(const Edge&) const { return INVALID;}
  21.149 +
  21.150 +      ///Gives back the tail node of an edge.
  21.151 +
  21.152 +      ///Gives back the tail node of an edge.
  21.153 +      ///
  21.154 +      Node tail(const Edge&) const { return INVALID;}
  21.155 +    };
  21.156 +
  21.157 +    /// Concept check structure for BaseGraph.
  21.158 +
  21.159 +    /// Concept check structure for BaseGraph.
  21.160 +    ///
  21.161 +
  21.162 +    template <typename Graph>
  21.163 +    struct BaseGraphComponentConcept {
  21.164 +      typedef typename Graph::Node Node;
  21.165 +      typedef typename Graph::Edge Edge;
  21.166 +      
  21.167 +      void constraints() {
  21.168 +	{
  21.169 +	  Node ni; 
  21.170 +	  Node nj(ni); 
  21.171 +	  Node nk(INVALID);
  21.172 +	  ni = nj;
  21.173 +	  bool b; b = true;
  21.174 +	  b = (ni == INVALID); b = (ni != INVALID);
  21.175 +	  b = (ni==nj); b = (ni != nj); b=( ni < nj);
  21.176 +	}
  21.177 +	{
  21.178 +	  Edge ei; 
  21.179 +	  Edge ej(ei); 
  21.180 +	  Edge ek(INVALID);
  21.181 +	  ei = ej;
  21.182 +	  bool b; b = true;
  21.183 +	  b = (ei == INVALID); b = (ei != INVALID);
  21.184 +	  b = (ei==ej); b = (ei != ej); b=( ei < ej);
  21.185 +	}
  21.186 +	{
  21.187 +	  const Graph& const_graph = graph;
  21.188 +	  Node n;
  21.189 +	  Edge e;
  21.190 +	  n = const_graph.tail(e);
  21.191 +	  n = const_graph.head(e);
  21.192 +	}      
  21.193 +      }
  21.194 +      
  21.195 +      Graph& graph;
  21.196 +    };
  21.197 +
  21.198 +    /// An empty iterable base graph class.
  21.199 +  
  21.200 +    /// This class provides beside the core graph features
  21.201 +    /// core iterable interface for the graph structure.
  21.202 +    /// The most of the base graphs should be conform to this concept.
  21.203 +
  21.204 +    class BaseIterableGraphComponent : virtual public BaseGraphComponent {
  21.205 +    public:
  21.206 +
  21.207 +      typedef BaseGraphComponent::Node Node;
  21.208 +      typedef BaseGraphComponent::Edge Edge;
  21.209 +
  21.210 +      /// Gives back the first Node in the iterating order.
  21.211 +      
  21.212 +      /// Gives back the first Node in the iterating order.
  21.213 +      ///     
  21.214 +      void first(Node&) const {}
  21.215 +
  21.216 +      /// Gives back the next Node in the iterating order.
  21.217 +      
  21.218 +      /// Gives back the next Node in the iterating order.
  21.219 +      ///     
  21.220 +      void next(Node&) const {}
  21.221 +
  21.222 +      /// Gives back the first Edge in the iterating order.
  21.223 +      
  21.224 +      /// Gives back the first Edge in the iterating order.
  21.225 +      ///     
  21.226 +      void first(Edge&) const {}
  21.227 +      /// Gives back the next Edge in the iterating order.
  21.228 +      
  21.229 +      /// Gives back the next Edge in the iterating order.
  21.230 +      ///     
  21.231 +      void next(Edge&) const {}
  21.232 +
  21.233 +
  21.234 +      /// Gives back the first of the Edges point to the given Node.
  21.235 +      
  21.236 +      /// Gives back the first of the Edges point to the given Node.
  21.237 +      ///     
  21.238 +      void firstIn(Edge&, const Node&) const {}
  21.239 +
  21.240 +      /// Gives back the next of the Edges points to the given Node.
  21.241 +
  21.242 +
  21.243 +      /// Gives back the next of the Edges points to the given Node.
  21.244 +      ///
  21.245 +      void nextIn(Edge&) const {}
  21.246 +
  21.247 +      /// Gives back the first of the Edges start from the given Node.
  21.248 +      
  21.249 +      /// Gives back the first of the Edges start from the given Node.
  21.250 +      ///     
  21.251 +      void firstOut(Edge&, const Node&) const {}
  21.252 +
  21.253 +      /// Gives back the next of the Edges start from the given Node.
  21.254 +      
  21.255 +      /// Gives back the next of the Edges start from the given Node.
  21.256 +      ///     
  21.257 +      void nextOut(Edge&) const {}
  21.258 +    };
  21.259 +
  21.260 +
  21.261 +    /// Concept check structure for IterableBaseGraph.
  21.262 +
  21.263 +    /// Concept check structure for IterableBaseGraph.
  21.264 +    ///
  21.265 +    template <typename Graph>
  21.266 +    struct BaseIterableGraphComponentConcept {
  21.267 +      
  21.268 +      void constraints() { 
  21.269 +	const Graph& const_graph = graph;
  21.270 +	typename Graph::Node node;      
  21.271 +	typename Graph::Edge edge;
  21.272 +	{
  21.273 +	  const_graph.first(node);
  21.274 +	  const_graph.next(node);
  21.275 +	}
  21.276 +	{
  21.277 +	  const_graph.first(edge);
  21.278 +	  const_graph.next(edge);
  21.279 +	}
  21.280 +	{
  21.281 +	  const_graph.firstIn(edge, node);
  21.282 +	  const_graph.nextIn(edge);
  21.283 +	}
  21.284 +	{
  21.285 +	  const_graph.firstOut(edge, node);
  21.286 +	  const_graph.nextOut(edge);
  21.287 +	}
  21.288 +      }
  21.289 +
  21.290 +      Graph& graph;
  21.291 +    };
  21.292 +
  21.293 +    /// An empty idable base graph class.
  21.294 +  
  21.295 +    /// This class provides beside the core graph features
  21.296 +    /// core id functions for the graph structure.
  21.297 +    /// The most of the base graphs should be conform to this concept.
  21.298 +    /// The id's are unique and immutable.
  21.299 +
  21.300 +    class IDableGraphComponent : virtual public BaseGraphComponent {
  21.301 +    public:
  21.302 +
  21.303 +      typedef BaseGraphComponent::Node Node;
  21.304 +      typedef BaseGraphComponent::Edge Edge;
  21.305 +
  21.306 +      /// Gives back an unique integer id for the Node. 
  21.307 +
  21.308 +      /// Gives back an unique integer id for the Node. 
  21.309 +      ///
  21.310 +      int id(const Node&) const { return -1;}
  21.311 +
  21.312 +      /// Gives back an unique integer id for the Edge. 
  21.313 +
  21.314 +      /// Gives back an unique integer id for the Edge. 
  21.315 +      ///
  21.316 +      int id(const Edge&) const { return -1;}
  21.317 +    };
  21.318 +
  21.319 +
  21.320 +    /// Concept check structure for IdableBaseGraph.
  21.321 +
  21.322 +    /// Concept check structure for IdableBaseGraph.
  21.323 +    ///
  21.324 +    template <typename Graph>
  21.325 +    struct IDableGraphComponentConcept {
  21.326 +
  21.327 +      void constraints() {
  21.328 +	const Graph& const_graph = graph;
  21.329 +	typename Graph::Node node;
  21.330 +	int nid = const_graph.id(node);
  21.331 +	nid = const_graph.id(node);
  21.332 +	typename Graph::Edge edge;
  21.333 +	int eid = const_graph.id(edge);
  21.334 +	eid = const_graph.id(edge);
  21.335 +      }
  21.336 +
  21.337 +      Graph& graph;
  21.338 +    };
  21.339 +
  21.340 +
  21.341 +    /// An empty max-idable base graph class.
  21.342 +  
  21.343 +    /// This class provides beside the core graph features
  21.344 +    /// core max id functions for the graph structure.
  21.345 +    /// The most of the base graphs should be conform to this concept.
  21.346 +    /// The id's are unique and immutable.
  21.347 +    class MaxIDableGraphComponent : virtual public BaseGraphComponent {
  21.348 +    public:
  21.349 +
  21.350 +      /// Gives back an integer greater or equal to the maximum Node id. 
  21.351 +
  21.352 +      /// Gives back an integer greater or equal to the maximum Node id. 
  21.353 +      ///
  21.354 +      int maxEdgeId() const { return -1;}
  21.355 +
  21.356 +      /// Gives back an integer greater or equal to the maximum Edge id. 
  21.357 +
  21.358 +      /// Gives back an integer greater or equal to the maximum Edge id. 
  21.359 +      ///
  21.360 +      int maxNodeId() const { return -1;}
  21.361 +    };
  21.362 +
  21.363 +    /// Concept check structure for MaxIdableBaseGraph.
  21.364 +
  21.365 +    /// Concept check structure for MaxIdableBaseGraph.
  21.366 +    ///
  21.367 +    template <typename Graph>
  21.368 +    struct MaxIDableGraphComponentConcept {
  21.369 +
  21.370 +      void constraints() {
  21.371 +	const Graph& const_graph = graph;
  21.372 +	int nid = const_graph.maxEdgeId();
  21.373 +	ignore_unused_variable_warning(nid);
  21.374 +	int eid = const_graph.maxNodeId();
  21.375 +	ignore_unused_variable_warning(eid);
  21.376 +      }
  21.377 +
  21.378 +      Graph& graph;
  21.379 +    };
  21.380 +
  21.381 +    /// An empty extendable base graph class.
  21.382 +  
  21.383 +    /// This class provides beside the core graph features
  21.384 +    /// core graph extend interface for the graph structure.
  21.385 +    /// The most of the base graphs should be conform to this concept.
  21.386 +    class BaseExtendableGraphComponent : virtual public BaseGraphComponent {
  21.387 +    public:
  21.388 +
  21.389 +      typedef BaseGraphComponent::Node Node;
  21.390 +      typedef BaseGraphComponent::Edge Edge;
  21.391 +
  21.392 +      /// Adds a new Node to the graph.
  21.393 +
  21.394 +      /// Adds a new Node to the graph.
  21.395 +      ///
  21.396 +      Node addNode() {
  21.397 +	return INVALID;
  21.398 +      }
  21.399 +    
  21.400 +      /// Adds a new Edge connects the two Nodes to the graph.
  21.401 +
  21.402 +      /// Adds a new Edge connects the two Nodes to the graph.
  21.403 +      ///
  21.404 +      Edge addEdge(const Node& from, const Node& to) {
  21.405 +	return INVALID;
  21.406 +      }
  21.407 +
  21.408 +    };
  21.409 +
  21.410 +    /// Concept check structure for ExtendableBaseGraph.
  21.411 +
  21.412 +    /// Concept check structure for ExtendableBaseGraph.
  21.413 +    ///
  21.414 +    template <typename Graph>
  21.415 +    struct BaseExtendableGraphComponentConcept {
  21.416 +      void constraints() {
  21.417 +	typename Graph::Node node_a, node_b;
  21.418 +	node_a = graph.addNode();
  21.419 +	typename Graph::Edge edge;
  21.420 +	edge = graph.addEdge(node_a, node_b);
  21.421 +      }
  21.422 +
  21.423 +      Graph& graph;
  21.424 +    };
  21.425 +
  21.426 +    /// An empty erasable base graph class.
  21.427 +  
  21.428 +    /// This class provides beside the core graph features
  21.429 +    /// core erase functions for the graph structure.
  21.430 +    /// The most of the base graphs should be conform to this concept.
  21.431 +    class BaseErasableGraphComponent : virtual public BaseGraphComponent {
  21.432 +    public:
  21.433 +
  21.434 +      typedef BaseGraphComponent::Node Node;
  21.435 +      typedef BaseGraphComponent::Edge Edge;
  21.436 +
  21.437 +      /// Erase a Node from the graph.
  21.438 +      
  21.439 +      /// Erase a Node from the graph. This function should not
  21.440 +      /// erase edges connecting to the Node.
  21.441 +      void erase(const Node&) {}    
  21.442 +
  21.443 +      /// Erase an Edge from the graph.
  21.444 +
  21.445 +      /// Erase an Edge from the graph.
  21.446 +      ///
  21.447 +      void erase(const Edge&) {}
  21.448 +
  21.449 +    };
  21.450 +
  21.451 +    /// Concept check structure for ErasableBaseGraph.
  21.452 +
  21.453 +    /// Concept check structure for ErasableBaseGraph.
  21.454 +    ///
  21.455 +    template <typename Graph>
  21.456 +    struct BaseErasableGraphComponentConcept {
  21.457 +      void constraints() {
  21.458 +	typename Graph::Node node;
  21.459 +	graph.erase(node);
  21.460 +	typename Graph::Edge edge;
  21.461 +	graph.erase(edge);
  21.462 +      }
  21.463 +
  21.464 +      Graph& graph;
  21.465 +    };
  21.466 +
  21.467 +    /// An empty clearable base graph class.
  21.468 +  
  21.469 +    /// This class provides beside the core graph features
  21.470 +    /// core clear functions for the graph structure.
  21.471 +    /// The most of the base graphs should be conform to this concept.
  21.472 +    class BaseClearableGraphComponent : virtual public BaseGraphComponent {
  21.473 +    public:
  21.474 +
  21.475 +      /// Erase all the Nodes and Edges from the graph.
  21.476 +
  21.477 +      /// Erase all the Nodes and Edges from the graph.
  21.478 +      ///
  21.479 +      void clear() {}    
  21.480 +    };
  21.481 +
  21.482 +    /// Concept check function for ErasableBaseGraph.
  21.483 +
  21.484 +    /// Concept check function for ErasableBaseGraph.
  21.485 +    ///
  21.486 +    template <typename Graph>
  21.487 +    struct BaseClearableGraphComponentConcept {
  21.488 +      void constraints() {
  21.489 +	graph.clear();
  21.490 +      }
  21.491 +
  21.492 +      Graph& graph;
  21.493 +    };
  21.494 +
  21.495 +
  21.496 +    class IterableGraphComponent : virtual public BaseGraphComponent {
  21.497 +
  21.498 +    public:
  21.499 +    
  21.500 +      typedef IterableGraphComponent Graph;
  21.501 +
  21.502 +      typedef BaseGraphComponent::Node Node;
  21.503 +      typedef BaseGraphComponent::Edge Edge;
  21.504 +
  21.505 +      class NodeIt : public Node {
  21.506 +      public:
  21.507 +	NodeIt() {}
  21.508 +	NodeIt(Invalid) {}
  21.509 +	NodeIt(const Graph&) {}
  21.510 +
  21.511 +	NodeIt& operator++() { return *this; }
  21.512 +	//	Node operator*() const { return INVALID; }
  21.513 +
  21.514 +	bool operator==(const NodeIt&) { return true;}
  21.515 +	bool operator!=(const NodeIt&) { return true;}
  21.516 +      };
  21.517 +
  21.518 +      class EdgeIt : public Edge {
  21.519 +      public:
  21.520 +	EdgeIt() {}
  21.521 +	EdgeIt(Invalid) {}
  21.522 +	EdgeIt(const Graph&) {}
  21.523 +
  21.524 +	EdgeIt& operator++() { return *this; }
  21.525 +	//	Edge operator*() const { return INVALID; }
  21.526 +
  21.527 +	bool operator==(const EdgeIt&) { return true;}
  21.528 +	bool operator!=(const EdgeIt&) { return true;}
  21.529 +      };
  21.530 +
  21.531 +      class InEdgeIt : public Edge {
  21.532 +      public:
  21.533 +	InEdgeIt() {}
  21.534 +	InEdgeIt(Invalid) {}
  21.535 +	InEdgeIt(const Graph&, const Node&) {}
  21.536 +
  21.537 +	InEdgeIt& operator++() { return *this; }
  21.538 +	//	Edge operator*() const { return INVALID; }
  21.539 +
  21.540 +	bool operator==(const InEdgeIt&) { return true;}
  21.541 +	bool operator!=(const InEdgeIt&) { return true;}
  21.542 +      };
  21.543 +
  21.544 +      class OutEdgeIt : public Edge {
  21.545 +      public:
  21.546 +	OutEdgeIt() {}
  21.547 +	OutEdgeIt(Invalid) {}
  21.548 +	OutEdgeIt(const Graph&, const Node&) {}
  21.549 +
  21.550 +	OutEdgeIt& operator++() { return *this; }
  21.551 +	//	Edge operator*() const { return INVALID; }
  21.552 +
  21.553 +	bool operator==(const OutEdgeIt&) { return true;}
  21.554 +	bool operator!=(const OutEdgeIt&) { return true;}
  21.555 +      };
  21.556 +
  21.557 +    };
  21.558 +    
  21.559 +    template <typename Graph> 
  21.560 +    struct IterableGraphComponentConcept {
  21.561 +
  21.562 +      void constraints() {
  21.563 +  
  21.564 +	typedef typename Graph::Node Node;
  21.565 +	typedef typename Graph::NodeIt NodeIt;
  21.566 +	typedef typename Graph::Edge Edge;
  21.567 +	typedef typename Graph::EdgeIt EdgeIt;
  21.568 +	typedef typename Graph::InEdgeIt InEdgeIt;
  21.569 +	typedef typename Graph::OutEdgeIt OutEdgeIt;
  21.570 +  
  21.571 +	{
  21.572 +	  NodeIt it; 
  21.573 +	  NodeIt jt(it); 
  21.574 +	  NodeIt kt(INVALID); 
  21.575 +	  NodeIt lt(graph);
  21.576 +	  it = jt;
  21.577 +	  jt = ++it;
  21.578 +	  bool b;
  21.579 +	  b = (it == INVALID); 
  21.580 +	  b = (it != INVALID);
  21.581 +	  b = (it == jt); 
  21.582 +	  b = (it != jt);
  21.583 +	  Node node = it;
  21.584 +	  node = it;
  21.585 +	}
  21.586 +	{
  21.587 +	  EdgeIt it; 
  21.588 +	  EdgeIt jt(it); 
  21.589 +	  EdgeIt kt(INVALID); 
  21.590 +	  EdgeIt lt(graph);
  21.591 +	  it = jt;
  21.592 +	  jt = ++it;
  21.593 +	  bool b;
  21.594 +	  b = (it == INVALID); 
  21.595 +	  b = (it != INVALID);
  21.596 +	  b = (it == jt); 
  21.597 +	  b = (it != jt);
  21.598 +	  Edge edge = it;
  21.599 +	  edge = it;
  21.600 +	}
  21.601 +	{
  21.602 +	  InEdgeIt it; 
  21.603 +	  InEdgeIt jt(it); 
  21.604 +	  InEdgeIt kt(INVALID); 
  21.605 +	  Node node;
  21.606 +	  InEdgeIt lt(graph, node);
  21.607 +	  it = jt;
  21.608 +	  jt = ++it;
  21.609 +	  bool b;
  21.610 +	  b = (it == INVALID); 
  21.611 +	  b = (it != INVALID);
  21.612 +	  b = (it == jt); 
  21.613 +	  b = (it != jt);
  21.614 +	  Edge edge = it;
  21.615 +	  edge = it;
  21.616 +	}
  21.617 +	{
  21.618 +	  OutEdgeIt it; 
  21.619 +	  OutEdgeIt jt(it); 
  21.620 +	  OutEdgeIt kt(INVALID); 
  21.621 +	  Node node;
  21.622 +	  OutEdgeIt lt(graph, node);
  21.623 +	  it = jt;
  21.624 +	  jt = ++it;
  21.625 +	  bool b;
  21.626 +	  b = (it == INVALID); 
  21.627 +	  b = (it != INVALID);
  21.628 +	  b = (it == jt); 
  21.629 +	  b = (it != jt);
  21.630 +	  Edge edge = it;
  21.631 +	  edge = it;
  21.632 +	}
  21.633 +      }
  21.634 +      Graph& graph;
  21.635 +    };
  21.636 +
  21.637 +
  21.638 +    class IdMappableGraphComponent : virtual public BaseGraphComponent {
  21.639 +
  21.640 +      typedef IdMappableGraphComponent Graph;
  21.641 +
  21.642 +      typedef BaseGraphComponent::Node Node;
  21.643 +      typedef BaseGraphComponent::Edge Edge;
  21.644 +
  21.645 +    public:
  21.646 +
  21.647 +      class NodeIdMap : public ReadMap<Node, int> {
  21.648 +      public:
  21.649 +	NodeIdMap(const Graph&) {}
  21.650 +	int maxId() const { return -1;}
  21.651 +      };
  21.652 +
  21.653 +      class EdgeIdMap : public ReadMap<Edge, int> {
  21.654 +      public:
  21.655 +	EdgeIdMap(const Graph&) {}
  21.656 +	int maxId() const { return -1;}
  21.657 +      };
  21.658 +
  21.659 +    };
  21.660 +    
  21.661 +    template <typename Graph>
  21.662 +    struct IdMappableGraphComponentConcept {
  21.663 +      void constraints() {	
  21.664 +	{
  21.665 +	  typedef typename Graph::EdgeIdMap EdgeIdMap;
  21.666 +	  function_requires<ReadMapConcept<EdgeIdMap> >();
  21.667 +	  EdgeIdMap edge_map(graph);
  21.668 +	  int n = edge_map.maxId();
  21.669 +	  ignore_unused_variable_warning(n);
  21.670 +	}
  21.671 +	{
  21.672 +	  typedef typename Graph::NodeIdMap NodeIdMap;
  21.673 +	  function_requires<ReadMapConcept<NodeIdMap> >();
  21.674 +	  NodeIdMap node_map(graph);
  21.675 +	  int n = node_map.maxId();
  21.676 +	  ignore_unused_variable_warning(n);
  21.677 +	}
  21.678 +      }
  21.679 +      Graph& graph;
  21.680 +    };
  21.681 +
  21.682 +
  21.683 +    class MappableGraphComponent : virtual public BaseGraphComponent {
  21.684 +    public:
  21.685 +
  21.686 +      typedef MappableGraphComponent Graph;
  21.687 +
  21.688 +      typedef BaseGraphComponent::Node Node;
  21.689 +      typedef BaseGraphComponent::Edge Edge;
  21.690 +
  21.691 +      template <typename Value>
  21.692 +      class NodeMap : public ReferenceMap<Node, Value> {
  21.693 +      public:
  21.694 +	NodeMap(const Graph&) {}
  21.695 +	NodeMap(const Graph&, const Value&) {}
  21.696 +	NodeMap(const NodeMap&) {}
  21.697 +
  21.698 +	NodeMap& operator=(const NodeMap&) { return *this;}
  21.699 +	
  21.700 +      };
  21.701 +
  21.702 +      template <typename Value>
  21.703 +      class EdgeMap : public ReferenceMap<Edge, Value> {
  21.704 +      public:
  21.705 +	EdgeMap(const Graph&) {}
  21.706 +	EdgeMap(const Graph&, const Value&) {}
  21.707 +	EdgeMap(const EdgeMap&) {}
  21.708 +
  21.709 +	EdgeMap& operator=(const EdgeMap&) { return *this;}
  21.710 +	
  21.711 +      };
  21.712 +
  21.713 +    };
  21.714 +
  21.715 +    template <typename Graph>
  21.716 +    struct MappableGraphComponentConcept {
  21.717 +
  21.718 +      struct Type {
  21.719 +	int value;
  21.720 +	Type() : value(0) {}
  21.721 +	Type(int _v) : value(_v) {}
  21.722 +      };
  21.723 +
  21.724 +      void constraints() {
  21.725 +	{ // int map test
  21.726 +	  typedef typename Graph::template NodeMap<int> IntNodeMap;
  21.727 +	  function_requires<GraphMapConcept<IntNodeMap,Graph> >();
  21.728 +	} { // bool map test
  21.729 +	  typedef typename Graph::template NodeMap<bool> BoolNodeMap;
  21.730 +	  function_requires<GraphMapConcept<BoolNodeMap,Graph> >();
  21.731 +	} { // Type map test
  21.732 +	  typedef typename Graph::template NodeMap<Type> TypeNodeMap;
  21.733 +	  function_requires<GraphMapConcept<TypeNodeMap,Graph> >();
  21.734 +	} 
  21.735 +
  21.736 +	{ // int map test
  21.737 +	  typedef typename Graph::template EdgeMap<int> IntEdgeMap;
  21.738 +	  function_requires<GraphMapConcept<IntEdgeMap,Graph> >();
  21.739 +	} { // bool map test
  21.740 +	  typedef typename Graph::template EdgeMap<bool> BoolEdgeMap;
  21.741 +	  function_requires<GraphMapConcept<BoolEdgeMap,Graph> >();
  21.742 +	} { // Type map test
  21.743 +	  typedef typename Graph::template EdgeMap<Type> TypeEdgeMap;
  21.744 +	  function_requires<GraphMapConcept<TypeEdgeMap,Graph> >();
  21.745 +	} 
  21.746 +      }
  21.747 +
  21.748 +      Graph& graph;
  21.749 +    };
  21.750 +
  21.751 +
  21.752 +    class ExtendableGraphComponent : virtual public BaseGraphComponent {
  21.753 +    public:
  21.754 +
  21.755 +      typedef ExtendableGraphComponent Graph;
  21.756 +
  21.757 +      typedef BaseGraphComponent::Node Node;
  21.758 +      typedef BaseGraphComponent::Edge Edge;
  21.759 +
  21.760 +      Node addNode() {
  21.761 +	return INVALID;
  21.762 +      }
  21.763 +    
  21.764 +      Edge addEdge(const Node& from, const Node& to) {
  21.765 +	return INVALID;
  21.766 +      }
  21.767 +
  21.768 +    };
  21.769 +
  21.770 +    template <typename Graph>
  21.771 +    struct ExtendableGraphComponentConcept {
  21.772 +      void constraints() {
  21.773 +	typename Graph::Node node_a, node_b;
  21.774 +	node_a = graph.addNode();
  21.775 +	typename Graph::Edge edge;
  21.776 +	edge = graph.addEdge(node_a, node_b);      
  21.777 +      }
  21.778 +      Graph& graph;
  21.779 +    };
  21.780 +
  21.781 +    class ErasableGraphComponent : virtual public BaseGraphComponent {
  21.782 +    public:
  21.783 +
  21.784 +      typedef ErasableGraphComponent Graph;
  21.785 +
  21.786 +      typedef BaseGraphComponent::Node Node;
  21.787 +      typedef BaseGraphComponent::Edge Edge;
  21.788 +
  21.789 +      void erase(const Node&) {}    
  21.790 +      void erase(const Edge&) {}
  21.791 +
  21.792 +    };
  21.793 +
  21.794 +    template <typename Graph>
  21.795 +    struct ErasableGraphComponentConcept {
  21.796 +      void constraints() {
  21.797 +	typename Graph::Node node;
  21.798 +	graph.erase(node);
  21.799 +	typename Graph::Edge edge;
  21.800 +	graph.erase(edge);      
  21.801 +      }
  21.802 +
  21.803 +      Graph& graph;
  21.804 +    };
  21.805 +
  21.806 +    class ClearableGraphComponent : virtual public BaseGraphComponent {
  21.807 +    public:
  21.808 +
  21.809 +      typedef ClearableGraphComponent Graph;
  21.810 +
  21.811 +      typedef BaseGraphComponent::Node Node;
  21.812 +      typedef BaseGraphComponent::Edge Edge;
  21.813 +
  21.814 +      void clear() {}    
  21.815 +
  21.816 +    };
  21.817 +
  21.818 +    template <typename Graph>
  21.819 +    struct ClearableGraphComponentConcept {
  21.820 +      void constraints() {
  21.821 +	graph.clear();
  21.822 +      }
  21.823 +      Graph& graph;
  21.824 +    };
  21.825 +
  21.826 +  }
  21.827 +
  21.828 +}
  21.829 +
  21.830 +#endif
    22.1 --- a/src/lemon/skeletons/maps.h	Mon Oct 25 13:29:46 2004 +0000
    22.2 +++ b/src/lemon/skeletons/maps.h	Wed Oct 27 22:38:50 2004 +0000
    22.3 @@ -17,6 +17,8 @@
    22.4  #ifndef LEMON_MAPSKELETON_H
    22.5  #define LEMON_MAPSKELETON_H
    22.6  
    22.7 +#include <lemon/concept_check.h>
    22.8 +
    22.9  ///\ingroup skeletons
   22.10  ///\file
   22.11  ///\brief Map concepts checking classes for testing and documenting.
   22.12 @@ -113,6 +115,130 @@
   22.13        ReferenceMap() {}
   22.14      };
   22.15  
   22.16 +
   22.17 +    template<typename Item, typename T, typename Graph>
   22.18 +    class GraphMap : public ReadWriteMap<Item, T> {
   22.19 +      // I really, really don't like the idea that every graph should have
   22.20 +      // reference maps! --klao
   22.21 +
   22.22 +    private:
   22.23 +      // We state explicitly that graph maps have no default constructor?
   22.24 +      GraphMap();
   22.25 +
   22.26 +    public:
   22.27 +      explicit GraphMap(Graph const&) {}
   22.28 +      // value for initializing
   22.29 +      GraphMap(Graph const&, T) {}
   22.30 +
   22.31 +      // this probably should be required:
   22.32 +      GraphMap(GraphMap const&) {}
   22.33 +      GraphMap& operator=(GraphMap const&) { return *this; }
   22.34 +
   22.35 +      // but this is a absolute no-op! We should provide a more generic
   22.36 +      // graph-map-copy operation.
   22.37 +      //
   22.38 +      // template<typename TT>
   22.39 +      // GraphMap(GraphMap<TT> const&);
   22.40 +      //
   22.41 +      // template<typename TT>
   22.42 +      // GraphMap& operator=(const GraphMap<TT>&);
   22.43 +    };
   22.44 +
   22.45 +
   22.46 +    /****************  Concept-checking classes  ****************/
   22.47 +
   22.48 +    template<typename ReadMap>
   22.49 +    struct ReadMapConcept {
   22.50 +      typedef typename ReadMap::KeyType KeyType;
   22.51 +      typedef typename ReadMap::ValueType ValueType;
   22.52 +
   22.53 +      void constraints() {
   22.54 +	// No constraints for constructor.
   22.55 +
   22.56 +	// What are the requirement for the ValueType?
   22.57 +	// CopyConstructible? Assignable? None of these?
   22.58 +	ValueType v = m[k];
   22.59 +	v = m[k];
   22.60 +
   22.61 +	// FIXME:
   22.62 +	ignore_unused_variable_warning(v);
   22.63 +      }
   22.64 +
   22.65 +      ReadMap m;
   22.66 +      KeyType k;
   22.67 +    };
   22.68 +
   22.69 +    template<typename WriteMap>
   22.70 +    struct WriteMapConcept {
   22.71 +      typedef typename WriteMap::KeyType KeyType;
   22.72 +      typedef typename WriteMap::ValueType ValueType;
   22.73 +
   22.74 +      void constraints() {
   22.75 +	// No constraints for constructor.
   22.76 +
   22.77 +	m.set(k, v);
   22.78 +      }
   22.79 +
   22.80 +      WriteMap m;
   22.81 +      KeyType k;
   22.82 +      ValueType v;
   22.83 +    };
   22.84 +
   22.85 +    template<typename ReadWriteMap>
   22.86 +    struct ReadWriteMapConcept {
   22.87 +      void constraints() {
   22.88 +	function_requires< ReadMapConcept<ReadWriteMap> >();
   22.89 +	function_requires< WriteMapConcept<ReadWriteMap> >();
   22.90 +      }
   22.91 +    };
   22.92 +
   22.93 +    template<typename ReferenceMap>
   22.94 +    struct ReferenceMapConcept {
   22.95 +      typedef typename ReferenceMap::KeyType KeyType;
   22.96 +      typedef typename ReferenceMap::ValueType ValueType;
   22.97 +      typedef typename ReferenceMap::ReferenceType ReferenceType;
   22.98 +
   22.99 +      // What for is this?
  22.100 +      typedef typename ReferenceMap::ConstReferenceType ConstReferenceType;
  22.101 +
  22.102 +      void constraints() {
  22.103 +	function_requires< ReadWriteMapConcept<ReferenceMap> >();
  22.104 +
  22.105 +	m[k] = v;
  22.106 +	// Or should we require real reference?
  22.107 +	// Like this:
  22.108 +	// ValueType &vv = m[k];
  22.109 +	// ignore_unused_variable_warning(vv);
  22.110 +      }
  22.111 +
  22.112 +      ReferenceMap m;
  22.113 +      KeyType k;
  22.114 +      ValueType v;
  22.115 +    };
  22.116 +
  22.117 +    /// \todo GraphMapConceptCheck
  22.118 +
  22.119 +    template<typename GraphMap, typename Graph>
  22.120 +    struct GraphMapConcept {
  22.121 +      void constraints() {
  22.122 +	function_requires< ReadWriteMapConcept<GraphMap> >();
  22.123 +	// Construction with a graph parameter
  22.124 +	GraphMap a(g);
  22.125 +	// Ctor with a graph and a default value parameter
  22.126 +	GraphMap a2(g,t);
  22.127 +	// Copy ctor. Do we need it?
  22.128 +	GraphMap b=c;
  22.129 +	// Copy operator. Do we need it?
  22.130 +	a=b;
  22.131 +
  22.132 +	ignore_unused_variable_warning(a2);
  22.133 +      }
  22.134 +      const GraphMap &c;
  22.135 +      const Graph &g;
  22.136 +      const typename GraphMap::ValueType &t;
  22.137 +    };
  22.138 +    
  22.139 +
  22.140      // @}
  22.141  
  22.142    } //namespace skeleton
    23.1 --- a/src/lemon/smart_graph.h	Mon Oct 25 13:29:46 2004 +0000
    23.2 +++ b/src/lemon/smart_graph.h	Wed Oct 27 22:38:50 2004 +0000
    23.3 @@ -22,22 +22,28 @@
    23.4  ///\brief SmartGraph and SymSmartGraph classes.
    23.5  
    23.6  #include <vector>
    23.7 -#include <climits>
    23.8  
    23.9  #include <lemon/invalid.h>
   23.10  
   23.11 +#include <lemon/erasable_graph_extender.h>
   23.12 +#include <lemon/clearable_graph_extender.h>
   23.13 +#include <lemon/extendable_graph_extender.h>
   23.14  
   23.15 -#include <lemon/array_map.h>
   23.16 +#include <lemon/idmappable_graph_extender.h>
   23.17  
   23.18 -#include <lemon/map_registry.h>
   23.19 +#include <lemon/iterable_graph_extender.h>
   23.20  
   23.21 -#include <lemon/map_defines.h>
   23.22 +#include <lemon/alteration_observer_registry.h>
   23.23 +#include <lemon/default_map.h>
   23.24 +
   23.25 +
   23.26 +#include <lemon/graph_utils.h>
   23.27 +
   23.28  
   23.29  namespace lemon {
   23.30  
   23.31 -/// \addtogroup graphs
   23.32 -/// @{
   23.33 -//  class SymSmartGraph;
   23.34 +  /// \addtogroup graphs
   23.35 +  /// @{
   23.36  
   23.37    ///A smart graph class.
   23.38  
   23.39 @@ -56,7 +62,7 @@
   23.40    ///Of course it should be used as a stack. (Maybe X is not necessary.)
   23.41    ///
   23.42    ///\author Alpar Juttner
   23.43 -  class SmartGraph {
   23.44 +  class SmartGraphBase {
   23.45  
   23.46      struct NodeT 
   23.47      {
   23.48 @@ -77,25 +83,16 @@
   23.49      
   23.50    public:
   23.51  
   23.52 -    typedef SmartGraph Graph;
   23.53 +    typedef SmartGraphBase Graph;
   23.54  
   23.55      class Node;
   23.56      class Edge;
   23.57  
   23.58 -    class NodeIt;
   23.59 -    class EdgeIt;
   23.60 -    class OutEdgeIt;
   23.61 -    class InEdgeIt;
   23.62 -    
   23.63 -    // Create map registries.
   23.64 -    CREATE_MAP_REGISTRIES;
   23.65 -    // Create node and edge maps.
   23.66 -    CREATE_MAPS(ArrayMap);
   23.67      
   23.68    public:
   23.69  
   23.70 -    SmartGraph() : nodes(), edges() { }
   23.71 -    SmartGraph(const SmartGraph &_g) : nodes(_g.nodes), edges(_g.edges) { }
   23.72 +    SmartGraphBase() : nodes(), edges() { }
   23.73 +    SmartGraphBase(const SmartGraphBase &_g) : nodes(_g.nodes), edges(_g.edges) { }
   23.74      
   23.75      ///Number of nodes.
   23.76      int nodeNum() const { return nodes.size(); }
   23.77 @@ -116,15 +113,6 @@
   23.78      Node tail(Edge e) const { return edges[e.n].tail; }
   23.79      Node head(Edge e) const { return edges[e.n].head; }
   23.80  
   23.81 -    NodeIt& first(NodeIt& v) const { 
   23.82 -      v=NodeIt(*this); return v; }
   23.83 -    EdgeIt& first(EdgeIt& e) const { 
   23.84 -      e=EdgeIt(*this); return e; }
   23.85 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
   23.86 -      e=OutEdgeIt(*this,v); return e; }
   23.87 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
   23.88 -      e=InEdgeIt(*this,v); return e; }
   23.89 -
   23.90      /// Node ID.
   23.91      
   23.92      /// The ID of a valid Node is a nonnegative integer not greater than
   23.93 @@ -147,9 +135,6 @@
   23.94      Node addNode() {
   23.95        Node n; n.n=nodes.size();
   23.96        nodes.push_back(NodeT()); //FIXME: Hmmm...
   23.97 -
   23.98 -      
   23.99 -      node_maps.add(n);
  23.100        return n;
  23.101      }
  23.102      
  23.103 @@ -160,8 +145,6 @@
  23.104        edges[e.n].next_in=nodes[v.n].first_in;
  23.105        nodes[u.n].first_out=nodes[v.n].first_in=e.n;
  23.106  
  23.107 -      edge_maps.add(e);
  23.108 -
  23.109        return e;
  23.110      }
  23.111  
  23.112 @@ -182,24 +165,16 @@
  23.113      }
  23.114      
  23.115      void clear() {
  23.116 -      edge_maps.clear();
  23.117        edges.clear();
  23.118 -      node_maps.clear();
  23.119        nodes.clear();
  23.120      }
  23.121  
  23.122 +
  23.123      class Node {
  23.124 -      friend class SmartGraph;
  23.125 -      template <typename T> friend class NodeMap;
  23.126 -      
  23.127 -      friend class Edge;
  23.128 -      friend class OutEdgeIt;
  23.129 -      friend class InEdgeIt;
  23.130 -      friend class SymEdge;
  23.131 +      friend class SmartGraphBase;
  23.132  
  23.133      protected:
  23.134        int n;
  23.135 -      friend int SmartGraph::id(Node v); 
  23.136        Node(int nn) {n=nn;}
  23.137      public:
  23.138        Node() {}
  23.139 @@ -207,529 +182,77 @@
  23.140        bool operator==(const Node i) const {return n==i.n;}
  23.141        bool operator!=(const Node i) const {return n!=i.n;}
  23.142        bool operator<(const Node i) const {return n<i.n;}
  23.143 -      //      ///Validity check
  23.144 -      //      operator bool() { return n!=-1; }
  23.145      };
  23.146      
  23.147 -    class NodeIt : public Node {
  23.148 -      const SmartGraph *G;
  23.149 -      friend class SmartGraph;
  23.150 -    public:
  23.151 -      NodeIt() : Node() { }
  23.152 -      NodeIt(const SmartGraph& _G,Node n) : Node(n), G(&_G) { }
  23.153 -      NodeIt(Invalid i) : Node(i) { }
  23.154 -      NodeIt(const SmartGraph& _G) : Node(_G.nodes.size()?0:-1), G(&_G) { }
  23.155 -      NodeIt &operator++() {
  23.156 -	n=(n+2)%(G->nodes.size()+1)-1; 
  23.157 -	return *this; 
  23.158 -      }
  23.159 -//       ///Validity check
  23.160 -//       operator bool() { return Node::operator bool(); }      
  23.161 -    };
  23.162  
  23.163      class Edge {
  23.164 -      friend class SmartGraph;
  23.165 -      template <typename T> friend class EdgeMap;
  23.166 +      friend class SmartGraphBase;
  23.167  
  23.168 -      friend class SymSmartGraph;
  23.169 -      
  23.170 -      friend class Node;
  23.171 -      friend class NodeIt;
  23.172      protected:
  23.173        int n;
  23.174 -      friend int SmartGraph::id(Edge e);
  23.175        Edge(int nn) {n=nn;}
  23.176      public:
  23.177 -      /// An Edge with id \c n.
  23.178 -
  23.179        Edge() { }
  23.180        Edge (Invalid) { n=-1; }
  23.181        bool operator==(const Edge i) const {return n==i.n;}
  23.182        bool operator!=(const Edge i) const {return n!=i.n;}
  23.183        bool operator<(const Edge i) const {return n<i.n;}
  23.184 -//       ///Validity check
  23.185 -//       operator bool() { return n!=-1; }
  23.186 +    };
  23.187  
  23.188 -      ///Set the edge to that have ID \c ID.
  23.189 -      void setToId(int id) { n=id; }
  23.190 -   };
  23.191 +    void first(Node& node) const {
  23.192 +      node.n = nodes.size() - 1;
  23.193 +    }
  23.194 +
  23.195 +    static void next(Node& node) {
  23.196 +      --node.n;
  23.197 +    }
  23.198 +
  23.199 +    void first(Edge& edge) const {
  23.200 +      edge.n = edges.size() - 1;
  23.201 +    }
  23.202 +
  23.203 +    static void next(Edge& edge) {
  23.204 +      --edge.n;
  23.205 +    }
  23.206 +
  23.207 +    void firstOut(Edge& edge, const Node& node) const {
  23.208 +      edge.n = nodes[node.n].first_out;
  23.209 +    }
  23.210 +
  23.211 +    void nextOut(Edge& edge) const {
  23.212 +      edge.n = edges[edge.n].next_out;
  23.213 +    }
  23.214 +
  23.215 +    void firstIn(Edge& edge, const Node& node) const {
  23.216 +      edge.n = nodes[node.n].first_in;
  23.217 +    }
  23.218      
  23.219 -    class EdgeIt : public Edge {
  23.220 -      const SmartGraph *G;
  23.221 -      friend class SmartGraph;
  23.222 -    public:
  23.223 -      EdgeIt(const SmartGraph& _G) : Edge(_G.edges.size()-1), G(&_G) { }
  23.224 -      EdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
  23.225 -      EdgeIt (Invalid i) : Edge(i) { }
  23.226 -      EdgeIt() : Edge() { }
  23.227 -      EdgeIt &operator++() { --n; return *this; }
  23.228 -//       ///Validity check
  23.229 -//       operator bool() { return Edge::operator bool(); }      
  23.230 -    };
  23.231 -    
  23.232 -    class OutEdgeIt : public Edge {
  23.233 -      const SmartGraph *G;
  23.234 -      friend class SmartGraph;
  23.235 -    public: 
  23.236 -      OutEdgeIt() : Edge() { }
  23.237 -      OutEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
  23.238 -      OutEdgeIt (Invalid i) : Edge(i) { }
  23.239 -
  23.240 -      OutEdgeIt(const SmartGraph& _G,const Node v)
  23.241 -	: Edge(_G.nodes[v.n].first_out), G(&_G) {}
  23.242 -      OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
  23.243 -//       ///Validity check
  23.244 -//       operator bool() { return Edge::operator bool(); }      
  23.245 -    };
  23.246 -    
  23.247 -    class InEdgeIt : public Edge {
  23.248 -      const SmartGraph *G;
  23.249 -      friend class SmartGraph;
  23.250 -    public: 
  23.251 -      InEdgeIt() : Edge() { }
  23.252 -      InEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
  23.253 -      InEdgeIt (Invalid i) : Edge(i) { }
  23.254 -      InEdgeIt(const SmartGraph& _G,Node v)
  23.255 -	: Edge(_G.nodes[v.n].first_in), G(&_G) { }
  23.256 -      InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
  23.257 -//       ///Validity check
  23.258 -//       operator bool() { return Edge::operator bool(); }      
  23.259 -    };
  23.260 +    void nextIn(Edge& edge) const {
  23.261 +      edge.n = edges[edge.n].next_in;
  23.262 +    }
  23.263  
  23.264    };
  23.265  
  23.266 +  typedef AlterableGraphExtender<SmartGraphBase> AlterableSmartGraphBase;
  23.267 +  typedef IterableGraphExtender<AlterableSmartGraphBase> IterableSmartGraphBase;
  23.268 +  typedef IdMappableGraphExtender<IterableSmartGraphBase> IdMappableSmartGraphBase;
  23.269 +  typedef DefaultMappableGraphExtender<IdMappableSmartGraphBase> MappableSmartGraphBase;
  23.270 +  typedef ExtendableGraphExtender<MappableSmartGraphBase> ExtendableSmartGraphBase;
  23.271 +  typedef ClearableGraphExtender<ExtendableSmartGraphBase> ClearableSmartGraphBase;
  23.272  
  23.273 +  typedef ClearableSmartGraphBase SmartGraph;
  23.274  
  23.275 -  class SymSmartGraph : public SmartGraph {
  23.276 -    typedef SmartGraph Parent;
  23.277 -  public:
  23.278  
  23.279 -    typedef SymSmartGraph Graph;
  23.280 +  template <>
  23.281 +  int countNodes<SmartGraph>(const SmartGraph& graph) {
  23.282 +    return graph.nodeNum();
  23.283 +  }
  23.284  
  23.285 -    typedef SmartGraph::Node Node;
  23.286 -    typedef SmartGraph::NodeIt NodeIt;
  23.287 +  template <>
  23.288 +  int countEdges<SmartGraph>(const SmartGraph& graph) {
  23.289 +    return graph.edgeNum();
  23.290 +  }
  23.291  
  23.292 -    class SymEdge;
  23.293 -    class SymEdgeIt;
  23.294 -
  23.295 -    class Edge;
  23.296 -    class EdgeIt;
  23.297 -    class OutEdgeIt;
  23.298 -    class InEdgeIt;
  23.299 -
  23.300 -    template <typename Value>
  23.301 -    class NodeMap : public Parent::NodeMap<Value> {      
  23.302 -    public:
  23.303 -      NodeMap(const SymSmartGraph& g) 
  23.304 -	: SymSmartGraph::Parent::NodeMap<Value>(g) {}
  23.305 -      NodeMap(const SymSmartGraph& g, Value v) 
  23.306 -	: SymSmartGraph::Parent::NodeMap<Value>(g, v) {}
  23.307 -      template<typename TT> 
  23.308 -      NodeMap(const NodeMap<TT>& copy) 
  23.309 -	: SymSmartGraph::Parent::NodeMap<Value>(copy) { }            
  23.310 -    };
  23.311 -
  23.312 -    template <typename Value>
  23.313 -    class SymEdgeMap : public Parent::EdgeMap<Value> {
  23.314 -    public:
  23.315 -      typedef SymEdge KeyType;
  23.316 -
  23.317 -      SymEdgeMap(const SymSmartGraph& g) 
  23.318 -	: SymSmartGraph::Parent::EdgeMap<Value>(g) {}
  23.319 -      SymEdgeMap(const SymSmartGraph& g, Value v) 
  23.320 -	: SymSmartGraph::Parent::EdgeMap<Value>(g, v) {}
  23.321 -      template<typename TT> 
  23.322 -      SymEdgeMap(const SymEdgeMap<TT>& copy) 
  23.323 -	: SymSmartGraph::Parent::EdgeMap<Value>(copy) { }
  23.324 -      
  23.325 -    };
  23.326 -
  23.327 -    // Create edge map registry.
  23.328 -    CREATE_EDGE_MAP_REGISTRY;
  23.329 -    // Create edge maps.
  23.330 -    CREATE_EDGE_MAP(ArrayMap);
  23.331 -
  23.332 -    class Edge {
  23.333 -      friend class SymSmartGraph;
  23.334 -      friend class SymSmartGraph::EdgeIt;
  23.335 -      friend class SymSmartGraph::OutEdgeIt;
  23.336 -      friend class SymSmartGraph::InEdgeIt;
  23.337 -      
  23.338 -    protected:
  23.339 -      int id;
  23.340 -
  23.341 -      Edge(int pid) { id = pid; }
  23.342 -
  23.343 -    public:
  23.344 -      /// An Edge with id \c n.
  23.345 -
  23.346 -      Edge() { }
  23.347 -      Edge (Invalid) { id = -1; }
  23.348 -
  23.349 -      operator SymEdge(){ return SymEdge(id >> 1);}
  23.350 -      
  23.351 -      bool operator==(const Edge i) const {return id == i.id;}
  23.352 -      bool operator!=(const Edge i) const {return id != i.id;}
  23.353 -      bool operator<(const Edge i) const {return id < i.id;}
  23.354 -      //      ///Validity check
  23.355 -      //      operator bool() { return n!=-1; }
  23.356 -    };
  23.357 -
  23.358 -    class SymEdge : public SmartGraph::Edge {
  23.359 -      friend class SymSmartGraph;
  23.360 -      friend class SymSmartGraph::Edge;
  23.361 -      typedef SmartGraph::Edge Parent;
  23.362 -
  23.363 -    protected:      
  23.364 -      SymEdge(int pid) : Parent(pid) {}
  23.365 -    public:
  23.366 -
  23.367 -      SymEdge() { }
  23.368 -      SymEdge(const SmartGraph::Edge& i) : Parent(i) {} 
  23.369 -      SymEdge (Invalid) : Parent(INVALID) {}
  23.370 -
  23.371 -    };
  23.372 -
  23.373 -    class OutEdgeIt {
  23.374 -      Parent::OutEdgeIt out;
  23.375 -      Parent::InEdgeIt in;      
  23.376 -    public: 
  23.377 -      OutEdgeIt() {}
  23.378 -      OutEdgeIt(const SymSmartGraph& g, Edge e) { 
  23.379 -	if ((e.id & 1) == 0) {	
  23.380 -	  out = Parent::OutEdgeIt(g, SymEdge(e));
  23.381 -	  in = Parent::InEdgeIt(g, g.tail(e));
  23.382 -	} else {
  23.383 -	  out = Parent::OutEdgeIt(INVALID);
  23.384 -	  in = Parent::InEdgeIt(g, SymEdge(e));
  23.385 -	}
  23.386 -      }
  23.387 -      OutEdgeIt (Invalid i) : out(INVALID), in(INVALID) { }
  23.388 -
  23.389 -      OutEdgeIt(const SymSmartGraph& g, const Node v)
  23.390 -	: out(g, v), in(g, v) {}
  23.391 -      OutEdgeIt &operator++() { 
  23.392 -	if (out != INVALID) {
  23.393 -	  ++out;
  23.394 -	} else {
  23.395 -	  ++in;
  23.396 -	}
  23.397 -	return *this; 
  23.398 -      }
  23.399 -
  23.400 -      operator Edge() const {
  23.401 -	if (out == INVALID && in == INVALID) return INVALID;
  23.402 -	return out != INVALID ? forward(out) : backward(in);
  23.403 -      }
  23.404 -
  23.405 -      bool operator==(const Edge i) const {return Edge(*this) == i;}
  23.406 -      bool operator!=(const Edge i) const {return Edge(*this) != i;}
  23.407 -      bool operator<(const Edge i) const {return Edge(*this) < i;}
  23.408 -    };
  23.409 -
  23.410 -    class InEdgeIt {
  23.411 -      Parent::OutEdgeIt out;
  23.412 -      Parent::InEdgeIt in;      
  23.413 -    public: 
  23.414 -      InEdgeIt() {}
  23.415 -      InEdgeIt(const SymSmartGraph& g, Edge e) { 
  23.416 -	if ((e.id & 1) == 0) {	
  23.417 -	  out = Parent::OutEdgeIt(g, SymEdge(e));
  23.418 -	  in = Parent::InEdgeIt(g, g.tail(e));
  23.419 -	} else {
  23.420 -	  out = Parent::OutEdgeIt(INVALID);
  23.421 -	  in = Parent::InEdgeIt(g, SymEdge(e));
  23.422 -	}
  23.423 -      }
  23.424 -      InEdgeIt (Invalid i) : out(INVALID), in(INVALID) { }
  23.425 -
  23.426 -      InEdgeIt(const SymSmartGraph& g, const Node v)
  23.427 -	: out(g, v), in(g, v) {}
  23.428 -
  23.429 -      InEdgeIt &operator++() { 
  23.430 -	if (out != INVALID) {
  23.431 -	  ++out;
  23.432 -	} else {
  23.433 -	  ++in;
  23.434 -	}
  23.435 -	return *this; 
  23.436 -      }
  23.437 -
  23.438 -      operator Edge() const {
  23.439 -	if (out == INVALID && in == INVALID) return INVALID;
  23.440 -	return out != INVALID ? backward(out) : forward(in);
  23.441 -      }
  23.442 -
  23.443 -      bool operator==(const Edge i) const {return Edge(*this) == i;}
  23.444 -      bool operator!=(const Edge i) const {return Edge(*this) != i;}
  23.445 -      bool operator<(const Edge i) const {return Edge(*this) < i;}
  23.446 -    };
  23.447 -
  23.448 -    class SymEdgeIt : public Parent::EdgeIt {
  23.449 -
  23.450 -    public:
  23.451 -      SymEdgeIt() {}
  23.452 -
  23.453 -      SymEdgeIt(const SymSmartGraph& g) 
  23.454 -	: SymSmartGraph::Parent::EdgeIt(g) {}
  23.455 -
  23.456 -      SymEdgeIt(const SymSmartGraph& g, SymEdge e) 
  23.457 -	: SymSmartGraph::Parent::EdgeIt(g, e) {}
  23.458 -
  23.459 -      SymEdgeIt(Invalid i) 
  23.460 -	: SymSmartGraph::Parent::EdgeIt(INVALID) {}
  23.461 -
  23.462 -      SymEdgeIt& operator++() {
  23.463 -	SymSmartGraph::Parent::EdgeIt::operator++();
  23.464 -	return *this;
  23.465 -      }
  23.466 -
  23.467 -      operator SymEdge() const {
  23.468 -	return SymEdge
  23.469 -	  (static_cast<const SymSmartGraph::Parent::EdgeIt&>(*this));
  23.470 -      }
  23.471 -      bool operator==(const SymEdge i) const {return SymEdge(*this) == i;}
  23.472 -      bool operator!=(const SymEdge i) const {return SymEdge(*this) != i;}
  23.473 -      bool operator<(const SymEdge i) const {return SymEdge(*this) < i;}
  23.474 -    };
  23.475 -
  23.476 -    class EdgeIt {
  23.477 -      SymEdgeIt it;
  23.478 -      bool fw;
  23.479 -    public:
  23.480 -      EdgeIt(const SymSmartGraph& g) : it(g), fw(true) {}
  23.481 -      EdgeIt (Invalid i) : it(i) { }
  23.482 -      EdgeIt(const SymSmartGraph& g, Edge e) 
  23.483 -	: it(g, SymEdge(e)), fw(id(e) & 1 == 0) { }
  23.484 -      EdgeIt() { }
  23.485 -      EdgeIt& operator++() {
  23.486 -	fw = !fw;
  23.487 -	if (fw) ++it;
  23.488 -	return *this;
  23.489 -      }
  23.490 -      operator Edge() const {
  23.491 -	if (it == INVALID) return INVALID;
  23.492 -	return fw ? forward(it) : backward(it);
  23.493 -      }
  23.494 -      bool operator==(const Edge i) const {return Edge(*this) == i;}
  23.495 -      bool operator!=(const Edge i) const {return Edge(*this) != i;}
  23.496 -      bool operator<(const Edge i) const {return Edge(*this) < i;}
  23.497 -
  23.498 -    };
  23.499 -
  23.500 -    ///Number of nodes.
  23.501 -    int nodeNum() const { return Parent::nodeNum(); }
  23.502 -    ///Number of edges.
  23.503 -    int edgeNum() const { return 2*Parent::edgeNum(); }
  23.504 -    ///Number of symmetric edges.
  23.505 -    int symEdgeNum() const { return Parent::edgeNum(); }
  23.506 -
  23.507 -    /// Maximum node ID.
  23.508 -    
  23.509 -    /// Maximum node ID.
  23.510 -    ///\sa id(Node)
  23.511 -    int maxNodeId() const { return Parent::maxNodeId(); } 
  23.512 -    /// Maximum edge ID.
  23.513 -    
  23.514 -    /// Maximum edge ID.
  23.515 -    ///\sa id(Edge)
  23.516 -    int maxEdgeId() const { return 2*Parent::maxEdgeId(); }
  23.517 -    /// Maximum symmetric edge ID.
  23.518 -    
  23.519 -    /// Maximum symmetric edge ID.
  23.520 -    ///\sa id(SymEdge)
  23.521 -    int maxSymEdgeId() const { return Parent::maxEdgeId(); }
  23.522 -
  23.523 -
  23.524 -    Node tail(Edge e) const { 
  23.525 -      return (e.id & 1) == 0 ? 
  23.526 -	Parent::tail(SymEdge(e)) : Parent::head(SymEdge(e)); 
  23.527 -    }
  23.528 -
  23.529 -    Node head(Edge e) const { 
  23.530 -      return (e.id & 1) == 0 ? 
  23.531 -	Parent::head(SymEdge(e)) : Parent::tail(SymEdge(e)); 
  23.532 -    }
  23.533 -
  23.534 -    Node tail(SymEdge e) const { 
  23.535 -      return Parent::tail(e); 
  23.536 -    }
  23.537 -
  23.538 -    Node head(SymEdge e) const { 
  23.539 -      return Parent::head(e); 
  23.540 -    }
  23.541 -
  23.542 -    NodeIt& first(NodeIt& v) const { 
  23.543 -      v=NodeIt(*this); return v; }
  23.544 -    EdgeIt& first(EdgeIt& e) const { 
  23.545 -      e=EdgeIt(*this); return e; }
  23.546 -    SymEdgeIt& first(SymEdgeIt& e) const {
  23.547 -      e=SymEdgeIt(*this); return e; }
  23.548 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  23.549 -      e=OutEdgeIt(*this,v); return e; }
  23.550 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  23.551 -      e=InEdgeIt(*this,v); return e; }
  23.552 -
  23.553 -    /// Node ID.
  23.554 -    
  23.555 -    /// The ID of a valid Node is a nonnegative integer not greater than
  23.556 -    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  23.557 -    /// and the greatest node ID can be actually less then \ref maxNodeId().
  23.558 -    ///
  23.559 -    /// The ID of the \ref INVALID node is -1.
  23.560 -    ///\return The ID of the node \c v. 
  23.561 -    static int id(Node v) { return Parent::id(v); }
  23.562 -    /// Edge ID.
  23.563 -    
  23.564 -    /// The ID of a valid Edge is a nonnegative integer not greater than
  23.565 -    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  23.566 -    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  23.567 -    ///
  23.568 -    /// The ID of the \ref INVALID edge is -1.
  23.569 -    ///\return The ID of the edge \c e. 
  23.570 -    static int id(Edge e) { return e.id; }
  23.571 -
  23.572 -    /// The ID of a valid SymEdge is a nonnegative integer not greater than
  23.573 -    /// \ref maxSymEdgeId(). The range of the ID's is not surely continuous
  23.574 -    /// and the greatest edge ID can be actually less then \ref maxSymEdgeId().
  23.575 -    ///
  23.576 -    /// The ID of the \ref INVALID symmetric edge is -1.
  23.577 -    ///\return The ID of the edge \c e. 
  23.578 -    static int id(SymEdge e) { return Parent::id(e); }
  23.579 -
  23.580 -    /// Adds a new node to the graph.
  23.581 -
  23.582 -    /// \warning It adds the new node to the front of the list.
  23.583 -    /// (i.e. the lastly added node becomes the first.)
  23.584 -    Node addNode() {
  23.585 -      return Parent::addNode();
  23.586 -    }
  23.587 -    
  23.588 -    SymEdge addEdge(Node u, Node v) {
  23.589 -      SymEdge se = Parent::addEdge(u, v);
  23.590 -      edge_maps.add(forward(se));
  23.591 -      edge_maps.add(backward(se));
  23.592 -      return se;
  23.593 -    }
  23.594 -    
  23.595 -    /// Finds an edge between two nodes.
  23.596 -
  23.597 -    /// Finds an edge from node \c u to node \c v.
  23.598 -    ///
  23.599 -    /// If \c prev is \ref INVALID (this is the default value), then
  23.600 -    /// It finds the first edge from \c u to \c v. Otherwise it looks for
  23.601 -    /// the next edge from \c u to \c v after \c prev.
  23.602 -    /// \return The found edge or INVALID if there is no such an edge.
  23.603 -    Edge findEdge(Node u, Node v, Edge prev = INVALID) 
  23.604 -    {     
  23.605 -      if (prev == INVALID || id(prev) & 1 == 0) {
  23.606 -	SymEdge se = Parent::findEdge(u, v, SymEdge(prev));
  23.607 -	if (se != INVALID) return forward(se);
  23.608 -      } else {
  23.609 -	SymEdge se = Parent::findEdge(v, u, SymEdge(prev));
  23.610 -	if (se != INVALID) return backward(se);	
  23.611 -      }
  23.612 -      return INVALID;
  23.613 -    }
  23.614 -
  23.615 -//     /// Finds an symmetric edge between two nodes.
  23.616 -
  23.617 -//     /// Finds an symmetric edge from node \c u to node \c v.
  23.618 -//     ///
  23.619 -//     /// If \c prev is \ref INVALID (this is the default value), then
  23.620 -//     /// It finds the first edge from \c u to \c v. Otherwise it looks for
  23.621 -//     /// the next edge from \c u to \c v after \c prev.
  23.622 -//     /// \return The found edge or INVALID if there is no such an edge.
  23.623 -
  23.624 -//     SymEdge findEdge(Node u, Node v, SymEdge prev = INVALID) 
  23.625 -//     {     
  23.626 -//       if (prev == INVALID || id(prev) & 1 == 0) {
  23.627 -// 	SymEdge se = Parent::findEdge(u, v, SymEdge(prev));
  23.628 -// 	if (se != INVALID) return se;
  23.629 -//       } else {
  23.630 -// 	SymEdge se = Parent::findEdge(v, u, SymEdge(prev));
  23.631 -// 	if (se != INVALID) return se;	
  23.632 -//       }
  23.633 -//       return INVALID;
  23.634 -//     }
  23.635 -    
  23.636 -  public:
  23.637 -
  23.638 -    void clear() {
  23.639 -      edge_maps.clear();
  23.640 -      Parent::clear();
  23.641 -    }
  23.642 -
  23.643 -    static Edge opposite(Edge e) {
  23.644 -      return Edge(id(e) ^ 1);
  23.645 -    }
  23.646 -
  23.647 -    static Edge forward(SymEdge e) {
  23.648 -      return Edge(id(e) << 1);
  23.649 -    }
  23.650 -
  23.651 -    static Edge backward(SymEdge e) {
  23.652 -      return Edge((id(e) << 1) | 1);
  23.653 -    }
  23.654 -
  23.655 -  };
  23.656 -  ///Graph for bidirectional edges.
  23.657 -
  23.658 -  ///The purpose of this graph structure is to handle graphs
  23.659 -  ///having bidirectional edges. Here the function \c addEdge(u,v) adds a pair
  23.660 -  ///of oppositely directed edges.
  23.661 -  ///There is a new edge map type called
  23.662 -  ///\ref SymSmartGraph::SymEdgeMap "SymEdgeMap"
  23.663 -  ///that complements this
  23.664 -  ///feature by
  23.665 -  ///storing shared values for the edge pairs. The usual
  23.666 -  ///\ref Graph::EdgeMap "EdgeMap"
  23.667 -  ///can be used
  23.668 -  ///as well.
  23.669 -  ///
  23.670 -  ///The oppositely directed edge can also be obtained easily
  23.671 -  ///using \ref opposite.
  23.672 -  ///\warning It shares the similarity with \ref SmartGraph that
  23.673 -  ///it is not possible to delete edges or nodes from the graph.
  23.674 -  //\sa SmartGraph.
  23.675 -
  23.676 -  /*  class SymSmartGraph : public SmartGraph
  23.677 -  {
  23.678 -  public:
  23.679 -    typedef SymSmartGraph Graph;
  23.680 -
  23.681 -    // Create symmetric map registry.
  23.682 -    CREATE_SYM_EDGE_MAP_REGISTRY;
  23.683 -    // Create symmetric edge map.
  23.684 -    CREATE_SYM_EDGE_MAP(ArrayMap);
  23.685 -
  23.686 -
  23.687 -    SymSmartGraph() : SmartGraph() { }
  23.688 -    SymSmartGraph(const SmartGraph &_g) : SmartGraph(_g) { }
  23.689 -    ///Adds a pair of oppositely directed edges to the graph.
  23.690 -    Edge addEdge(Node u, Node v)
  23.691 -    {
  23.692 -      Edge e = SmartGraph::addEdge(u,v);
  23.693 -      Edge f = SmartGraph::addEdge(v,u);
  23.694 -      sym_edge_maps.add(e);
  23.695 -      sym_edge_maps.add(f);
  23.696 -      return e;
  23.697 -    }
  23.698 -
  23.699 -    ///The oppositely directed edge.
  23.700 -
  23.701 -    ///Returns the oppositely directed
  23.702 -    ///pair of the edge \c e.
  23.703 -    static Edge opposite(Edge e)
  23.704 -    {
  23.705 -      Edge f;
  23.706 -      f.n = e.n - 2*(e.n%2) + 1;
  23.707 -      return f;
  23.708 -    }
  23.709 -    
  23.710 -
  23.711 -    };*/
  23.712 -  
  23.713    /// @}  
  23.714  } //namespace lemon
  23.715  
    24.1 --- a/src/lemon/suurballe.h	Mon Oct 25 13:29:46 2004 +0000
    24.2 +++ b/src/lemon/suurballe.h	Wed Oct 27 22:38:50 2004 +0000
    24.3 @@ -125,12 +125,10 @@
    24.4        paths.resize(k);
    24.5        for (int j=0; j<i; ++j){
    24.6  	Node n=s;
    24.7 -	OutEdgeIt e;
    24.8  
    24.9  	while (n!=t){
   24.10  
   24.11 -
   24.12 -	  G.first(e,n);
   24.13 +	  OutEdgeIt e(G, n);
   24.14  	  
   24.15  	  while (!reversed[e]){
   24.16  	    ++e;
    25.1 --- a/src/lemon/vector_map.h	Mon Oct 25 13:29:46 2004 +0000
    25.2 +++ b/src/lemon/vector_map.h	Wed Oct 27 22:38:50 2004 +0000
    25.3 @@ -18,9 +18,9 @@
    25.4  #define LEMON_VECTOR_MAP_H
    25.5  
    25.6  #include <vector>
    25.7 +#include <algorithm>
    25.8  
    25.9 -#include <lemon/map_iterator.h>
   25.10 -#include <lemon/map_bits.h>
   25.11 +#include <lemon/alteration_observer_registry.h>
   25.12  
   25.13  ///\ingroup graphmaps
   25.14  ///\file
   25.15 @@ -31,34 +31,41 @@
   25.16    /// \addtogroup graphmaps
   25.17    /// @{
   25.18    
   25.19 -  /** The VectorMap template class is graph map structure what
   25.20 -   *  automatically updates the map when a key is added to or erased from
   25.21 -   *  the map. This map factory uses the allocators to implement 
   25.22 -   *  the container functionality. This map factory
   25.23 -   *  uses the std::vector to implement the container function.
   25.24 -   *
   25.25 -   *  \param MapRegistry The MapRegistry that the maps will belong to.
   25.26 -   *  \param Value The value type of the map.
   25.27 -   * 
   25.28 -   *  \author Balazs Dezso
   25.29 -   */
   25.30 -	
   25.31 -  template <typename MapRegistry, typename Value>
   25.32 -  class VectorMap : public MapRegistry::MapBase {
   25.33 -    template <typename MR, typename T> friend class VectorMap;
   25.34 +  /// The VectorMap template class is graph map structure what
   25.35 +  /// automatically updates the map when a key is added to or erased from
   25.36 +  /// the map. This map factory uses the allocators to implement 
   25.37 +  /// the container functionality. This map factory
   25.38 +  /// uses the std::vector to implement the container function.
   25.39 +  ///
   25.40 +  /// \param Registry The AlterationObserverRegistry that will notify this map.
   25.41 +  /// \param IdMap The IdMap type of the graph items.
   25.42 +  /// \param Value The value type of the map.
   25.43 +  /// 
   25.44 +  /// \author Balazs Dezso
   25.45 +  	
   25.46 +
   25.47 +  template <typename _Graph, 
   25.48 +	    typename _Item,
   25.49 +	    typename _IdMap,
   25.50 +	    typename _Value>
   25.51 +  class VectorMap : public AlterationObserverRegistry<_Item>::ObserverBase {
   25.52    public:
   25.53  		
   25.54 -    /// The graph type of the maps. 
   25.55 -    typedef typename MapRegistry::Graph Graph;
   25.56 -    /// The key type of the maps.
   25.57 -    typedef typename MapRegistry::KeyType KeyType;
   25.58 -    /// The iterator to iterate on the keys.
   25.59 -    typedef typename MapRegistry::KeyIt KeyIt;
   25.60 +    /// The graph type of the map. 
   25.61 +    typedef _Graph Graph;
   25.62 +    /// The key type of the map.
   25.63 +    typedef _Item KeyType;
   25.64 +    /// The id map type of the map.
   25.65 +    typedef _IdMap IdMap;
   25.66 +    /// The registry type of the map.
   25.67 +    typedef AlterationObserverRegistry<_Item> Registry;
   25.68 +    /// The value type of the map.
   25.69 +    typedef _Value Value;
   25.70  
   25.71      /// The map type.
   25.72      typedef VectorMap Map;
   25.73 -    /// The MapBase of the Map which implements the core regisitry function.
   25.74 -    typedef typename MapRegistry::MapBase MapBase;
   25.75 +    /// The base class of the map.
   25.76 +    typedef typename Registry::ObserverBase Parent;
   25.77  
   25.78    private:
   25.79  		
   25.80 @@ -67,7 +74,6 @@
   25.81  
   25.82    public:
   25.83  
   25.84 -
   25.85      /// The value type of the map.
   25.86      typedef Value ValueType;
   25.87      /// The reference type of the map;
   25.88 @@ -82,95 +88,98 @@
   25.89      /// The pointer type of the map;
   25.90      typedef typename Container::const_pointer ConstPointerType;
   25.91  
   25.92 -    /// Constructor to attach the new map into a registry.
   25.93 +    /// Constructor to attach the new map into the registry.
   25.94  
   25.95 -    /** Constructor to attach the new map into a registry.
   25.96 -     *  It adds all the nodes or edges of the graph to the map.
   25.97 -     */
   25.98 -    VectorMap(const Graph& g, MapRegistry& r) 
   25.99 -      : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1) {}
  25.100 +    /// It construates a map and attachs it into the registry.
  25.101 +    /// It adds all the items of the graph to the map.
  25.102 +     
  25.103 +    VectorMap(const Graph& _g, Registry& _r) : graph(&_g) {
  25.104 +      attach(_r);
  25.105 +      build();
  25.106 +    }
  25.107  
  25.108      /// Constructor uses given value to initialize the map. 
  25.109  
  25.110 -    /** Constructor uses given value to initialize the map. 
  25.111 -     *  It adds all the nodes or edges of the graph to the map.
  25.112 -     */
  25.113 -    VectorMap(const Graph& g, MapRegistry& r, const Value& v) 
  25.114 -      : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1, v) {}
  25.115 +    /// It construates a map uses a given value to initialize the map. 
  25.116 +    /// It adds all the items of the graph to the map.
  25.117 +     
  25.118 +    VectorMap(const Graph& g, Registry& r, const Value& v) : graph(&g) { 
  25.119 +      attach(r);
  25.120 +      container.resize(IdMap(*graph).maxId() + 1, v);
  25.121 +    }
  25.122  
  25.123 -    /// Assign operator to copy a map of an other map type.
  25.124 -
  25.125 -    /** Assign operator to copy a map of an other map type.
  25.126 -     *  This map's value type must be assignable by the other
  25.127 -     *  map type's value type.
  25.128 -     */
  25.129 -    template <typename TT>
  25.130 -    VectorMap(const VectorMap<MapRegistry, TT>& c) 
  25.131 -      : MapBase(c), container(c.container.size()) {
  25.132 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  25.133 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  25.134 -	container[id] = c.container[id];
  25.135 +    VectorMap(const VectorMap& copy) : graph(copy.getGraph()) {
  25.136 +      if (copy.attached()) {
  25.137 +	attach(*copy.getRegistry());
  25.138 +	container = copy.container;
  25.139        }
  25.140      }
  25.141  
  25.142 -    /// Assign operator to copy a map of an other map type.
  25.143  
  25.144 -    /** Assign operator to copy a map of an other map type.
  25.145 -     *  This map's value type must be assignable by the other
  25.146 -     *  map type's value type.
  25.147 +    /** Assign operator to copy a map of the same map type.
  25.148       */
  25.149 -    template <typename TT>
  25.150 -    VectorMap& operator=(const VectorMap<MapRegistry, TT>& c) {
  25.151 -      if (MapBase::getGraph() != c.getGraph()) {
  25.152 -	MapBase::operator=(c);
  25.153 -	container.resize(c.container.size());
  25.154 +    VectorMap& operator=(const VectorMap& copy) {
  25.155 +      if (&copy == this) return *this;
  25.156 +      
  25.157 +      if (graph != copy.graph) {
  25.158 +	if (attached()) {
  25.159 +	  detach();
  25.160 +	}
  25.161 +	if (copy.attached()) {
  25.162 +	  attach(*copy.getRegistry());
  25.163 +	}
  25.164        }
  25.165 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  25.166 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  25.167 -	container[id] = c.container[id];
  25.168 +      container = copy.container;
  25.169 +
  25.170 +      return *this;
  25.171 +    }
  25.172 +
  25.173 +
  25.174 +    virtual ~VectorMap() {
  25.175 +      if (attached()) {
  25.176 +	detach();
  25.177        }
  25.178 -      return *this;
  25.179 +    }
  25.180 +
  25.181 +    const Graph* getGraph() const {
  25.182 +      return graph;
  25.183      }
  25.184  
  25.185      /// The subcript operator.
  25.186  
  25.187 -    /**
  25.188 -     * The subscript operator. The map can be subscripted by the
  25.189 -     * actual keys of the graph. 
  25.190 -     */
  25.191 +    /// The subscript operator. The map can be subscripted by the
  25.192 +    /// actual items of the graph. 
  25.193 +     
  25.194      ReferenceType operator[](const KeyType& key) {
  25.195 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  25.196 -      return container[id];
  25.197 +      return container[IdMap(*graph)[key]];
  25.198      } 
  25.199  		
  25.200      /// The const subcript operator.
  25.201  
  25.202 -    /**
  25.203 -     * The const subscript operator. The map can be subscripted by the
  25.204 -     * actual keys of the graph. 
  25.205 -     */
  25.206 +    /// The const subscript operator. The map can be subscripted by the
  25.207 +    /// actual items of the graph. 
  25.208 +     
  25.209      ConstReferenceType operator[](const KeyType& key) const {
  25.210 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  25.211 -      return container[id];
  25.212 +      return container[IdMap(*graph)[key]];
  25.213      }
  25.214  
  25.215 -    ///Setter function of the map.
  25.216  
  25.217 -    /** Setter function of the map. Equivalent with map[key] = val.
  25.218 -     *  This is a compatibility feature with the not dereferable maps.
  25.219 -     */
  25.220 -    void set(const KeyType& key, const ValueType& val) {
  25.221 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  25.222 -      container[id] = val;
  25.223 +    /// The setter function of the map.
  25.224 +
  25.225 +    /// It the same as operator[](key) = value expression.
  25.226 +    ///
  25.227 +     
  25.228 +    void set(const KeyType& key, const ValueType& value) {
  25.229 +      (*this)[key] = value;
  25.230      }
  25.231 +
  25.232      /// Adds a new key to the map.
  25.233  		
  25.234 -    /** Adds a new key to the map. It called by the map registry
  25.235 -     *  and it overrides the \ref MapRegistry::MapBase MapBase's
  25.236 -     *  add() member function.
  25.237 -     */
  25.238 +    /// It adds a new key to the map. It called by the observer registry
  25.239 +    /// and it overrides the add() member function of the observer base.
  25.240 +     
  25.241      void add(const KeyType& key) {
  25.242 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  25.243 +      int id = IdMap(*graph)[key];
  25.244        if (id >= (int)container.size()) {
  25.245  	container.resize(id + 1);
  25.246        }
  25.247 @@ -178,93 +187,94 @@
  25.248  
  25.249      /// Erases a key from the map.
  25.250  		
  25.251 -    /** Erase a key from the map. It called by the map registry 
  25.252 -     *  and it overrides the \ref MapRegistry::MapBase MapBase's
  25.253 -     *  erase() member function.
  25.254 -     */
  25.255 +    /// Erase a key from the map. It called by the observer registry
  25.256 +    /// and it overrides the erase() member function of the observer base.     
  25.257      void erase(const KeyType& key) {}
  25.258  
  25.259 -    /// Makes empty the map.
  25.260 +    /// Buildes the map.
  25.261 +		
  25.262 +    /// It buildes the map. It called by the observer registry
  25.263 +    /// and it overrides the build() member function of the observer base.
  25.264  
  25.265 -    /** Makes empty the map. It called by the map registry 
  25.266 -     *  and it overrides the \ref MapRegistry::MapBase MapBase's
  25.267 -     *  clear() member function.
  25.268 -     */
  25.269 +    void build() { 
  25.270 +      container.resize(IdMap(*graph).maxId() + 1);
  25.271 +    }
  25.272  
  25.273 +    /// Clear the map.
  25.274 +
  25.275 +    /// It erase all items from the map. It called by the observer registry
  25.276 +    /// and it overrides the clear() member function of the observer base.     
  25.277      void clear() { 
  25.278        container.clear();
  25.279      }
  25.280  
  25.281 -    /// The stl compatible pair iterator of the map.
  25.282 -    typedef MapIterator<VectorMap> Iterator;
  25.283 -    /// The stl compatible const pair iterator of the map.
  25.284 -    typedef MapConstIterator<VectorMap> ConstIterator;
  25.285 -
  25.286 -    /** Returns the begin iterator of the map.
  25.287 -     */
  25.288 -    Iterator begin() {
  25.289 -      return Iterator(*this, KeyIt(*MapBase::getGraph()));
  25.290 -    }
  25.291 -
  25.292 -    /** Returns the end iterator of the map.
  25.293 -     */
  25.294 -    Iterator end() {
  25.295 -      return Iterator(*this, INVALID);
  25.296 -    }
  25.297 -
  25.298 -    /** Returns the begin ConstIterator of the map.
  25.299 -     */
  25.300 -    ConstIterator begin() const {
  25.301 -      return ConstIterator(*this, KeyIt(*MapBase::getGraph()));
  25.302 -    }
  25.303 -
  25.304 -    /** Returns the end const_iterator of the map.
  25.305 -     */
  25.306 -    ConstIterator end() const {
  25.307 -      return ConstIterator(*this, INVALID);
  25.308 -    }
  25.309 -
  25.310 -    /// The KeySet of the Map.
  25.311 -    typedef MapConstKeySet<VectorMap> ConstKeySet;
  25.312 -
  25.313 -    /// KeySet getter function.
  25.314 -    ConstKeySet keySet() const {
  25.315 -      return ConstKeySet(*this); 
  25.316 -    }
  25.317 -
  25.318 -    /// The ConstValueSet of the Map.
  25.319 -    typedef MapConstValueSet<VectorMap> ConstValueSet;
  25.320 -
  25.321 -    /// ConstValueSet getter function.
  25.322 -    ConstValueSet valueSet() const {
  25.323 -      return ConstValueSet(*this);
  25.324 -    }
  25.325 -
  25.326 -    /// The ValueSet of the Map.
  25.327 -    typedef MapValueSet<VectorMap> ValueSet;
  25.328 -
  25.329 -    /// ValueSet getter function.
  25.330 -    ValueSet valueSet() {
  25.331 -      return ValueSet(*this);
  25.332 -    }
  25.333 -
  25.334 -
  25.335    private:
  25.336  		
  25.337      Container container;
  25.338 +    const Graph *graph;
  25.339  
  25.340 +  };
  25.341 +
  25.342 +
  25.343 +  template <typename _Base> 
  25.344 +  class VectorMappableGraphExtender : public _Base {
  25.345    public:
  25.346 -    // STL  compatibility typedefs.
  25.347 -    typedef Iterator iterator;
  25.348 -    typedef ConstIterator const_iterator;
  25.349 -    typedef typename Iterator::PairValueType value_type;
  25.350 -    typedef typename Iterator::KeyType key_type;
  25.351 -    typedef typename Iterator::ValueType data_type;
  25.352 -    typedef typename Iterator::PairReferenceType reference;
  25.353 -    typedef typename Iterator::PairPointerType pointer;
  25.354 -    typedef typename ConstIterator::PairReferenceType const_reference;
  25.355 -    typedef typename ConstIterator::PairPointerType const_pointer;
  25.356 -    typedef int difference_type;		
  25.357 +
  25.358 +    typedef VectorMappableGraphExtender<_Base> Graph;
  25.359 +    typedef _Base Parent;
  25.360 +
  25.361 +    typedef typename Parent::Node Node;
  25.362 +    typedef typename Parent::NodeIt NodeIt;
  25.363 +    typedef typename Parent::NodeIdMap NodeIdMap;
  25.364 +    typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
  25.365 +
  25.366 +    typedef typename Parent::Edge Edge;
  25.367 +    typedef typename Parent::EdgeIt EdgeIt;
  25.368 +    typedef typename Parent::EdgeIdMap EdgeIdMap;
  25.369 +    typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
  25.370 +
  25.371 +    
  25.372 +
  25.373 +    template <typename _Value>
  25.374 +    class NodeMap : public VectorMap<Graph, Node, NodeIdMap, _Value> {
  25.375 +    public:
  25.376 +      typedef VectorMappableGraphExtender<_Base> Graph;
  25.377 +
  25.378 +      typedef typename Graph::Node Node;
  25.379 +      typedef typename Graph::NodeIdMap NodeIdMap;
  25.380 +
  25.381 +      typedef VectorMap<Graph, Node, NodeIdMap, _Value> Parent;
  25.382 +
  25.383 +      typedef typename Parent::Graph Graph;
  25.384 +      typedef typename Parent::Value Value;
  25.385 +
  25.386 +      NodeMap(const Graph& g) 
  25.387 +	: Parent(g, g.getNodeObserverRegistry()) {}
  25.388 +      NodeMap(const Graph& g, const Value& v) 
  25.389 +	: Parent(g, g.getNodeObserverRegistry(), v) {}
  25.390 +
  25.391 +    };
  25.392 +
  25.393 +    template <typename _Value>
  25.394 +    class EdgeMap : public VectorMap<Graph, Edge, EdgeIdMap, _Value> {
  25.395 +    public:
  25.396 +      typedef VectorMappableGraphExtender<_Base> Graph;
  25.397 +
  25.398 +      typedef typename Graph::Edge Edge;
  25.399 +      typedef typename Graph::EdgeIdMap EdgeIdMap;
  25.400 +
  25.401 +      typedef VectorMap<Graph, Edge, EdgeIdMap, _Value> Parent;
  25.402 +
  25.403 +      typedef typename Parent::Graph Graph;
  25.404 +      typedef typename Parent::Value Value;
  25.405 +
  25.406 +      EdgeMap(const Graph& g) 
  25.407 +	: Parent(g, g.getEdgeObserverRegistry()) {}
  25.408 +      EdgeMap(const Graph& g, const Value& v) 
  25.409 +	: Parent(g, g.getEdgeObserverRegistry(), v) {}
  25.410 +
  25.411 +    };
  25.412 +    
  25.413    };
  25.414    
  25.415    /// @}
    26.1 --- a/src/test/Makefile.am	Mon Oct 25 13:29:46 2004 +0000
    26.2 +++ b/src/test/Makefile.am	Wed Oct 27 22:38:50 2004 +0000
    26.3 @@ -2,17 +2,22 @@
    26.4  
    26.5  EXTRA_DIST = preflow_graph.dim #input file for preflow_test.cc
    26.6  
    26.7 -noinst_HEADERS = test_tools.h graph_test.h sym_graph_test.h
    26.8 +noinst_HEADERS = \
    26.9 +	test_tools.h \
   26.10 +	graph_test.h \
   26.11 +	sym_graph_test.h \
   26.12 +	map_test.h \
   26.13 +	graph_utils_test.h
   26.14  
   26.15  check_PROGRAMS = \
   26.16  	bfs_test \
   26.17  	dfs_test \
   26.18  	dijkstra_test \
   26.19  	graph_test \
   26.20 -	sym_graph_test \
   26.21 -	graph_wrapper_test \
   26.22 +	graph_utils_test \
   26.23  	kruskal_test \
   26.24  	min_cost_flow_test \
   26.25 +	new_graph_test \
   26.26  	suurballe_test \
   26.27  	path_test \
   26.28  	preflow_test \
   26.29 @@ -20,6 +25,7 @@
   26.30  	test_tools_pass \
   26.31  	time_measure_test \
   26.32  	unionfind_test \
   26.33 +	graph_wrapper_test \
   26.34  	xy_test
   26.35  
   26.36  TESTS = $(check_PROGRAMS)
   26.37 @@ -29,10 +35,11 @@
   26.38  dfs_test_SOURCES = dfs_test.cc
   26.39  dijkstra_test_SOURCES = dijkstra_test.cc
   26.40  graph_test_SOURCES = graph_test.cc
   26.41 -sym_graph_test_SOURCES = sym_graph_test.cc
   26.42 +graph_utils_test_SOURCES = graph_utils_test.cc
   26.43  graph_wrapper_test_SOURCES = graph_wrapper_test.cc
   26.44  kruskal_test_SOURCES = kruskal_test.cc
   26.45  min_cost_flow_test_SOURCES = min_cost_flow_test.cc
   26.46 +new_graph_test_SOURCES = new_graph_test.cc
   26.47  suurballe_test_SOURCES = suurballe_test.cc
   26.48  path_test_SOURCES = path_test.cc
   26.49  preflow_test_SOURCES = preflow_test.cc
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/src/test/graph_factory_test.cc	Wed Oct 27 22:38:50 2004 +0000
    27.3 @@ -0,0 +1,154 @@
    27.4 +/* -*- C++ -*-
    27.5 + * src/test/graph_test.cc - Part of LEMON, a generic C++ optimization library
    27.6 + *
    27.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    27.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    27.9 + *
   27.10 + * Permission to use, modify and distribute this software is granted
   27.11 + * provided that this copyright notice appears in all copies. For
   27.12 + * precise terms see the accompanying LICENSE file.
   27.13 + *
   27.14 + * This software is provided "AS IS" with no warranty of any kind,
   27.15 + * express or implied, and with no claim as to its suitability for any
   27.16 + * purpose.
   27.17 + *
   27.18 + */
   27.19 +
   27.20 +#include<iostream>
   27.21 +#include<lemon/smart_graph.h>
   27.22 +#include<lemon/skeletons/graph.h>
   27.23 +#include<lemon/skeletons/maps.h>
   27.24 +#include<lemon/list_graph_base.h>
   27.25 +#include<lemon/full_graph.h>
   27.26 +
   27.27 +#include"test_tools.h"
   27.28 +#include"graph_test.h"
   27.29 +
   27.30 +/**
   27.31 +\file
   27.32 +This test makes consistency checks of list graph structures.
   27.33 +
   27.34 +G.addNode(), G.addEdge(), G.tail(), G.head()
   27.35 +
   27.36 +\todo Checks for empty graphs and isolated points.
   27.37 +conversion.
   27.38 +*/
   27.39 +
   27.40 +using namespace lemon;
   27.41 +
   27.42 +template<class Graph> void bidirPetersen(Graph &G)
   27.43 +{
   27.44 +  typedef typename Graph::Edge Edge;
   27.45 +  typedef typename Graph::EdgeIt EdgeIt;
   27.46 +  
   27.47 +  checkGraphEdgeList(G,15);
   27.48 +  
   27.49 +  std::vector<Edge> ee;
   27.50 +  
   27.51 +  for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
   27.52 +
   27.53 +  for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
   27.54 +    G.addEdge(G.head(*p),G.tail(*p));
   27.55 +}
   27.56 +
   27.57 +template<class Graph> void checkPetersen(Graph &G)
   27.58 +{
   27.59 +  typedef typename Graph::Node Node;
   27.60 +
   27.61 +  typedef typename Graph::EdgeIt EdgeIt;
   27.62 +  typedef typename Graph::NodeIt NodeIt;
   27.63 +
   27.64 +  checkGraphNodeList(G,10);
   27.65 +  checkGraphEdgeList(G,30);
   27.66 +
   27.67 +  for(NodeIt n(G);n!=INVALID;++n) {
   27.68 +    checkGraphInEdgeList(G,n,3);
   27.69 +    checkGraphOutEdgeList(G,n,3);
   27.70 +  }  
   27.71 +}
   27.72 +
   27.73 +//Compile Graph
   27.74 +template void lemon::skeleton::checkCompileStaticGraph<skeleton::StaticGraph>
   27.75 +(skeleton::StaticGraph &);
   27.76 +
   27.77 +template
   27.78 +void lemon::skeleton::checkCompileExtendableGraph<skeleton::ExtendableGraph>
   27.79 +(skeleton::ExtendableGraph &);
   27.80 +
   27.81 +template
   27.82 +void lemon::skeleton::checkCompileErasableGraph<skeleton::ErasableGraph>
   27.83 +(skeleton::ErasableGraph &);
   27.84 +
   27.85 +//Compile SmartGraph
   27.86 +template
   27.87 +void lemon::skeleton::checkCompileExtendableGraph<SmartGraph>(SmartGraph &);
   27.88 +template
   27.89 +void lemon::skeleton::checkCompileGraphFindEdge<SmartGraph>(SmartGraph &);
   27.90 +
   27.91 +//Compile SymSmartGraph
   27.92 +//template void hugo::checkCompileGraph<SymSmartGraph>(SymSmartGraph &);
   27.93 +//template void hugo::checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &);
   27.94 +
   27.95 +//Compile ListGraph
   27.96 +template
   27.97 +void lemon::skeleton::checkCompileExtendableGraph<ListGraph>(ListGraph &);
   27.98 +template
   27.99 +void lemon::skeleton::checkCompileErasableGraph<ListGraph>(ListGraph &);
  27.100 +template
  27.101 +void lemon::skeleton::checkCompileGraphFindEdge<ListGraph>(ListGraph &);
  27.102 +
  27.103 +
  27.104 +//Compile SymListGraph
  27.105 +//template void hugo::checkCompileGraph<SymListGraph>(SymListGraph &);
  27.106 +//template void hugo::checkCompileErasableGraph<SymListGraph>(SymListGraph &);
  27.107 +//template void hugo::checkCompileGraphFindEdge<SymListGraph>(SymListGraph &);
  27.108 +
  27.109 +//Compile FullGraph
  27.110 +template void lemon::skeleton::checkCompileStaticGraph<FullGraph>(FullGraph &);
  27.111 +template
  27.112 +void lemon::skeleton::checkCompileGraphFindEdge<FullGraph>(FullGraph &);
  27.113 +
  27.114 +
  27.115 +int main() 
  27.116 +{
  27.117 +  {
  27.118 +    SmartGraph G;
  27.119 +    addPetersen(G);
  27.120 +    bidirPetersen(G);
  27.121 +    checkPetersen(G);
  27.122 +  }
  27.123 +  {
  27.124 +    ListGraph G;
  27.125 +    addPetersen(G);
  27.126 +    bidirPetersen(G);
  27.127 +    checkPetersen(G);
  27.128 +  }
  27.129 +  {
  27.130 +    //    SymSmartGraph G;
  27.131 +    //    addPetersen(G);
  27.132 +    //    checkPetersen(G);
  27.133 +  }
  27.134 +  {
  27.135 +    //    SymListGraph G;
  27.136 +    //    addPetersen(G);
  27.137 +    //    checkPetersen(G);
  27.138 +  }
  27.139 +
  27.140 +  ///\file
  27.141 +  ///\todo map tests.
  27.142 +  ///\todo copy constr tests.
  27.143 +
  27.144 +
  27.145 +  // Some map tests.
  27.146 +  // FIXME: These shouldn't be here.
  27.147 +  using namespace skeleton;
  27.148 +  function_requires< ReadMapConcept< ReadMap<int,int> > >();
  27.149 +  function_requires< WriteMapConcept< WriteMap<int,int> > >();
  27.150 +  function_requires< ReadWriteMapConcept< ReadWriteMap<int,int> > >();
  27.151 +  function_requires< ReferenceMapConcept< ReferenceMap<int,int> > >();
  27.152 +
  27.153 +
  27.154 +  std::cout << __FILE__ ": All tests passed.\n";
  27.155 +
  27.156 +  return 0;
  27.157 +}
    28.1 --- a/src/test/graph_test.cc	Mon Oct 25 13:29:46 2004 +0000
    28.2 +++ b/src/test/graph_test.cc	Wed Oct 27 22:38:50 2004 +0000
    28.3 @@ -1,157 +1,67 @@
    28.4 -/* -*- C++ -*-
    28.5 - * src/test/graph_test.cc - Part of LEMON, a generic C++ optimization library
    28.6 - *
    28.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    28.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    28.9 - *
   28.10 - * Permission to use, modify and distribute this software is granted
   28.11 - * provided that this copyright notice appears in all copies. For
   28.12 - * precise terms see the accompanying LICENSE file.
   28.13 - *
   28.14 - * This software is provided "AS IS" with no warranty of any kind,
   28.15 - * express or implied, and with no claim as to its suitability for any
   28.16 - * purpose.
   28.17 - *
   28.18 - */
   28.19 +// -*- c++ -*-
   28.20  
   28.21 -#include<iostream>
   28.22 -#include<lemon/smart_graph.h>
   28.23 -#include<lemon/skeletons/graph.h>
   28.24 -#include<lemon/list_graph.h>
   28.25 -#include<lemon/full_graph.h>
   28.26 +#include <iostream>
   28.27 +#include <vector>
   28.28  
   28.29 -#include"test_tools.h"
   28.30 -#include"graph_test.h"
   28.31 +#include <lemon/skeletons/graph.h>
   28.32 +#include <lemon/list_graph.h>
   28.33 +#include <lemon/smart_graph.h>
   28.34 +#include <lemon/full_graph.h>
   28.35  
   28.36 -/**
   28.37 -\file
   28.38 -This test makes consistency checks of list graph structures.
   28.39 +#include "test_tools.h"
   28.40 +#include "graph_test.h"
   28.41 +#include "map_test.h"
   28.42  
   28.43 -G.addNode(), G.addEdge(), G.tail(), G.head()
   28.44 -
   28.45 -\todo Checks for empty graphs and isolated points.
   28.46 -conversion.
   28.47 -*/
   28.48  
   28.49  using namespace lemon;
   28.50 +using namespace lemon::skeleton;
   28.51  
   28.52 -template<class Graph> void bidirPetersen(Graph &G)
   28.53 -{
   28.54 -  typedef typename Graph::Edge Edge;
   28.55 -  typedef typename Graph::EdgeIt EdgeIt;
   28.56 -  
   28.57 -  checkGraphEdgeList(G,15);
   28.58 -  
   28.59 -  std::vector<Edge> ee;
   28.60 -  
   28.61 -  for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
   28.62  
   28.63 -  for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
   28.64 -    G.addEdge(G.head(*p),G.tail(*p));
   28.65 -}
   28.66 +int main() {
   28.67 +  ///\file
   28.68 +  { // checking graph components
   28.69 +    function_requires<BaseGraphComponentConcept<BaseGraphComponent> >();
   28.70  
   28.71 -template<class Graph> void checkPetersen(Graph &G)
   28.72 -{
   28.73 -  typedef typename Graph::Node Node;
   28.74 +    function_requires<BaseIterableGraphComponentConcept<BaseIterableGraphComponent> >();
   28.75  
   28.76 -  typedef typename Graph::EdgeIt EdgeIt;
   28.77 -  typedef typename Graph::NodeIt NodeIt;
   28.78 +    function_requires<IDableGraphComponentConcept<IDableGraphComponent> >();
   28.79 +    function_requires<MaxIDableGraphComponentConcept<MaxIDableGraphComponent> >();
   28.80  
   28.81 -  checkGraphNodeList(G,10);
   28.82 -  checkGraphEdgeList(G,30);
   28.83 +    function_requires<BaseExtendableGraphComponentConcept<BaseExtendableGraphComponent> >();
   28.84 +    function_requires<BaseErasableGraphComponentConcept<BaseErasableGraphComponent> >();
   28.85 +    function_requires<BaseClearableGraphComponentConcept<BaseClearableGraphComponent> >();
   28.86  
   28.87 -  for(NodeIt n(G);n!=INVALID;++n) {
   28.88 -    checkGraphInEdgeList(G,n,3);
   28.89 -    checkGraphOutEdgeList(G,n,3);
   28.90 -  }  
   28.91 -}
   28.92 +    function_requires<IterableGraphComponentConcept<IterableGraphComponent> >();
   28.93  
   28.94 -//Compile Graph
   28.95 -template void lemon::skeleton::checkCompileStaticGraph<skeleton::StaticGraph>
   28.96 -(skeleton::StaticGraph &);
   28.97 +    function_requires<IdMappableGraphComponentConcept<IdMappableGraphComponent> >();
   28.98 +    function_requires<MappableGraphComponentConcept<MappableGraphComponent> >();
   28.99  
  28.100 -template
  28.101 -void lemon::skeleton::checkCompileExtendableGraph<skeleton::ExtendableGraph>
  28.102 -(skeleton::ExtendableGraph &);
  28.103 +    function_requires<ExtendableGraphComponentConcept<ExtendableGraphComponent> >();
  28.104 +    function_requires<ErasableGraphComponentConcept<ErasableGraphComponent> >();
  28.105 +    function_requires<ClearableGraphComponentConcept<ClearableGraphComponent> >();
  28.106 +  }
  28.107 +  { // checking skeleton graphs
  28.108 +    function_requires<StaticGraphConcept<StaticGraph> >();
  28.109 +    function_requires<ExtendableGraphConcept<ExtendableGraph> >();
  28.110 +    function_requires<ErasableGraphConcept<ErasableGraph> >();
  28.111 +  }
  28.112 +  { // checking list graph
  28.113 +    function_requires<ErasableGraphConcept<ListGraph> >();
  28.114  
  28.115 -template
  28.116 -void lemon::skeleton::checkCompileErasableGraph<skeleton::ErasableGraph>
  28.117 -(skeleton::ErasableGraph &);
  28.118 +    checkGraph<ListGraph>();
  28.119 +    checkGraphNodeMap<ListGraph>();
  28.120 +    checkGraphEdgeMap<ListGraph>();
  28.121 +  }
  28.122 +  { // checking smart graph
  28.123 +    function_requires<ExtendableGraphConcept<SmartGraph> >();
  28.124  
  28.125 -//Compile SmartGraph
  28.126 -template
  28.127 -void lemon::skeleton::checkCompileExtendableGraph<SmartGraph>(SmartGraph &);
  28.128 -template
  28.129 -void lemon::skeleton::checkCompileGraphFindEdge<SmartGraph>(SmartGraph &);
  28.130 -
  28.131 -//Compile SymSmartGraph
  28.132 -//template void hugo::checkCompileGraph<SymSmartGraph>(SymSmartGraph &);
  28.133 -//template void hugo::checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &);
  28.134 -
  28.135 -//Compile ListGraph
  28.136 -template
  28.137 -void lemon::skeleton::checkCompileExtendableGraph<ListGraph>(ListGraph &);
  28.138 -template
  28.139 -void lemon::skeleton::checkCompileErasableGraph<ListGraph>(ListGraph &);
  28.140 -template
  28.141 -void lemon::skeleton::checkCompileGraphFindEdge<ListGraph>(ListGraph &);
  28.142 -
  28.143 -
  28.144 -//Compile SymListGraph
  28.145 -//template void hugo::checkCompileGraph<SymListGraph>(SymListGraph &);
  28.146 -//template void hugo::checkCompileErasableGraph<SymListGraph>(SymListGraph &);
  28.147 -//template void hugo::checkCompileGraphFindEdge<SymListGraph>(SymListGraph &);
  28.148 -
  28.149 -//Compile FullGraph
  28.150 -template void lemon::skeleton::checkCompileStaticGraph<FullGraph>(FullGraph &);
  28.151 -template
  28.152 -void lemon::skeleton::checkCompileGraphFindEdge<FullGraph>(FullGraph &);
  28.153 -
  28.154 -//Compile EdgeSet <ListGraph>
  28.155 -template void lemon::skeleton::checkCompileExtendableGraph<EdgeSet <ListGraph> >
  28.156 -(EdgeSet <ListGraph> &);
  28.157 -template void lemon::skeleton::checkCompileGraphEraseEdge<EdgeSet <ListGraph> >
  28.158 -(EdgeSet <ListGraph> &);
  28.159 -template void lemon::skeleton::checkCompileGraphFindEdge<EdgeSet <ListGraph> >
  28.160 -(EdgeSet <ListGraph> &);
  28.161 -
  28.162 -//Compile EdgeSet <NodeSet>
  28.163 -template void lemon::skeleton::checkCompileExtendableGraph<EdgeSet <NodeSet> >
  28.164 -(EdgeSet <NodeSet> &);
  28.165 -template void lemon::skeleton::checkCompileGraphEraseEdge<EdgeSet <NodeSet> >
  28.166 -(EdgeSet <NodeSet> &);
  28.167 -template void lemon::skeleton::checkCompileGraphFindEdge<EdgeSet <NodeSet> >
  28.168 -(EdgeSet <NodeSet> &);
  28.169 -
  28.170 -
  28.171 -int main() 
  28.172 -{
  28.173 -  {
  28.174 -    SmartGraph G;
  28.175 -    addPetersen(G);
  28.176 -    bidirPetersen(G);
  28.177 -    checkPetersen(G);
  28.178 +    checkGraph<SmartGraph>();
  28.179 +    checkGraphNodeMap<SmartGraph>();
  28.180 +    checkGraphEdgeMap<SmartGraph>();
  28.181    }
  28.182 -  {
  28.183 -    ListGraph G;
  28.184 -    addPetersen(G);
  28.185 -    bidirPetersen(G);
  28.186 -    checkPetersen(G);
  28.187 +  { // checking full graph
  28.188 +    function_requires<StaticGraphConcept<FullGraph> >();
  28.189    }
  28.190 -  {
  28.191 -    //    SymSmartGraph G;
  28.192 -    //    addPetersen(G);
  28.193 -    //    checkPetersen(G);
  28.194 -  }
  28.195 -  {
  28.196 -    //    SymListGraph G;
  28.197 -    //    addPetersen(G);
  28.198 -    //    checkPetersen(G);
  28.199 -  }
  28.200 -
  28.201 -  ///\file
  28.202 -  ///\todo map tests.
  28.203 -  ///\todo copy constr tests.
  28.204  
  28.205    std::cout << __FILE__ ": All tests passed.\n";
  28.206  
    29.1 --- a/src/test/graph_test.h	Mon Oct 25 13:29:46 2004 +0000
    29.2 +++ b/src/test/graph_test.h	Wed Oct 27 22:38:50 2004 +0000
    29.3 @@ -21,56 +21,64 @@
    29.4  
    29.5  //! \ingroup misc
    29.6  //! \file
    29.7 -//! \brief Some utility to  test graph classes.
    29.8 +//! \brief Some utility and test cases to test graph classes.
    29.9  namespace lemon {
   29.10  
   29.11    template<class Graph> void checkGraphNodeList(Graph &G, int nn)
   29.12 -    {
   29.13 -      typename Graph::NodeIt n(G);
   29.14 -      for(int i=0;i<nn;i++) {
   29.15 -	check(n!=INVALID,"Wrong Node list linking.");
   29.16 -	++n;
   29.17 -      }
   29.18 -      check(n==INVALID,"Wrong Node list linking.");
   29.19 +  {
   29.20 +    typename Graph::NodeIt n(G);
   29.21 +    for(int i=0;i<nn;i++) {
   29.22 +      check(n!=INVALID,"Wrong Node list linking.");
   29.23 +      ++n;
   29.24      }
   29.25 +    check(n==INVALID,"Wrong Node list linking.");
   29.26 +  }
   29.27  
   29.28 -  template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
   29.29 -    {
   29.30 -      typedef typename Graph::EdgeIt EdgeIt;
   29.31 +  template<class Graph>
   29.32 +  void checkGraphEdgeList(Graph &G, int nn)
   29.33 +  {
   29.34 +    typedef typename Graph::EdgeIt EdgeIt;
   29.35  
   29.36 -      EdgeIt e(G);
   29.37 -      for(int i=0;i<nn;i++) {
   29.38 -	check(e!=INVALID,"Wrong Edge list linking.");
   29.39 -	++e;
   29.40 -      }
   29.41 -      check(e==INVALID,"Wrong Edge list linking.");
   29.42 +    EdgeIt e(G);
   29.43 +    for(int i=0;i<nn;i++) {
   29.44 +      check(e!=INVALID,"Wrong Edge list linking.");
   29.45 +      ++e;
   29.46      }
   29.47 +    check(e==INVALID,"Wrong Edge list linking.");
   29.48 +  }
   29.49  
   29.50 -  template<class Graph> void checkGraphOutEdgeList(Graph &G,
   29.51 -						   typename Graph::Node n,
   29.52 -						   int nn)
   29.53 -    {
   29.54 -      typename Graph::OutEdgeIt e(G,n);
   29.55 -      for(int i=0;i<nn;i++) {
   29.56 -	check(e!=INVALID,"Wrong OutEdge list linking.");
   29.57 -	check(n==G.tail(e), "Wrong OutEdge list linking.");
   29.58 -	++e;
   29.59 -      }
   29.60 -      check(e==INVALID,"Wrong OutEdge list linking.");
   29.61 +  template<class Graph> 
   29.62 +  void checkGraphOutEdgeList(Graph &G, typename Graph::Node n, int nn)
   29.63 +  {
   29.64 +    typename Graph::OutEdgeIt e(G,n);
   29.65 +    for(int i=0;i<nn;i++) {
   29.66 +      check(e!=INVALID,"Wrong OutEdge list linking.");
   29.67 +      check(n==G.tail(e), "Wrong OutEdge list linking.");
   29.68 +      ++e;
   29.69      }
   29.70 +    check(e==INVALID,"Wrong OutEdge list linking.");
   29.71 +  }
   29.72  
   29.73 -  template<class Graph> void checkGraphInEdgeList(Graph &G,
   29.74 -						  typename Graph::Node n,
   29.75 -						  int nn)
   29.76 -    {
   29.77 -      typename Graph::InEdgeIt e(G,n);
   29.78 -      for(int i=0;i<nn;i++) {
   29.79 -	check(e!=INVALID,"Wrong InEdge list linking.");
   29.80 -	check(n==G.head(e), "Wrong InEdge list linking.");
   29.81 -	++e;
   29.82 -      }
   29.83 -      check(e==INVALID,"Wrong InEdge list linking.");
   29.84 +  template<class Graph> void 
   29.85 +  checkGraphInEdgeList(Graph &G, typename Graph::Node n, int nn)
   29.86 +  {
   29.87 +    typename Graph::InEdgeIt e(G,n);
   29.88 +    for(int i=0;i<nn;i++) {
   29.89 +      check(e!=INVALID,"Wrong InEdge list linking.");
   29.90 +      check(n==G.head(e), "Wrong InEdge list linking.");
   29.91 +      ++e;
   29.92      }
   29.93 +    check(e==INVALID,"Wrong InEdge list linking.");
   29.94 +  }
   29.95 +
   29.96 +  template <class Graph> 
   29.97 +  void checkGraph() {
   29.98 +    const int num = 5;
   29.99 +    Graph G;
  29.100 +    addPetersen(G, num);
  29.101 +    bidirGraph(G);
  29.102 +    checkBidirPetersen(G, num);
  29.103 +  }
  29.104  
  29.105    ///\file
  29.106    ///\todo Check head(), tail() as well;
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/src/test/graph_utils_test.cc	Wed Oct 27 22:38:50 2004 +0000
    30.3 @@ -0,0 +1,29 @@
    30.4 +// -*- c++ -*-
    30.5 +
    30.6 +#include <iostream>
    30.7 +#include <vector>
    30.8 +
    30.9 +#include <lemon/list_graph.h>
   30.10 +#include <lemon/smart_graph.h>
   30.11 +#include <lemon/full_graph.h>
   30.12 +
   30.13 +#include "test_tools.h"
   30.14 +#include "graph_utils_test.h"
   30.15 +
   30.16 +
   30.17 +using namespace lemon;
   30.18 +
   30.19 +
   30.20 +int main() {
   30.21 +  ///\file
   30.22 +  { // checking list graph
   30.23 +    checkGraphCounters<ListGraph>();
   30.24 +  }
   30.25 +  { // checking smart graph
   30.26 +    checkGraphCounters<SmartGraph>();
   30.27 +  }
   30.28 +
   30.29 +  std::cout << __FILE__ ": All tests passed.\n";
   30.30 +
   30.31 +  return 0;
   30.32 +}
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/src/test/graph_utils_test.h	Wed Oct 27 22:38:50 2004 +0000
    31.3 @@ -0,0 +1,44 @@
    31.4 +/* -*- C++ -*-
    31.5 + * src/test/graph_utils_test.h - Part of LEMON, a generic C++ optimization library
    31.6 + *
    31.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    31.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    31.9 + *
   31.10 + * Permission to use, modify and distribute this software is granted
   31.11 + * provided that this copyright notice appears in all copies. For
   31.12 + * precise terms see the accompanying LICENSE file.
   31.13 + *
   31.14 + * This software is provided "AS IS" with no warranty of any kind,
   31.15 + * express or implied, and with no claim as to its suitability for any
   31.16 + * purpose.
   31.17 + *
   31.18 + */
   31.19 +#ifndef LEMON_TEST_GRAPH_UTILS_TEST_H
   31.20 +#define LEMON_TEST_GRAPH_UTILS_TEST_H
   31.21 +
   31.22 +
   31.23 +#include "test_tools.h"
   31.24 +
   31.25 +//! \ingroup misc
   31.26 +//! \file
   31.27 +//! \brief Test cases for graph utils.
   31.28 +namespace lemon {
   31.29 +  
   31.30 +  template <typename Graph>
   31.31 +  void checkGraphCounters() {
   31.32 +    const int num = 5;
   31.33 +    Graph graph;
   31.34 +    addPetersen(graph, num);
   31.35 +    bidirGraph(graph);
   31.36 +    check(countNodes(graph) == 2*num, "Wrong node counter.");
   31.37 +    check(countEdges(graph) == 6*num, "Wrong edge counter.");    
   31.38 +    for (typename Graph::NodeIt it(graph); it != INVALID; ++it) {
   31.39 +      check(countOutEdges(graph, it) == 3, "Wrong out degree counter.");
   31.40 +      check(countInEdges(graph, it) == 3, "Wrong in degree counter.");
   31.41 +    }
   31.42 +  }
   31.43 +  
   31.44 +} //namespace lemon
   31.45 +
   31.46 +
   31.47 +#endif
    32.1 --- a/src/test/graph_wrapper_test.cc	Mon Oct 25 13:29:46 2004 +0000
    32.2 +++ b/src/test/graph_wrapper_test.cc	Wed Oct 27 22:38:50 2004 +0000
    32.3 @@ -15,8 +15,11 @@
    32.4   */
    32.5  
    32.6  #include<iostream>
    32.7 +#include<lemon/concept_check.h>
    32.8 +
    32.9  #include<lemon/smart_graph.h>
   32.10  #include<lemon/skeletons/graph.h>
   32.11 +
   32.12  #include<lemon/list_graph.h>
   32.13  #include<lemon/full_graph.h>
   32.14  #include<lemon/graph_wrapper.h>
   32.15 @@ -32,66 +35,31 @@
   32.16  */
   32.17  
   32.18  using namespace lemon;
   32.19 +using namespace lemon::skeleton;
   32.20  
   32.21  
   32.22  typedef SmartGraph Graph;
   32.23  
   32.24 -//Compile GraphWrapper
   32.25 -typedef GraphWrapper<Graph> GW;
   32.26 -template void lemon::skeleton::checkCompileStaticGraph<GW>(GW &);
   32.27 -
   32.28 -//Compile RevGraphWrapper
   32.29 -typedef RevGraphWrapper<Graph> RevGW;
   32.30 -template void lemon::skeleton::checkCompileStaticGraph<RevGW>(RevGW &);
   32.31 -
   32.32 -//Compile SubGraphWrapper
   32.33 -typedef SubGraphWrapper<Graph, Graph::NodeMap<bool>, 
   32.34 -			Graph::EdgeMap<bool> > SubGW;
   32.35 -template void lemon::skeleton::checkCompileStaticGraph<SubGW>(SubGW &);
   32.36 -
   32.37 -//Compile NodeSubGraphWrapper
   32.38 -typedef NodeSubGraphWrapper<Graph, Graph::NodeMap<bool> > NodeSubGW;
   32.39 -template void lemon::skeleton::checkCompileStaticGraph<NodeSubGW>(NodeSubGW &);
   32.40 -
   32.41 -//Compile EdgeSubGraphWrapper
   32.42 -typedef EdgeSubGraphWrapper<Graph, Graph::EdgeMap<bool> > EdgeSubGW;
   32.43 -template void lemon::skeleton::checkCompileStaticGraph<EdgeSubGW>(EdgeSubGW &);
   32.44 -
   32.45 -//Compile UndirGraphWrapper
   32.46 -/// \bug UndirGraphWrapper cannot pass the StaticGraph test
   32.47 -//typedef UndirGraphWrapper<Graph> UndirGW;
   32.48 -//template void checkCompileStaticGraph<UndirGW>(UndirGW &);
   32.49 -
   32.50 -//Compile UndirGraph
   32.51 -//typedef UndirGraph<Graph> UndirG;
   32.52 -//template void checkCompileStaticGraph<UndirG>(UndirG &);
   32.53 -
   32.54 -//Compile SubBidirGraphWrapper
   32.55 -typedef SubBidirGraphWrapper<Graph, Graph::EdgeMap<bool>, 
   32.56 -			     Graph::EdgeMap<bool> > SubBDGW;
   32.57 -template void lemon::skeleton::checkCompileStaticGraph<SubBDGW>(SubBDGW &);
   32.58 -
   32.59 -//Compile BidirGraphWrapper
   32.60 -typedef BidirGraphWrapper<Graph> BidirGW;
   32.61 -template void lemon::skeleton::checkCompileStaticGraph<BidirGW>(BidirGW &);
   32.62 -
   32.63 -//Compile BidirGraph
   32.64 -typedef BidirGraph<Graph> BidirG;
   32.65 -template void lemon::skeleton::checkCompileStaticGraph<BidirG>(BidirG &);
   32.66 -
   32.67 -//Compile ResGraphWrapper
   32.68 -typedef ResGraphWrapper<Graph, int, Graph::EdgeMap<int>, 
   32.69 -			Graph::EdgeMap<int> > ResGW;
   32.70 -template void lemon::skeleton::checkCompileStaticGraph<ResGW>(ResGW &);
   32.71 -
   32.72 -//Compile ErasingFirstGraphWrapper
   32.73 -typedef ErasingFirstGraphWrapper<Graph, Graph::NodeMap<Graph::Edge> > ErasingFirstGW;
   32.74 -template
   32.75 -void lemon::skeleton::checkCompileStaticGraph<ErasingFirstGW>(ErasingFirstGW &);
   32.76 -
   32.77  
   32.78  int main() 
   32.79  {
   32.80 +  {
   32.81 +    function_requires<StaticGraphConcept<GraphWrapper<Graph> > >();
   32.82 +
   32.83 +    function_requires<StaticGraphConcept<RevGraphWrapper<Graph> > >();
   32.84 +
   32.85 +    function_requires<StaticGraphConcept<SubGraphWrapper<Graph, Graph::NodeMap<bool> , Graph::EdgeMap<bool> > > >();
   32.86 +    function_requires<StaticGraphConcept<NodeSubGraphWrapper<Graph, Graph::NodeMap<bool> > > >();
   32.87 +    function_requires<StaticGraphConcept<EdgeSubGraphWrapper<Graph, Graph::EdgeMap<bool> > > >();
   32.88 +
   32.89 +    function_requires<StaticGraphConcept<SubBidirGraphWrapper<Graph, Graph::EdgeMap<bool>, Graph::EdgeMap<bool> > > > ();
   32.90 +
   32.91 +    function_requires<StaticGraphConcept<BidirGraph<Graph> > >();
   32.92 +
   32.93 +    function_requires<StaticGraphConcept<ResGraphWrapper<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > > >();
   32.94 +
   32.95 +    function_requires<StaticGraphConcept<ErasingFirstGraphWrapper<Graph, Graph::NodeMap<Graph::Edge> > > >();
   32.96 +  }
   32.97    std::cout << __FILE__ ": All tests passed.\n";
   32.98  
   32.99    return 0;
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/src/test/map_test.h	Wed Oct 27 22:38:50 2004 +0000
    33.3 @@ -0,0 +1,95 @@
    33.4 +/* -*- C++ -*-
    33.5 + * src/test/map_test.h - Part of LEMON, a generic C++ optimization library
    33.6 + *
    33.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    33.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    33.9 + *
   33.10 + * Permission to use, modify and distribute this software is granted
   33.11 + * provided that this copyright notice appears in all copies. For
   33.12 + * precise terms see the accompanying LICENSE file.
   33.13 + *
   33.14 + * This software is provided "AS IS" with no warranty of any kind,
   33.15 + * express or implied, and with no claim as to its suitability for any
   33.16 + * purpose.
   33.17 + *
   33.18 + */
   33.19 +#ifndef LEMON_TEST_MAP_TEST_H
   33.20 +#define LEMON_TEST_MAP_TEST_H
   33.21 +
   33.22 +
   33.23 +#include <vector>
   33.24 +
   33.25 +#include "test_tools.h"
   33.26 +
   33.27 +
   33.28 +//! \ingroup misc
   33.29 +//! \file
   33.30 +//! \brief Some utility to test map classes.
   33.31 +
   33.32 +namespace lemon {
   33.33 +
   33.34 +
   33.35 +  template <typename Graph>
   33.36 +  void checkGraphNodeMap() {
   33.37 +    Graph graph;
   33.38 +    const int num = 16;
   33.39 +    
   33.40 +    typedef typename Graph::Node Node;
   33.41 +
   33.42 +    std::vector<Node> nodes;
   33.43 +    for (int i = 0; i < num; ++i) {
   33.44 +      nodes.push_back(graph.addNode());      
   33.45 +    }
   33.46 +    typedef typename Graph::template NodeMap<int> IntNodeMap;
   33.47 +    IntNodeMap map(graph, 42);
   33.48 +    for (int i = 0; i < (int)nodes.size(); ++i) {
   33.49 +      check(map[nodes[i]] == 42, "Wrong map constructor.");      
   33.50 +    }
   33.51 +    for (int i = 0; i < num; ++i) {
   33.52 +      nodes.push_back(graph.addNode());
   33.53 +      map[nodes.back()] = 23;
   33.54 +    }
   33.55 +    graph.clear();
   33.56 +    nodes.clear();
   33.57 +  }
   33.58 +
   33.59 +  template <typename Graph>
   33.60 +  void checkGraphEdgeMap() {
   33.61 +    Graph graph;
   33.62 +    const int num = 16;
   33.63 +    
   33.64 +    typedef typename Graph::Node Node;
   33.65 +    typedef typename Graph::Edge Edge;
   33.66 +    
   33.67 +    std::vector<Node> nodes;
   33.68 +    for (int i = 0; i < num; ++i) {
   33.69 +      nodes.push_back(graph.addNode());
   33.70 +    }
   33.71 +    
   33.72 +    std::vector<Edge> edges;
   33.73 +    for (int i = 0; i < num; ++i) {
   33.74 +      for (int j = 0; j < i; ++j) {
   33.75 +	edges.push_back(graph.addEdge(nodes[i], nodes[j]));
   33.76 +      }
   33.77 +    }
   33.78 +    
   33.79 +    typedef typename Graph::template EdgeMap<int> IntEdgeMap;
   33.80 +    IntEdgeMap map(graph, 42);
   33.81 +    
   33.82 +    for (int i = 0; i < (int)edges.size(); ++i) {
   33.83 +      check(map[edges[i]] == 42, "Wrong map constructor.");      
   33.84 +    }
   33.85 +    
   33.86 +    for (int i = 0; i < num; ++i) {
   33.87 +      for (int j = i + 1; j < num; ++j) {
   33.88 +	edges.push_back(graph.addEdge(nodes[i], nodes[j]));
   33.89 +	map[edges.back()] = 23;
   33.90 +      }
   33.91 +    }
   33.92 +    graph.clear();
   33.93 +    edges.clear();    
   33.94 +  }
   33.95 +
   33.96 +}
   33.97 +
   33.98 +#endif
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/src/test/new_graph_test.cc	Wed Oct 27 22:38:50 2004 +0000
    34.3 @@ -0,0 +1,39 @@
    34.4 +/* -*- C++ -*-
    34.5 + * src/test/new_graph_test.cc - Part of LEMON, a generic C++ optimization library
    34.6 + *
    34.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    34.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    34.9 + *
   34.10 + * Permission to use, modify and distribute this software is granted
   34.11 + * provided that this copyright notice appears in all copies. For
   34.12 + * precise terms see the accompanying LICENSE file.
   34.13 + *
   34.14 + * This software is provided "AS IS" with no warranty of any kind,
   34.15 + * express or implied, and with no claim as to its suitability for any
   34.16 + * purpose.
   34.17 + *
   34.18 + */
   34.19 +
   34.20 +#include <lemon/skeletons/graph.h>
   34.21 +// #include <boost/concept_check.hpp>
   34.22 +
   34.23 +using namespace lemon::skeleton;
   34.24 +
   34.25 +// Borrowed from boost:
   34.26 +template <class T> inline void ignore_unused_variable_warning(const T&) { }
   34.27 +
   34.28 +int main()
   34.29 +{
   34.30 +  //    This is the "right" way to check a concept:
   34.31 +  // boost::function_requires< BaseGraphItemConcept<BaseGraphItem> >();
   34.32 +
   34.33 +  //    which is equivalent (considering compile-time checks) to
   34.34 +  // BaseGraphItemConcept<BaseGraphItem> bgic;
   34.35 +  // bgic.constraints();
   34.36 +  //    but not actually call or intatiates anything...
   34.37 +  //    It's doing aproximately this:
   34.38 +  typedef BaseGraphItemConcept<BaseGraphItem> CC;
   34.39 +  void (CC::*x)() = &CC::constraints;
   34.40 +  ignore_unused_variable_warning(x);
   34.41 +  //    But even more hackish...
   34.42 +}
    35.1 --- a/src/test/test_tools.h	Mon Oct 25 13:29:46 2004 +0000
    35.2 +++ b/src/test/test_tools.h	Wed Oct 27 22:38:50 2004 +0000
    35.3 @@ -70,7 +70,7 @@
    35.4  ///\return The nodes and edges of the generated graph.
    35.5  
    35.6  template<typename Graph>
    35.7 -PetStruct<Graph> addPetersen(Graph &G,int num=5)
    35.8 +PetStruct<Graph> addPetersen(Graph &G,int num = 5)
    35.9  {
   35.10    PetStruct<Graph> n;
   35.11  
   35.12 @@ -81,12 +81,50 @@
   35.13  
   35.14   for(int i=0;i<num;i++) {
   35.15     n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
   35.16 -   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
   35.17 -   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
   35.18 +   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1) % num]));
   35.19 +   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2) % num]));
   35.20    }
   35.21   return n;
   35.22  }
   35.23  
   35.24 +/// \brief Adds to the graph the reverse pair of all edge.
   35.25 +///
   35.26 +/// Adds to the graph the reverse pair of all edge.
   35.27 +///
   35.28 +template<class Graph> void bidirGraph(Graph &G)
   35.29 +{
   35.30 +  typedef typename Graph::Edge Edge;
   35.31 +  typedef typename Graph::EdgeIt EdgeIt;
   35.32 +  
   35.33 +  std::vector<Edge> ee;
   35.34 +  
   35.35 +  for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
   35.36 +
   35.37 +  for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
   35.38 +    G.addEdge(G.head(*p),G.tail(*p));
   35.39 +}
   35.40 +
   35.41 +
   35.42 +/// \brief Checks the bidirectioned Petersen graph.
   35.43 +///
   35.44 +///  Checks the bidirectioned Petersen graph.
   35.45 +///
   35.46 +template<class Graph> void checkBidirPetersen(Graph &G, int num = 5)
   35.47 +{
   35.48 +  typedef typename Graph::Node Node;
   35.49 +
   35.50 +  typedef typename Graph::EdgeIt EdgeIt;
   35.51 +  typedef typename Graph::NodeIt NodeIt;
   35.52 +
   35.53 +  checkGraphNodeList(G, 2 * num);
   35.54 +  checkGraphEdgeList(G, 6 * num);
   35.55 +
   35.56 +  for(NodeIt n(G);n!=INVALID;++n) {
   35.57 +    checkGraphInEdgeList(G, n, 3);
   35.58 +    checkGraphOutEdgeList(G, n, 3);
   35.59 +  }  
   35.60 +}
   35.61 +
   35.62  ///Structure returned by \ref addSymPetersen().
   35.63  
   35.64  ///Structure returned by \ref addSymPetersen().
    36.1 --- a/src/work/klao/TODO	Mon Oct 25 13:29:46 2004 +0000
    36.2 +++ b/src/work/klao/TODO	Wed Oct 27 22:38:50 2004 +0000
    36.3 @@ -1,1 +1,3 @@
    36.4 +full_graph.h -t atnez(et)ni!
    36.5 +
    36.6  megcsinalni, hogy mukodjon a kereses a doksiban