lemon/bits/traits.h
author deba
Tue, 17 Oct 2006 10:50:57 +0000
changeset 2247 269a0dcee70b
parent 1996 5dc13b93f8b4
child 2290 f30867b359a8
permissions -rw-r--r--
Update the Path concept
Concept check for paths

DirPath renamed to Path
The interface updated to the new lemon interface
Make difference between the empty path and the path from one node
Builder interface have not been changed
// I wanted but there was not accordance about it

UPath is removed
It was a buggy implementation, it could not iterate on the
nodes in the right order
Right way to use undirected paths => path of edges in undirected graphs

The tests have been modified to the current implementation
deba@1993
     1
/* -*- C++ -*-
deba@1993
     2
 *
deba@1993
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@1993
     4
 *
deba@1993
     5
 * Copyright (C) 2003-2006
deba@1993
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@1993
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@1993
     8
 *
deba@1993
     9
 * Permission to use, modify and distribute this software is granted
deba@1993
    10
 * provided that this copyright notice appears in all copies. For
deba@1993
    11
 * precise terms see the accompanying LICENSE file.
deba@1993
    12
 *
deba@1993
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@1993
    14
 * express or implied, and with no claim as to its suitability for any
deba@1993
    15
 * purpose.
deba@1993
    16
 *
deba@1993
    17
 */
deba@1993
    18
deba@1993
    19
#ifndef LEMON_BITS_TRAITS_H
deba@1993
    20
#define LEMON_BITS_TRAITS_H
deba@1993
    21
deba@1993
    22
#include <lemon/bits/utility.h>
deba@1993
    23
deba@1993
    24
///\file
deba@1993
    25
///\brief Traits for graphs and maps
deba@1993
    26
///
deba@1993
    27
deba@1993
    28
