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