↑ Collapse diff ↑
Ignore white space 192 line context
1 1
LEMON code without an explicit copyright is covered by the following
2 2
copyright/license.
3 3

	
4
Copyright (C) 2003-2007 Egervary Jeno Kombinatorikus Optimalizalasi
4
Copyright (C) 2003-2008 Egervary Jeno Kombinatorikus Optimalizalasi
5 5
Kutatocsoport (Egervary Combinatorial Optimization Research Group,
6 6
EGRES).
7 7

	
8 8
Permission is hereby granted, free of charge, to any person or organization
9 9
obtaining a copy of the software and accompanying documentation covered by
10 10
this license (the "Software") to use, reproduce, display, distribute,
11 11
execute, and transmit the Software, and to prepare derivative works of the
12 12
Software, and to permit third-parties to whom the Software is furnished to
13 13
do so, all subject to the following:
14 14

	
15 15
The copyright notices in the Software and this entire statement, including
16 16
the above license grant, this restriction and the following disclaimer,
17 17
must be included in all copies of the Software, in whole or in part, and
18 18
all derivative works of the Software, unless such copies or derivative
19 19
works are solely in the form of machine-executable object code generated by
20 20
a source language processor.
21 21

	
22 22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 24
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
25 25
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
26 26
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
27 27
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 28
DEALINGS IN THE SOFTWARE.
29 29

	
30 30
===========================================================================
31 31
This license is a verbatim copy of the Boost Software License, Version 1.0.
32 32

	
33 33

	
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_BITS_ALTERATION_NOTIFIER_H
20 20
#define LEMON_BITS_ALTERATION_NOTIFIER_H
21 21

	
22 22
#include <vector>
23 23
#include <list>
24 24

	
25 25
#include <lemon/bits/utility.h>
26 26

	
27 27
///\ingroup graphbits
28 28
///\file
29 29
///\brief Observer notifier for graph alteration observers.
30 30

	
31 31
namespace lemon {
32 32

	
33 33
  /// \ingroup graphbits
34 34
  ///
35 35
  /// \brief Notifier class to notify observes about alterations in 
36 36
  /// a container.
37 37
  ///
38 38
  /// The simple graph's can be refered as two containers, one node container
39 39
  /// and one edge container. But they are not standard containers they
40 40
  /// does not store values directly they are just key continars for more
41 41
  /// value containers which are the node and edge maps.
42 42
  ///
43 43
  /// The graph's node and edge sets can be changed as we add or erase
44 44
  /// nodes and edges in the graph. Lemon would like to handle easily
45 45
  /// that the node and edge maps should contain values for all nodes or
46 46
  /// edges. If we want to check on every indicing if the map contains
47 47
  /// the current indicing key that cause a drawback in the performance
48 48
  /// in the library. We use another solution we notify all maps about
49 49
  /// an alteration in the graph, which cause only drawback on the
50 50
  /// alteration of the graph.
51 51
  ///
52 52
  /// This class provides an interface to the container. The \e first() and \e 
53 53
  /// next() member functions make possible to iterate on the keys of the
54 54
  /// container. The \e id() function returns an integer id for each key.
55 55
  /// The \e maxId() function gives back an upper bound of the ids.
56 56
  ///
57 57
  /// For the proper functonality of this class, we should notify it
58 58
  /// about each alteration in the container. The alterations have four type
59 59
  /// as \e add(), \e erase(), \e build() and \e clear(). The \e add() and
60 60
  /// \e erase() signals that only one or few items added or erased to or
61 61
  /// from the graph. If all items are erased from the graph or from an empty
62 62
  /// graph a new graph is builded then it can be signaled with the
63 63
  /// clear() and build() members. Important rule that if we erase items 
64 64
  /// from graph we should first signal the alteration and after that erase
65 65
  /// them from the container, on the other way on item addition we should
66 66
  /// first extend the container and just after that signal the alteration.
67 67
  ///
68 68
  /// The alteration can be observed with a class inherited from the
69 69
  /// \e ObserverBase nested class. The signals can be handled with
70 70
  /// overriding the virtual functions defined in the base class.  The
71 71
  /// observer base can be attached to the notifier with the 
72 72
  /// \e attach() member and can be detached with detach() function. The
73 73
  /// alteration handlers should not call any function which signals
74 74
  /// an other alteration in the same notifier and should not
75 75
  /// detach any observer from the notifier.
76 76
  ///
77 77
  /// Alteration observers try to be exception safe. If an \e add() or
78 78
  /// a \e clear() function throws an exception then the remaining
79 79
  /// observeres will not be notified and the fulfilled additions will
80 80
  /// be rolled back by calling the \e erase() or \e clear()
81 81
  /// functions. Thence the \e erase() and \e clear() should not throw
82 82
  /// exception. Actullay, it can be throw only 
83 83
  /// \ref AlterationObserver::ImmediateDetach ImmediateDetach
84 84
  /// exception which detach the observer from the notifier.
85 85
  ///
86 86
  /// There are some place when the alteration observing is not completly
87 87
  /// reliable. If we want to carry out the node degree in the graph
88 88
  /// as in the \ref InDegMap and we use the reverseEdge that cause 
89 89
  /// unreliable functionality. Because the alteration observing signals
90 90
  /// only erasing and adding but not the reversing it will stores bad
91 91
  /// degrees. The sub graph adaptors cannot signal the alterations because
92 92
  /// just a setting in the filter map can modify the graph and this cannot
93 93
  /// be watched in any way.
94 94
  ///
95 95
  /// \param _Container The container which is observed.
96 96
  /// \param _Item The item type which is obserbved.
97 97
  ///
98 98
  /// \author Balazs Dezso
99 99

	
100 100
  template <typename _Container, typename _Item>
101 101
  class AlterationNotifier {
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_BITS_ARRAY_MAP_H
20 20
#define LEMON_BITS_ARRAY_MAP_H
21 21

	
22 22
#include <memory>
23 23

	
24 24
#include <lemon/bits/traits.h>
25 25
#include <lemon/bits/alteration_notifier.h>
26 26
#include <lemon/concept_check.h>
27 27
#include <lemon/concepts/maps.h>
28 28

	
29 29
/// \ingroup graphbits
30 30
/// \file
31 31
/// \brief Graph map based on the array storage.
32 32

	
33 33
namespace lemon {
34 34

	
35 35
  /// \ingroup graphbits
36 36
  ///
37 37
  /// \brief Graph map based on the array storage.
38 38
  ///
39 39
  /// The ArrayMap template class is graph map structure what
40 40
  /// automatically updates the map when a key is added to or erased from
41 41
  /// the map. This map uses the allocators to implement 
42 42
  /// the container functionality.
43 43
  ///
44 44
  /// The template parameters are the Graph the current Item type and
45 45
  /// the Value type of the map.
46 46
  template <typename _Graph, typename _Item, typename _Value>
47 47
  class ArrayMap 
48 48
    : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
49 49
  public:
50 50
    /// The graph type of the maps. 
51 51
    typedef _Graph Graph;
52 52
    /// The item type of the map.
53 53
    typedef _Item Item;
54 54
    /// The reference map tag.
55 55
    typedef True ReferenceMapTag;
56 56

	
57 57
    /// The key type of the maps.
58 58
    typedef _Item Key;
59 59
    /// The value type of the map.
60 60
    typedef _Value Value;
61 61

	
62 62
    /// The const reference type of the map.
63 63
    typedef const _Value& ConstReference;
64 64
    /// The reference type of the map.
65 65
    typedef _Value& Reference;
66 66

	
67 67
    /// The notifier type.
68 68
    typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier;
69 69

	
70 70
    /// The MapBase of the Map which imlements the core regisitry function.
71 71
    typedef typename Notifier::ObserverBase Parent;
72 72
		
73 73
  private:
74 74
    typedef std::allocator<Value> Allocator;
75 75

	
76 76
  public:
77 77

	
78 78
    /// \brief Graph initialized map constructor.
79 79
    ///
80 80
    /// Graph initialized map constructor.
81 81
    explicit ArrayMap(const Graph& graph) {
82 82
      Parent::attach(graph.notifier(Item()));
83 83
      allocate_memory();
84 84
      Notifier* nf = Parent::notifier();
85 85
      Item it;
86 86
      for (nf->first(it); it != INVALID; nf->next(it)) {
87 87
	int id = nf->id(it);;
88 88
	allocator.construct(&(values[id]), Value());
89 89
      }								
90 90
    }
91 91

	
92 92
    /// \brief Constructor to use default value to initialize the map. 
93 93
    ///
94 94
    /// It constructs a map and initialize all of the the map. 
95 95
    ArrayMap(const Graph& graph, const Value& value) {
96 96
      Parent::attach(graph.notifier(Item()));
97 97
      allocate_memory();
98 98
      Notifier* nf = Parent::notifier();
99 99
      Item it;
100 100
      for (nf->first(it); it != INVALID; nf->next(it)) {
101 101
	int id = nf->id(it);;
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_BITS_BASE_EXTENDER_H
20 20
#define LEMON_BITS_BASE_EXTENDER_H
21 21

	
22 22
#include <lemon/bits/invalid.h>
23 23
#include <lemon/error.h>
24 24

	
25 25
#include <lemon/bits/map_extender.h>
26 26
#include <lemon/bits/default_map.h>
27 27

	
28 28
#include <lemon/concept_check.h>
29 29
#include <lemon/concepts/maps.h>
30 30

	
31 31
///\ingroup digraphbits
32 32
///\file
33 33
///\brief Extenders for the digraph types
34 34
namespace lemon {
35 35

	
36 36
  /// \ingroup digraphbits
37 37
  ///
38 38
  /// \brief BaseDigraph to BaseGraph extender
39 39
  template <typename Base>
40 40
  class UndirDigraphExtender : public Base {
41 41

	
42 42
  public:
43 43

	
44 44
    typedef Base Parent;
45 45
    typedef typename Parent::Arc Edge;
46 46
    typedef typename Parent::Node Node;
47 47

	
48 48
    typedef True UndirectedTag;
49 49

	
50 50
    class Arc : public Edge {
51 51
      friend class UndirDigraphExtender;
52 52

	
53 53
    protected:
54 54
      bool forward;
55 55

	
56 56
      Arc(const Edge &ue, bool _forward) :
57 57
        Edge(ue), forward(_forward) {}
58 58

	
59 59
    public:
60 60
      Arc() {}
61 61

	
62 62
      /// Invalid arc constructor
63 63
      Arc(Invalid i) : Edge(i), forward(true) {}
64 64

	
65 65
      bool operator==(const Arc &that) const {
66 66
	return forward==that.forward && Edge(*this)==Edge(that);
67 67
      }
68 68
      bool operator!=(const Arc &that) const {
69 69
	return forward!=that.forward || Edge(*this)!=Edge(that);
70 70
      }
71 71
      bool operator<(const Arc &that) const {
72 72
	return forward<that.forward ||
73 73
	  (!(that.forward<forward) && Edge(*this)<Edge(that));
74 74
      }
75 75
    };
76 76

	
77 77

	
78 78

	
79 79
    using Parent::source;
80 80

	
81 81
    /// Source of the given Arc.
82 82
    Node source(const Arc &e) const {
83 83
      return e.forward ? Parent::source(e) : Parent::target(e);
84 84
    }
85 85

	
86 86
    using Parent::target;
87 87

	
88 88
    /// Target of the given Arc.
89 89
    Node target(const Arc &e) const {
90 90
      return e.forward ? Parent::target(e) : Parent::source(e);
91 91
    }
92 92

	
93 93
    /// \brief Directed arc from an edge.
94 94
    ///
95 95
    /// Returns a directed arc corresponding to the specified Edge.
96 96
    /// If the given bool is true the given edge and the
97 97
    /// returned arc have the same source node.
98 98
    static Arc direct(const Edge &ue, bool d) {
99 99
      return Arc(ue, d);
100 100
    }
101 101

	
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_BITS_DEFAULT_MAP_H
20 20
#define LEMON_BITS_DEFAULT_MAP_H
21 21

	
22 22

	
23 23
#include <lemon/bits/array_map.h>
24 24
#include <lemon/bits/vector_map.h>
25 25
//#include <lemon/bits/debug_map.h>
26 26

	
27 27
///\ingroup graphbits
28 28
///\file
29 29
///\brief Graph maps that construct and destruct their elements dynamically.
30 30

	
31 31
namespace lemon {
32 32
  
33 33
  
34 34
  //#ifndef LEMON_USE_DEBUG_MAP
35 35

	
36 36
  template <typename _Graph, typename _Item, typename _Value>
37 37
  struct DefaultMapSelector {
38 38
    typedef ArrayMap<_Graph, _Item, _Value> Map;
39 39
  };
40 40

	
41 41
  // bool
42 42
  template <typename _Graph, typename _Item>
43 43
  struct DefaultMapSelector<_Graph, _Item, bool> {
44 44
    typedef VectorMap<_Graph, _Item, bool> Map;
45 45
  };
46 46

	
47 47
  // char
48 48
  template <typename _Graph, typename _Item>
49 49
  struct DefaultMapSelector<_Graph, _Item, char> {
50 50
    typedef VectorMap<_Graph, _Item, char> Map;
51 51
  };
52 52

	
53 53
  template <typename _Graph, typename _Item>
54 54
  struct DefaultMapSelector<_Graph, _Item, signed char> {
55 55
    typedef VectorMap<_Graph, _Item, signed char> Map;
56 56
  };
57 57

	
58 58
  template <typename _Graph, typename _Item>
59 59
  struct DefaultMapSelector<_Graph, _Item, unsigned char> {
60 60
    typedef VectorMap<_Graph, _Item, unsigned char> Map;
61 61
  };
62 62

	
63 63

	
64 64
  // int
65 65
  template <typename _Graph, typename _Item>
66 66
  struct DefaultMapSelector<_Graph, _Item, signed int> {
67 67
    typedef VectorMap<_Graph, _Item, signed int> Map;
68 68
  };
69 69

	
70 70
  template <typename _Graph, typename _Item>
71 71
  struct DefaultMapSelector<_Graph, _Item, unsigned int> {
72 72
    typedef VectorMap<_Graph, _Item, unsigned int> Map;
73 73
  };
74 74

	
75 75

	
76 76
  // short
77 77
  template <typename _Graph, typename _Item>
78 78
  struct DefaultMapSelector<_Graph, _Item, signed short> {
79 79
    typedef VectorMap<_Graph, _Item, signed short> Map;
80 80
  };
81 81

	
82 82
  template <typename _Graph, typename _Item>
83 83
  struct DefaultMapSelector<_Graph, _Item, unsigned short> {
84 84
    typedef VectorMap<_Graph, _Item, unsigned short> Map;
85 85
  };
86 86

	
87 87

	
88 88
  // long
89 89
  template <typename _Graph, typename _Item>
90 90
  struct DefaultMapSelector<_Graph, _Item, signed long> {
91 91
    typedef VectorMap<_Graph, _Item, signed long> Map;
92 92
  };
93 93

	
94 94
  template <typename _Graph, typename _Item>
95 95
  struct DefaultMapSelector<_Graph, _Item, unsigned long> {
96 96
    typedef VectorMap<_Graph, _Item, unsigned long> Map;
97 97
  };
98 98

	
99 99

	
100 100
#if defined __GNUC__ && !defined __STRICT_ANSI__
101 101

	
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_BITS_GRAPH_EXTENDER_H
20 20
#define LEMON_BITS_GRAPH_EXTENDER_H
21 21

	
22 22
#include <lemon/bits/invalid.h>
23 23
#include <lemon/bits/utility.h>
24 24

	
25 25
#include <lemon/bits/map_extender.h>
26 26
#include <lemon/bits/default_map.h>
27 27

	
28 28
#include <lemon/concept_check.h>
29 29
#include <lemon/concepts/maps.h>
30 30

	
31 31
///\ingroup graphbits
32 32
///\file
33 33
///\brief Extenders for the digraph types
34 34
namespace lemon {
35 35

	
36 36
  /// \ingroup graphbits
37 37
  ///
38 38
  /// \brief Extender for the Digraphs
39 39
  template <typename Base>
40 40
  class DigraphExtender : public Base {
41 41
  public:
42 42

	
43 43
    typedef Base Parent;
44 44
    typedef DigraphExtender Digraph;
45 45

	
46 46
    // Base extensions
47 47

	
48 48
    typedef typename Parent::Node Node;
49 49
    typedef typename Parent::Arc Arc;
50 50

	
51 51
    int maxId(Node) const {
52 52
      return Parent::maxNodeId();
53 53
    }
54 54

	
55 55
    int maxId(Arc) const {
56 56
      return Parent::maxArcId();
57 57
    }
58 58

	
59 59
    Node fromId(int id, Node) const {
60 60
      return Parent::nodeFromId(id);
61 61
    }
62 62

	
63 63
    Arc fromId(int id, Arc) const {
64 64
      return Parent::arcFromId(id);
65 65
    }
66 66

	
67 67
    Node oppositeNode(const Node &node, const Arc &arc) const {
68 68
      if (node == Parent::source(arc))
69 69
	return Parent::target(arc);
70 70
      else if(node == Parent::target(arc))
71 71
	return Parent::source(arc);
72 72
      else
73 73
	return INVALID;
74 74
    }
75 75

	
76 76
    // Alterable extension
77 77

	
78 78
    typedef AlterationNotifier<DigraphExtender, Node> NodeNotifier;
79 79
    typedef AlterationNotifier<DigraphExtender, Arc> ArcNotifier;
80 80

	
81 81

	
82 82
  protected:
83 83

	
84 84
    mutable NodeNotifier node_notifier;
85 85
    mutable ArcNotifier arc_notifier;
86 86

	
87 87
  public:
88 88

	
89 89
    NodeNotifier& notifier(Node) const {
90 90
      return node_notifier;
91 91
    }
92 92
    
93 93
    ArcNotifier& notifier(Arc) const {
94 94
      return arc_notifier;
95 95
    }
96 96

	
97 97
    class NodeIt : public Node { 
98 98
      const Digraph* _digraph;
99 99
    public:
100 100

	
101 101
      NodeIt() {}
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_BITS_MAP_EXTENDER_H
20 20
#define LEMON_BITS_MAP_EXTENDER_H
21 21

	
22 22
#include <iterator>
23 23

	
24 24
#include <lemon/bits/traits.h>
25 25

	
26 26
#include <lemon/concept_check.h>
27 27
#include <lemon/concepts/maps.h>
28 28

	
29 29
///\file
30 30
///\brief Extenders for iterable maps.
31 31

	
32 32
namespace lemon {
33 33

	
34 34
  /// \ingroup graphbits
35 35
  /// 
36 36
  /// \brief Extender for maps
37 37
  template <typename _Map>
38 38
  class MapExtender : public _Map {
39 39
  public:
40 40

	
41 41
    typedef _Map Parent;
42 42
    typedef MapExtender Map;
43 43

	
44 44

	
45 45
    typedef typename Parent::Graph Graph;
46 46
    typedef typename Parent::Key Item;
47 47

	
48 48
    typedef typename Parent::Key Key;
49 49
    typedef typename Parent::Value Value;
50 50

	
51 51
    class MapIt;
52 52
    class ConstMapIt;
53 53

	
54 54
    friend class MapIt;
55 55
    friend class ConstMapIt;
56 56

	
57 57
  public:
58 58

	
59 59
    MapExtender(const Graph& graph) 
60 60
      : Parent(graph) {}
61 61

	
62 62
    MapExtender(const Graph& graph, const Value& value) 
63 63
      : Parent(graph, value) {}
64 64

	
65 65
    MapExtender& operator=(const MapExtender& cmap) {
66 66
      return operator=<MapExtender>(cmap);
67 67
    }
68 68

	
69 69
    template <typename CMap>
70 70
    MapExtender& operator=(const CMap& cmap) {
71 71
      Parent::operator=(cmap);
72 72
      return *this;
73 73
    } 
74 74

	
75 75
    class MapIt : public Item {
76 76
    public:
77 77
      
78 78
      typedef Item Parent;
79 79
      typedef typename Map::Value Value;
80 80
      
81 81
      MapIt() {}
82 82

	
83 83
      MapIt(Invalid i) : Parent(i) { }
84 84

	
85 85
      explicit MapIt(Map& _map) : map(_map) {
86 86
        map.notifier()->first(*this);
87 87
      }
88 88

	
89 89
      MapIt(const Map& _map, const Item& item) 
90 90
	: Parent(item), map(_map) {}
91 91

	
92 92
      MapIt& operator++() { 
93 93
	map.notifier()->next(*this);
94 94
	return *this; 
95 95
      }
96 96
      
97 97
      typename MapTraits<Map>::ConstReturnValue operator*() const {
98 98
	return map[*this];
99 99
      }
100 100

	
101 101
      typename MapTraits<Map>::ReturnValue operator*() {
Ignore white space 192 line context
1 1

	
2 2
/* -*- C++ -*-
3 3
 *
4 4
 * This file is a part of LEMON, a generic C++ optimization library
5 5
 *
6
 * Copyright (C) 2003-2007
6
 * Copyright (C) 2003-2008
7 7
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
8 8
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 9
 *
10 10
 * Permission to use, modify and distribute this software is granted
11 11
 * provided that this copyright notice appears in all copies. For
12 12
 * precise terms see the accompanying LICENSE file.
13 13
 *
14 14
 * This software is provided "AS IS" with no warranty of any kind,
15 15
 * express or implied, and with no claim as to its suitability for any
16 16
 * purpose.
17 17
 *
18 18
 */
19 19

	
20 20
#ifndef LEMON_BITS_TRAITS_H
21 21
#define LEMON_BITS_TRAITS_H
22 22

	
23 23
#include <lemon/bits/utility.h>
24 24

	
25 25
///\file
26 26
///\brief Traits for graphs and maps
27 27
///
28 28

	
29 29
namespace lemon {
30 30
  template <typename _Graph, typename _Item>
31 31
  class ItemSetTraits {};
32 32
  
33 33

	
34 34
  template <typename Graph, typename Enable = void>
35 35
  struct NodeNotifierIndicator {
36 36
    typedef InvalidType Type;
37 37
  };
38 38
  template <typename Graph>
39 39
  struct NodeNotifierIndicator<
40 40
    Graph, 
41 41
    typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
42 42
  > { 
43 43
    typedef typename Graph::NodeNotifier Type;
44 44
  };
45 45

	
46 46
  template <typename _Graph>
47 47
  class ItemSetTraits<_Graph, typename _Graph::Node> {
48 48
  public:
49 49
    
50 50
    typedef _Graph Graph;
51 51

	
52 52
    typedef typename Graph::Node Item;
53 53
    typedef typename Graph::NodeIt ItemIt;
54 54

	
55 55
    typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
56 56

	
57 57
    template <typename _Value>
58 58
    class Map : public Graph::template NodeMap<_Value> {
59 59
    public:
60 60
      typedef typename Graph::template NodeMap<_Value> Parent; 
61 61
      typedef typename Graph::template NodeMap<_Value> Type; 
62 62
      typedef typename Parent::Value Value;
63 63

	
64 64
      Map(const Graph& _digraph) : Parent(_digraph) {}
65 65
      Map(const Graph& _digraph, const Value& _value) 
66 66
	: Parent(_digraph, _value) {}
67 67

	
68 68
     };
69 69

	
70 70
  };
71 71

	
72 72
  template <typename Graph, typename Enable = void>
73 73
  struct ArcNotifierIndicator {
74 74
    typedef InvalidType Type;
75 75
  };
76 76
  template <typename Graph>
77 77
  struct ArcNotifierIndicator<
78 78
    Graph, 
79 79
    typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
80 80
  > { 
81 81
    typedef typename Graph::ArcNotifier Type;
82 82
  };
83 83

	
84 84
  template <typename _Graph>
85 85
  class ItemSetTraits<_Graph, typename _Graph::Arc> {
86 86
  public:
87 87
    
88 88
    typedef _Graph Graph;
89 89

	
90 90
    typedef typename Graph::Arc Item;
91 91
    typedef typename Graph::ArcIt ItemIt;
92 92

	
93 93
    typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier;
94 94

	
95 95
    template <typename _Value>
96 96
    class Map : public Graph::template ArcMap<_Value> {
97 97
    public:
98 98
      typedef typename Graph::template ArcMap<_Value> Parent; 
99 99
      typedef typename Graph::template ArcMap<_Value> Type; 
100 100
      typedef typename Parent::Value Value;
101 101

	
102 102
      Map(const Graph& _digraph) : Parent(_digraph) {}
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_BITS_VECTOR_MAP_H
20 20
#define LEMON_BITS_VECTOR_MAP_H
21 21

	
22 22
#include <vector>
23 23
#include <algorithm>
24 24

	
25 25
#include <lemon/bits/traits.h>
26 26
#include <lemon/bits/utility.h>
27 27

	
28 28
#include <lemon/bits/alteration_notifier.h>
29 29

	
30 30
#include <lemon/concept_check.h>
31 31
#include <lemon/concepts/maps.h>
32 32

	
33 33
///\ingroup graphbits
34 34
///
35 35
///\file
36 36
///\brief Vector based graph maps.
37 37
namespace lemon {
38 38

	
39 39
  /// \ingroup graphbits
40 40
  ///
41 41
  /// \brief Graph map based on the std::vector storage.
42 42
  ///
43 43
  /// The VectorMap template class is graph map structure what
44 44
  /// automatically updates the map when a key is added to or erased from
45 45
  /// the map. This map type uses the std::vector to store the values.
46 46
  ///
47 47
  /// \param Notifier The AlterationNotifier that will notify this map.
48 48
  /// \param Item The item type of the graph items.
49 49
  /// \param Value The value type of the map.
50 50
  /// 
51 51
  /// \author Balazs Dezso  	
52 52
  template <typename _Graph, typename _Item, typename _Value>
53 53
  class VectorMap 
54 54
    : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
55 55
  private:
56 56
		
57 57
    /// The container type of the map.
58 58
    typedef std::vector<_Value> Container;	
59 59

	
60 60
  public:
61 61

	
62 62
    /// The graph type of the map. 
63 63
    typedef _Graph Graph;
64 64
    /// The item type of the map.
65 65
    typedef _Item Item;
66 66
    /// The reference map tag.
67 67
    typedef True ReferenceMapTag;
68 68

	
69 69
    /// The key type of the map.
70 70
    typedef _Item Key;
71 71
    /// The value type of the map.
72 72
    typedef _Value Value;
73 73

	
74 74
    /// The notifier type.
75 75
    typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier;
76 76

	
77 77
    /// The map type.
78 78
    typedef VectorMap Map;
79 79
    /// The base class of the map.
80 80
    typedef typename Notifier::ObserverBase Parent;
81 81

	
82 82
    /// The reference type of the map;
83 83
    typedef typename Container::reference Reference;
84 84
    /// The const reference type of the map;
85 85
    typedef typename Container::const_reference ConstReference;
86 86

	
87 87

	
88 88
    /// \brief Constructor to attach the new map into the notifier.
89 89
    ///
90 90
    /// It constructs a map and attachs it into the notifier.
91 91
    /// It adds all the items of the graph to the map.
92 92
    VectorMap(const Graph& graph) {
93 93
      Parent::attach(graph.notifier(Item()));
94 94
      container.resize(Parent::notifier()->maxId() + 1);
95 95
    }
96 96

	
97 97
    /// \brief Constructor uses given value to initialize the map. 
98 98
    ///
99 99
    /// It constructs a map uses a given value to initialize the map. 
100 100
    /// It adds all the items of the graph to the map.
101 101
    VectorMap(const Graph& graph, const Value& value) {
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_CONCEPT_DIGRAPH_H
20 20
#define LEMON_CONCEPT_DIGRAPH_H
21 21

	
22 22
///\ingroup graph_concepts
23 23
///\file
24 24
///\brief The concept of directed graphs.
25 25

	
26 26
#include <lemon/bits/invalid.h>
27 27
#include <lemon/bits/utility.h>
28 28
#include <lemon/concepts/maps.h>
29 29
#include <lemon/concept_check.h>
30 30
#include <lemon/concepts/graph_components.h>
31 31

	
32 32
namespace lemon {
33 33
  namespace concepts {
34 34

	
35 35
    /// \ingroup graph_concepts
36 36
    ///
37 37
    /// \brief Class describing the concept of directed graphs.
38 38
    ///
39 39
    /// This class describes the \ref concept "concept" of the
40 40
    /// immutable directed digraphs.
41 41
    ///
42 42
    /// Note that actual digraph implementation like @ref ListDigraph or
43 43
    /// @ref SmartDigraph may have several additional functionality.
44 44
    ///
45 45
    /// \sa concept
46 46
    class Digraph {
47 47
    private:
48 48
      ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
49 49
      
50 50
      ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
51 51
      ///
52 52
      Digraph(const Digraph &) {};
53 53
      ///\brief Assignment of \ref Digraph "Digraph"s to another ones are
54 54
      ///\e not allowed. Use DigraphCopy() instead.
55 55
      
56 56
      ///Assignment of \ref Digraph "Digraph"s to another ones are
57 57
      ///\e not allowed.  Use DigraphCopy() instead.
58 58

	
59 59
      void operator=(const Digraph &) {}
60 60
    public:
61 61
      ///\e
62 62

	
63 63
      /// Defalult constructor.
64 64

	
65 65
      /// Defalult constructor.
66 66
      ///
67 67
      Digraph() { }
68 68
      /// Class for identifying a node of the digraph
69 69

	
70 70
      /// This class identifies a node of the digraph. It also serves
71 71
      /// as a base class of the node iterators,
72 72
      /// thus they will convert to this type.
73 73
      class Node {
74 74
      public:
75 75
        /// Default constructor
76 76

	
77 77
        /// @warning The default constructor sets the iterator
78 78
        /// to an undefined value.
79 79
        Node() { }
80 80
        /// Copy constructor.
81 81

	
82 82
        /// Copy constructor.
83 83
        ///
84 84
        Node(const Node&) { }
85 85

	
86 86
        /// Invalid constructor \& conversion.
87 87

	
88 88
        /// This constructor initializes the iterator to be invalid.
89 89
        /// \sa Invalid for more details.
90 90
        Node(Invalid) { }
91 91
        /// Equality operator
92 92

	
93 93
        /// Two iterators are equal if and only if they point to the
94 94
        /// same object or both are invalid.
95 95
        bool operator==(Node) const { return true; }
96 96

	
97 97
        /// Inequality operator
98 98
        
99 99
        /// \sa operator==(Node n)
100 100
        ///
101 101
        bool operator!=(Node) const { return true; }
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
///\ingroup graph_concepts
20 20
///\file
21 21
///\brief The concept of Undirected Graphs.
22 22

	
23 23
#ifndef LEMON_CONCEPT_GRAPH_H
24 24
#define LEMON_CONCEPT_GRAPH_H
25 25

	
26 26
#include <lemon/concepts/graph_components.h>
27 27
#include <lemon/concepts/graph.h>
28 28
#include <lemon/bits/utility.h>
29 29

	
30 30
namespace lemon {
31 31
  namespace concepts {
32 32

	
33 33
    /// \ingroup graph_concepts
34 34
    ///
35 35
    /// \brief Class describing the concept of Undirected Graphs.
36 36
    ///
37 37
    /// This class describes the common interface of all Undirected
38 38
    /// Graphs.
39 39
    ///
40 40
    /// As all concept describing classes it provides only interface
41 41
    /// without any sensible implementation. So any algorithm for
42 42
    /// undirected graph should compile with this class, but it will not
43 43
    /// run properly, of course.
44 44
    ///
45 45
    /// The LEMON undirected graphs also fulfill the concept of
46 46
    /// directed graphs (\ref lemon::concepts::Digraph "Digraph
47 47
    /// Concept"). Each edges can be seen as two opposite
48 48
    /// directed arc and consequently the undirected graph can be
49 49
    /// seen as the direceted graph of these directed arcs. The
50 50
    /// Graph has the Edge inner class for the edges and
51 51
    /// the Arc type for the directed arcs. The Arc type is
52 52
    /// convertible to Edge or inherited from it so from a directed
53 53
    /// arc we can get the represented edge.
54 54
    ///
55 55
    /// In the sense of the LEMON each edge has a default
56 56
    /// direction (it should be in every computer implementation,
57 57
    /// because the order of edge's nodes defines an
58 58
    /// orientation). With the default orientation we can define that
59 59
    /// the directed arc is forward or backward directed. With the \c
60 60
    /// direction() and \c direct() function we can get the direction
61 61
    /// of the directed arc and we can direct an edge.
62 62
    ///
63 63
    /// The EdgeIt is an iterator for the edges. We can use
64 64
    /// the EdgeMap to map values for the edges. The InArcIt and
65 65
    /// OutArcIt iterates on the same edges but with opposite
66 66
    /// direction. The IncEdgeIt iterates also on the same edges
67 67
    /// as the OutArcIt and InArcIt but it is not convertible to Arc just
68 68
    /// to Edge.  
69 69
    class Graph {
70 70
    public:
71 71
      /// \brief The undirected graph should be tagged by the
72 72
      /// UndirectedTag.
73 73
      ///
74 74
      /// The undirected graph should be tagged by the UndirectedTag. This
75 75
      /// tag helps the enable_if technics to make compile time 
76 76
      /// specializations for undirected graphs.  
77 77
      typedef True UndirectedTag;
78 78

	
79 79
      /// \brief The base type of node iterators, 
80 80
      /// or in other words, the trivial node iterator.
81 81
      ///
82 82
      /// This is the base type of each node iterator,
83 83
      /// thus each kind of node iterator converts to this.
84 84
      /// More precisely each kind of node iterator should be inherited 
85 85
      /// from the trivial node iterator.
86 86
      class Node {
87 87
      public:
88 88
        /// Default constructor
89 89

	
90 90
        /// @warning The default constructor sets the iterator
91 91
        /// to an undefined value.
92 92
        Node() { }
93 93
        /// Copy constructor.
94 94

	
95 95
        /// Copy constructor.
96 96
        ///
97 97
        Node(const Node&) { }
98 98

	
99 99
        /// Invalid constructor \& conversion.
100 100

	
101 101
        /// This constructor initializes the iterator to be invalid.
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
///\ingroup graph_concepts
20 20
///\file
21 21
///\brief The concept of graph components.
22 22

	
23 23

	
24 24
#ifndef LEMON_CONCEPT_GRAPH_COMPONENTS_H
25 25
#define LEMON_CONCEPT_GRAPH_COMPONENTS_H
26 26

	
27 27
#include <lemon/bits/invalid.h>
28 28
#include <lemon/concepts/maps.h>
29 29

	
30 30
#include <lemon/bits/alteration_notifier.h>
31 31

	
32 32
namespace lemon {
33 33
  namespace concepts {
34 34

	
35 35
    /// \brief Skeleton class for graph Node and Arc types
36 36
    ///
37 37
    /// This class describes the interface of Node and Arc (and Edge
38 38
    /// in undirected graphs) subtypes of graph types.
39 39
    ///
40 40
    /// \note This class is a template class so that we can use it to
41 41
    /// create graph skeleton classes. The reason for this is than Node
42 42
    /// and Arc types should \em not derive from the same base class.
43 43
    /// For Node you should instantiate it with character 'n' and for Arc
44 44
    /// with 'a'.
45 45

	
46 46
#ifndef DOXYGEN
47 47
    template <char _selector = '0'>
48 48
#endif
49 49
    class GraphItem {
50 50
    public:
51 51
      /// \brief Default constructor.
52 52
      ///      
53 53
      /// \warning The default constructor is not required to set
54 54
      /// the item to some well-defined value. So you should consider it
55 55
      /// as uninitialized.
56 56
      GraphItem() {}
57 57
      /// \brief Copy constructor.
58 58
      ///
59 59
      /// Copy constructor.
60 60
      ///
61 61
      GraphItem(const GraphItem &) {}
62 62
      /// \brief Invalid constructor \& conversion.
63 63
      ///
64 64
      /// This constructor initializes the item to be invalid.
65 65
      /// \sa Invalid for more details.
66 66
      GraphItem(Invalid) {}
67 67
      /// \brief Assign operator for nodes.
68 68
      ///
69 69
      /// The nodes are assignable. 
70 70
      ///
71 71
      GraphItem& operator=(GraphItem const&) { return *this; }
72 72
      /// \brief Equality operator.
73 73
      ///
74 74
      /// Two iterators are equal if and only if they represents the
75 75
      /// same node in the graph or both are invalid.
76 76
      bool operator==(GraphItem) const { return false; }
77 77
      /// \brief Inequality operator.
78 78
      ///
79 79
      /// \sa operator==(const Node& n)
80 80
      ///
81 81
      bool operator!=(GraphItem) const { return false; }
82 82

	
83 83
      /// \brief Artificial ordering operator.
84 84
      ///
85 85
      /// To allow the use of graph descriptors as key type in std::map or
86 86
      /// similar associative container we require this.
87 87
      ///
88 88
      /// \note This operator only have to define some strict ordering of
89 89
      /// the items; this order has nothing to do with the iteration
90 90
      /// ordering of the items.
91 91
      bool operator<(GraphItem) const { return false; }
92 92

	
93 93
      template<typename _GraphItem>
94 94
      struct Constraints {
95 95
	void constraints() {
96 96
	  _GraphItem i1;
97 97
	  _GraphItem i2 = i1;
98 98
	  _GraphItem i3 = INVALID;
99 99
	  
100 100
	  i1 = i2 = i3;
101 101

	
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#include <iostream>
20 20
#include <vector>
21 21

	
22 22
#include <lemon/concepts/digraph.h>
23 23
#include <lemon/list_graph.h>
24 24
//#include <lemon/smart_graph.h>
25 25
//#include <lemon/full_graph.h>
26 26
//#include <lemon/hypercube_graph.h>
27 27

	
28 28
#include "test_tools.h"
29 29
#include "digraph_test.h"
30 30
#include "map_test.h"
31 31

	
32 32

	
33 33
using namespace lemon;
34 34
using namespace lemon::concepts;
35 35

	
36 36

	
37 37
int main() {
38 38
  { // checking digraph components
39 39
    checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
40 40

	
41 41
    checkConcept<IDableDigraphComponent<>, 
42 42
      IDableDigraphComponent<> >();
43 43

	
44 44
    checkConcept<IterableDigraphComponent<>, 
45 45
      IterableDigraphComponent<> >();
46 46

	
47 47
    checkConcept<MappableDigraphComponent<>, 
48 48
      MappableDigraphComponent<> >();
49 49

	
50 50
  }
51 51
  { // checking skeleton digraphs
52 52
    checkConcept<Digraph, Digraph>();
53 53
  }
54 54
  { // checking list digraph
55 55
    checkConcept<Digraph, ListDigraph >();
56 56
    checkConcept<AlterableDigraphComponent<>, ListDigraph>();
57 57
    checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
58 58
    checkConcept<ClearableDigraphComponent<>, ListDigraph>();
59 59
    checkConcept<ErasableDigraphComponent<>, ListDigraph>();
60 60

	
61 61
    checkDigraph<ListDigraph>();
62 62
    checkGraphNodeMap<ListDigraph>();
63 63
    checkGraphArcMap<ListDigraph>();
64 64
  }
65 65
//   { // checking smart digraph
66 66
//     checkConcept<Digraph, SmartDigraph >();
67 67

	
68 68
//     checkDigraph<SmartDigraph>();
69 69
//     checkDigraphNodeMap<SmartDigraph>();
70 70
//     checkDigraphArcMap<SmartDigraph>();
71 71
//   }
72 72
//   { // checking full digraph
73 73
//     checkConcept<Digraph, FullDigraph >();
74 74
//   }
75 75
//   { // checking full digraph
76 76
//     checkConcept<Digraph, HyperCubeDigraph >();
77 77
//   }
78 78

	
79 79
  std::cout << __FILE__ ": All tests passed.\n";
80 80

	
81 81
  return 0;
82 82
}
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_TEST_GRAPH_TEST_H
20 20
#define LEMON_TEST_GRAPH_TEST_H
21 21

	
22 22
//#include <lemon/graph_utils.h>
23 23
#include "test_tools.h"
24 24

	
25 25
//! \ingroup misc
26 26
//! \file
27 27
//! \brief Some utility and test cases to test digraph classes.
28 28
namespace lemon {
29 29

	
30 30
  ///Structure returned by \ref addPetersen().
31 31

	
32 32
  ///Structure returned by \ref addPetersen().
33 33
  ///
34 34
  template<class Digraph> 
35 35
  struct PetStruct
36 36
  {
37 37
    ///Vector containing the outer nodes.
38 38
    std::vector<typename Digraph::Node> outer;
39 39
    ///Vector containing the inner nodes.
40 40
    std::vector<typename Digraph::Node> inner;
41 41
    ///Vector containing the edges of the inner circle.
42 42
    std::vector<typename Digraph::Arc> incir;
43 43
    ///Vector containing the edges of the outer circle.
44 44
    std::vector<typename Digraph::Arc> outcir;
45 45
    ///Vector containing the chord edges.
46 46
    std::vector<typename Digraph::Arc> chords;
47 47
  };
48 48

	
49 49

	
50 50

	
51 51
  ///Adds a Petersen graph to \c G.
52 52

	
53 53
  ///Adds a Petersen graph to \c G.
54 54
  ///\return The nodes and edges of the generated graph.
55 55

	
56 56
  template<typename Digraph>
57 57
  PetStruct<Digraph> addPetersen(Digraph &G,int num = 5)
58 58
  {
59 59
    PetStruct<Digraph> n;
60 60

	
61 61
    for(int i=0;i<num;i++) {
62 62
      n.outer.push_back(G.addNode());
63 63
      n.inner.push_back(G.addNode());
64 64
    }
65 65

	
66 66
    for(int i=0;i<num;i++) {
67 67
      n.chords.push_back(G.addArc(n.outer[i],n.inner[i]));
68 68
      n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1) % num]));
69 69
      n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2) % num]));
70 70
    }
71 71
    return n;
72 72
  }
73 73

	
74 74
  /// \brief Adds to the digraph the reverse pair of all edges.
75 75
  ///
76 76
  /// Adds to the digraph the reverse pair of all edges.
77 77
  ///
78 78
  template<class Digraph> 
79 79
  void bidirDigraph(Digraph &G)
80 80
  {
81 81
    typedef typename Digraph::Arc Arc;
82 82
    typedef typename Digraph::ArcIt ArcIt;
83 83
  
84 84
    std::vector<Arc> ee;
85 85
  
86 86
    for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e);
87 87

	
88 88
    for(typename std::vector<Arc>::iterator p=ee.begin();p!=ee.end();p++)
89 89
      G.addArc(G.target(*p),G.source(*p));
90 90
  }
91 91

	
92 92

	
93 93
  /// \brief Checks the bidirectioned Petersen graph.
94 94
  ///
95 95
  ///  Checks the bidirectioned Petersen graph.
96 96
  ///
97 97
  template<class Digraph> 
98 98
  void checkBidirPetersen(Digraph &G, int num = 5)
99 99
  {
100 100
    typedef typename Digraph::Node Node;
101 101

	
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#include <lemon/concepts/graph.h>
20 20
#include <lemon/list_graph.h>
21 21
// #include <lemon/smart_graph.h>
22 22
// #include <lemon/full_graph.h>
23 23
// #include <lemon/grid_graph.h>
24 24

	
25 25
//#include <lemon/graph_utils.h>
26 26

	
27 27
#include "test_tools.h"
28 28

	
29 29

	
30 30
using namespace lemon;
31 31
using namespace lemon::concepts;
32 32

	
33 33
void check_concepts() {
34 34

	
35 35
  { // checking digraph components
36 36
    checkConcept<BaseGraphComponent, BaseGraphComponent >();
37 37

	
38 38
    checkConcept<IDableGraphComponent<>, 
39 39
      IDableGraphComponent<> >();
40 40

	
41 41
    checkConcept<IterableGraphComponent<>, 
42 42
      IterableGraphComponent<> >();
43 43

	
44 44
    checkConcept<MappableGraphComponent<>, 
45 45
      MappableGraphComponent<> >();
46 46

	
47 47
  }
48 48
  {
49 49
    checkConcept<Graph, ListGraph>();    
50 50
//     checkConcept<Graph, SmartGraph>();    
51 51
//     checkConcept<Graph, FullGraph>();    
52 52
//     checkConcept<Graph, Graph>();    
53 53
//     checkConcept<Graph, GridGraph>();
54 54
  }
55 55
}
56 56

	
57 57
template <typename Graph>
58 58
void check_item_counts(Graph &g, int n, int e) {
59 59
  int nn = 0;
60 60
  for (typename Graph::NodeIt it(g); it != INVALID; ++it) {
61 61
    ++nn;
62 62
  }
63 63

	
64 64
  check(nn == n, "Wrong node number.");
65 65
  //  check(countNodes(g) == n, "Wrong node number.");
66 66

	
67 67
  int ee = 0;
68 68
  for (typename Graph::ArcIt it(g); it != INVALID; ++it) {
69 69
    ++ee;
70 70
  }
71 71

	
72 72
  check(ee == 2*e, "Wrong arc number.");
73 73
  //  check(countArcs(g) == 2*e, "Wrong arc number.");
74 74

	
75 75
  int uee = 0;
76 76
  for (typename Graph::EdgeIt it(g); it != INVALID; ++it) {
77 77
    ++uee;
78 78
  }
79 79

	
80 80
  check(uee == e, "Wrong edge number.");
81 81
  //  check(countEdges(g) == e, "Wrong edge number.");
82 82
}
83 83

	
84 84
template <typename Graph>
85 85
void print_items(Graph &g) {
86 86

	
87 87
  typedef typename Graph::NodeIt NodeIt;
88 88
  typedef typename Graph::EdgeIt EdgeIt;
89 89
  typedef typename Graph::ArcIt ArcIt;
90 90

	
91 91
  std::cout << "Nodes" << std::endl;
92 92
  int i=0;
93 93
  for(NodeIt it(g); it!=INVALID; ++it, ++i) {
94 94
    std::cout << "  " << i << ": " << g.id(it) << std::endl;
95 95
  }
96 96

	
97 97
  std::cout << "Edge" << std::endl;
98 98
  i=0;
99 99
  for(EdgeIt it(g); it!=INVALID; ++it, ++i) {
100 100
    std::cout << "  " << i << ": " << g.id(it) 
101 101
	 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5
 * Copyright (C) 2003-2007
5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_TEST_MAP_TEST_H
20 20
#define LEMON_TEST_MAP_TEST_H
21 21

	
22 22

	
23 23
#include <vector>
24 24
#include <lemon/maps.h>
25 25

	
26 26
#include "test_tools.h"
27 27

	
28 28

	
29 29
//! \ingroup misc
30 30
//! \file
31 31
//! \brief Some utilities to test map classes.
32 32

	
33 33
namespace lemon {
34 34

	
35 35

	
36 36

	
37 37
  template <typename Graph>
38 38
  void checkGraphNodeMap() {
39 39
    Graph graph;
40 40
    const int num = 16;
41 41
    
42 42
    typedef typename Graph::Node Node;
43 43

	
44 44
    std::vector<Node> nodes;
45 45
    for (int i = 0; i < num; ++i) {
46 46
      nodes.push_back(graph.addNode());      
47 47
    }
48 48
    typedef typename Graph::template NodeMap<int> IntNodeMap;
49 49
    IntNodeMap map(graph, 42);
50 50
    for (int i = 0; i < int(nodes.size()); ++i) {
51 51
      check(map[nodes[i]] == 42, "Wrong map constructor.");      
52 52
    }
53 53
    for (int i = 0; i < num; ++i) {
54 54
      nodes.push_back(graph.addNode());
55 55
      map[nodes.back()] = 23;
56 56
    }
57 57
    map = constMap<Node>(12);
58 58
    for (int i = 0; i < int(nodes.size()); ++i) {
59 59
      check(map[nodes[i]] == 12, "Wrong map constructor.");      
60 60
    }    
61 61
    graph.clear();
62 62
    nodes.clear();
63 63
  }
64 64

	
65 65
  template <typename Graph>
66 66
  void checkGraphArcMap() {
67 67
    Graph graph;
68 68
    const int num = 16;
69 69
    
70 70
    typedef typename Graph::Node Node;
71 71
    typedef typename Graph::Arc Arc;
72 72
    
73 73
    std::vector<Node> nodes;
74 74
    for (int i = 0; i < num; ++i) {
75 75
      nodes.push_back(graph.addNode());
76 76
    }
77 77
    
78 78
    std::vector<Arc> edges;
79 79
    for (int i = 0; i < num; ++i) {
80 80
      for (int j = 0; j < i; ++j) {
81 81
	edges.push_back(graph.addArc(nodes[i], nodes[j]));
82 82
      }
83 83
    }
84 84
    
85 85
    typedef typename Graph::template ArcMap<int> IntArcMap;
86 86
    IntArcMap map(graph, 42);
87 87
    
88 88
    for (int i = 0; i < int(edges.size()); ++i) {
89 89
      check(map[edges[i]] == 42, "Wrong map constructor.");      
90 90
    }
91 91
    
92 92
    for (int i = 0; i < num; ++i) {
93 93
      for (int j = i + 1; j < num; ++j) {
94 94
	edges.push_back(graph.addArc(nodes[i], nodes[j]));
95 95
	map[edges.back()] = 23;
96 96
      }
97 97
    }
98 98
    map = constMap<Arc>(12);
99 99
    for (int i = 0; i < int(edges.size()); ++i) {
100 100
      check(map[edges[i]] == 12, "Wrong map constructor.");      
101 101
    }    
0 comments (0 inline)