namespace lemon {
deba@1993
    29
  template <typename _Graph, typename _Item>
deba@1993
    30
  class ItemSetTraits {};
deba@1993
    31
  
deba@1993
    32
deba@1993
    33
  template <typename Graph, typename Enable = void>
deba@1993
    34
  struct NodeNotifierIndicator {
deba@1993
    35
    typedef InvalidType Type;
deba@1993
    36
  };
deba@1993
    37
  template <typename Graph>
deba@1993
    38
  struct NodeNotifierIndicator<
deba@1993
    39
    Graph, 
deba@1993
    40
    typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
deba@1993
    41
  > { 
deba@1993
    42
    typedef typename Graph::NodeNotifier Type;
deba@1993
    43
  };
deba@1993
    44
deba@1993
    45
  template <typename _Graph>
deba@1993
    46
  class ItemSetTraits<_Graph, typename _Graph::Node> {
deba@1993
    47
  public:
deba@1993
    48
    
deba@1993
    49
    typedef _Graph Graph;
deba@1993
    50
deba@1993
    51
    typedef typename Graph::Node Item;
deba@1993
    52
    typedef typename Graph::NodeIt ItemIt;
deba@1993
    53
deba@1993
    54
    typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
    55
deba@1993
    56
    template <typename _Value>
deba@1993
    57
    class Map : public Graph::template NodeMap<_Value> {
deba@1993
    58
    public:
deba@1993
    59
      typedef typename Graph::template NodeMap<_Value> Parent; 
deba@1993
    60
      typedef typename Parent::Value Value;
deba@1993
    61
deba@1993
    62
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
    63
      Map(const Graph& _graph, const Value& _value) 
deba@1993
    64
	: Parent(_graph, _value) {}
deba@1993
    65
deba@1993
    66
     };
deba@1993
    67
deba@1993
    68
  };
deba@1993
    69
deba@1993
    70
  template <typename Graph, typename Enable = void>
deba@1993
    71
  struct EdgeNotifierIndicator {
deba@1993
    72
    typedef InvalidType Type;
deba@1993
    73
  };
deba@1993
    74
  template <typename Graph>
deba@1993
    75
  struct EdgeNotifierIndicator<
deba@1993
    76
    Graph, 
deba@1993
    77
    typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
deba@1993
    78
  > { 
deba@1993
    79
    typedef typename Graph::EdgeNotifier Type;
deba@1993
    80
  };
deba@1993
    81
deba@1993
    82
  template <typename _Graph>
deba@1993
    83
  class ItemSetTraits<_Graph, typename _Graph::Edge> {
deba@1993
    84
  public:
deba@1993
    85
    
deba@1993
    86
    typedef _Graph Graph;
deba@1993
    87
deba@1993
    88
    typedef typename Graph::Edge Item;
deba@1993
    89
    typedef typename Graph::EdgeIt ItemIt;
deba@1993
    90
deba@1993
    91
    typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
    92
deba@1993
    93
    template <typename _Value>
deba@1993
    94
    class Map : public Graph::template EdgeMap<_Value> {
deba@1993
    95
    public:
deba@1993
    96
      typedef typename Graph::template EdgeMap<_Value> Parent; 
deba@1993
    97
      typedef typename Parent::Value Value;
deba@1993
    98
deba@1993
    99
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   100
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   101
	: Parent(_graph, _value) {}
deba@1993
   102
    };
deba@1993
   103
deba@1993
   104
  };
deba@1993
   105
deba@1993
   106
  template <typename Graph, typename Enable = void>
deba@1993
   107
  struct UEdgeNotifierIndicator {
deba@1993
   108
    typedef InvalidType Type;
deba@1993
   109
  };
deba@1993
   110
  template <typename Graph>
deba@1993
   111
  struct UEdgeNotifierIndicator<
deba@1993
   112
    Graph, 
deba@1993
   113
    typename enable_if<typename Graph::UEdgeNotifier::Notifier, void>::type
deba@1993
   114
  > { 
deba@1993
   115
    typedef typename Graph::UEdgeNotifier Type;
deba@1993
   116
  };
deba@1993
   117
deba@1993
   118
  template <typename _Graph>
deba@1993
   119
  class ItemSetTraits<_Graph, typename _Graph::UEdge> {
deba@1993
   120
  public:
deba@1993
   121
    
deba@1993
   122
    typedef _Graph Graph;
deba@1993
   123
deba@1993
   124
    typedef typename Graph::UEdge Item;
deba@1993
   125
    typedef typename Graph::UEdgeIt ItemIt;
deba@1993
   126
deba@1993
   127
    typedef typename UEdgeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
   128
deba@1993
   129
    template <typename _Value>
deba@1993
   130
    class Map : public Graph::template UEdgeMap<_Value> {
deba@1993
   131
    public:
deba@1993
   132
      typedef typename Graph::template UEdgeMap<_Value> Parent; 
deba@1993
   133
      typedef typename Parent::Value Value;
deba@1993
   134
deba@1993
   135
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   136
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   137
	: Parent(_graph, _value) {}
deba@1993
   138
    };
deba@1993
   139
deba@1993
   140
  };
deba@1993
   141
deba@1993
   142
  template <typename Graph, typename Enable = void>
deba@1993
   143
  struct ANodeNotifierIndicator {
deba@1993
   144
    typedef InvalidType Type;
deba@1993
   145
  };
deba@1993
   146
  template <typename Graph>
deba@1993
   147
  struct ANodeNotifierIndicator<
deba@1993
   148
    Graph, 
deba@1993
   149
    typename enable_if<typename Graph::ANodeNotifier::Notifier, void>::type
deba@1993
   150
  > { 
deba@1993
   151
    typedef typename Graph::ANodeNotifier Type;
deba@1993
   152
  };
deba@1993
   153
deba@1993
   154
  template <typename _Graph>
deba@1993
   155
  class ItemSetTraits<_Graph, typename _Graph::ANode> {
deba@1993
   156
  public:
deba@1993
   157
    
deba@1993
   158
    typedef _Graph Graph;
deba@1993
   159
deba@1993
   160
    typedef typename Graph::ANode Item;
deba@1993
   161
    typedef typename Graph::ANodeIt ItemIt;
deba@1993
   162
deba@1993
   163
    typedef typename ANodeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
   164
deba@1993
   165
    template <typename _Value>
deba@1993
   166
    class Map : public Graph::template ANodeMap<_Value> {
deba@1993
   167
    public:
deba@1993
   168
      typedef typename Graph::template ANodeMap<_Value> Parent; 
deba@1993
   169
      typedef typename Parent::Value Value;
deba@1993
   170
deba@1993
   171
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   172
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   173
	: Parent(_graph, _value) {}
deba@1993
   174
    };
deba@1993
   175
deba@1993
   176
  };
deba@1993
   177
deba@1993
   178
  template <typename Graph, typename Enable = void>
deba@1993
   179
  struct BNodeNotifierIndicator {
deba@1993
   180
    typedef InvalidType Type;
deba@1993
   181
  };
deba@1993
   182
  template <typename Graph>
deba@1993
   183
  struct BNodeNotifierIndicator<
deba@1993
   184
    Graph, 
deba@1993
   185
    typename enable_if<typename Graph::BNodeNotifier::Notifier, void>::type
deba@1993
   186
  > { 
deba@1993
   187
    typedef typename Graph::BNodeNotifier Type;
deba@1993
   188
  };
deba@1993
   189
deba@1993
   190
  template <typename _Graph>
deba@1993
   191
  class ItemSetTraits<_Graph, typename _Graph::BNode> {
deba@1993
   192
  public:
deba@1993
   193
    
deba@1993
   194
    typedef _Graph Graph;
deba@1993
   195
deba@1993
   196
    typedef typename Graph::BNode Item;
deba@1993
   197
    typedef typename Graph::BNodeIt ItemIt;
deba@1993
   198
deba@1993
   199
    typedef typename BNodeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
   200
deba@1993
   201
    template <typename _Value>
deba@1993
   202
    class Map : public Graph::template BNodeMap<_Value> {
deba@1993
   203
    public:
deba@1993
   204
      typedef typename Graph::template BNodeMap<_Value> Parent; 
deba@1993
   205
      typedef typename Parent::Value Value;
deba@1993
   206
deba@1993
   207
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   208
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   209
	: Parent(_graph, _value) {}
deba@1993
   210
    };
deba@1993
   211
deba@1993
   212
  };
deba@1993
   213
deba@1993
   214
deba@1993
   215
  template <typename Map, typename Enable = void>
deba@1993
   216
  struct MapTraits {
deba@1993
   217
    typedef False ReferenceMapTag;
deba@1993
   218
deba@1993
   219
    typedef typename Map::Key Key;
deba@1993
   220
    typedef typename Map::Value Value;
deba@1993
   221
deba@1993
   222
    typedef const Value ConstReturnValue;
deba@1993
   223
    typedef const Value ReturnValue;
deba@1993
   224
  };
deba@1993
   225
deba@1993
   226
  template <typename Map>
deba@1993
   227
  struct MapTraits<
deba@1993
   228
    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
deba@1993
   229
  {
deba@1993
   230
    typedef True ReferenceMapTag;
deba@1993
   231
    
deba@1993
   232
    typedef typename Map::Key Key;
deba@1993
   233
    typedef typename Map::Value Value;
deba@1993
   234
deba@1993
   235
    typedef typename Map::ConstReference ConstReturnValue;
deba@1993
   236
    typedef typename Map::Reference ReturnValue;
deba@1993
   237
deba@1993
   238
    typedef typename Map::ConstReference ConstReference; 
deba@1993
   239
    typedef typename Map::Reference Reference;
deba@1993
   240
 };
deba@1993
   241
deba@2039
   242
  template <typename MatrixMap, typename Enable = void>
deba@2039
   243
  struct MatrixMapTraits {
deba@2039
   244
    typedef False ReferenceMapTag;
deba@2039
   245
deba@2039
   246
    typedef typename MatrixMap::FirstKey FirstKey;
deba@2039
   247
    typedef typename MatrixMap::SecondKey SecondKey;
deba@2039
   248
    typedef typename MatrixMap::Value Value;
deba@2039
   249
deba@2039
   250
    typedef const Value ConstReturnValue;
deba@2039
   251
    typedef const Value ReturnValue;
deba@2039
   252
  };
deba@2039
   253
deba@2039
   254
  template <typename MatrixMap>
deba@2039
   255
  struct MatrixMapTraits<
deba@2039
   256
    MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, 
deba@2039
   257
                                  void>::type > 
deba@2039
   258
  {
deba@2039
   259
    typedef True ReferenceMapTag;
deba@2039
   260
    
deba@2039
   261
    typedef typename MatrixMap::FirstKey FirstKey;
deba@2039
   262
    typedef typename MatrixMap::SecondKey SecondKey;
deba@2039
   263
    typedef typename MatrixMap::Value Value;
deba@2039
   264
deba@2039
   265
    typedef typename MatrixMap::ConstReference ConstReturnValue;
deba@2039
   266
    typedef typename MatrixMap::Reference ReturnValue;
deba@2039
   267
deba@2039
   268
    typedef typename MatrixMap::ConstReference ConstReference; 
deba@2039
   269
    typedef typename MatrixMap::Reference Reference;
deba@2039
   270
 };
deba@2039
   271
deba@1993
   272
  // Indicators for the tags
deba@1993
   273
deba@1993
   274
  template <typename Graph, typename Enable = void>
deba@1993
   275
  struct NodeNumTagIndicator {
deba@1993
   276
    static const bool value = false;
deba@1993
   277
  };
deba@1993
   278
deba@1993
   279
  template <typename Graph>
deba@1993
   280
  struct NodeNumTagIndicator<
deba@1993
   281
    Graph, 
deba@1993
   282
    typename enable_if<typename Graph::NodeNumTag, void>::type
deba@1993
   283
  > {
deba@1993
   284
    static const bool value = true;
deba@1993
   285
  };
deba@1993
   286
deba@1993
   287
  template <typename Graph, typename Enable = void>
deba@1993
   288
  struct EdgeNumTagIndicator {
deba@1993
   289
    static const bool value = false;
deba@1993
   290
  };
deba@1993
   291
deba@1993
   292
  template <typename Graph>
deba@1993
   293
  struct EdgeNumTagIndicator<
deba@1993
   294
    Graph, 
deba@1993
   295
    typename enable_if<typename Graph::EdgeNumTag, void>::type
deba@1993
   296
  > {
deba@1993
   297
    static const bool value = true;
deba@1993
   298
  };
deba@1993
   299
deba@1993
   300
  template <typename Graph, typename Enable = void>
deba@1993
   301
  struct FindEdgeTagIndicator {
deba@1993
   302
    static const bool value = false;
deba@1993
   303
  };
deba@1993
   304
deba@1993
   305
  template <typename Graph>
deba@1993
   306
  struct FindEdgeTagIndicator<
deba@1993
   307
    Graph, 
deba@1993
   308
    typename enable_if<typename Graph::FindEdgeTag, void>::type
deba@1993
   309
  > {
deba@1993
   310
    static const bool value = true;
deba@1993
   311
  };
deba@1993
   312
deba@1993
   313
  template <typename Graph, typename Enable = void>
deba@1993
   314
  struct UndirectedTagIndicator {
deba@1993
   315
    static const bool value = false;
deba@1993
   316
  };
deba@1993
   317
deba@1993
   318
  template <typename Graph>
deba@1993
   319
  struct UndirectedTagIndicator<
deba@1993
   320
    Graph, 
deba@1993
   321
    typename enable_if<typename Graph::UndirectedTag, void>::type
deba@1993
   322
  > {
deba@1993
   323
    static const bool value = true;
deba@1993
   324
  };
deba@1993
   325
deba@1993
   326
deba@1993
   327
deba@1993
   328
}
deba@1993
   329
deba@1996
   330
#endif