lemon/bits/traits.h
author Balazs Dezso <deba@inf.elte.hu>
Thu, 24 Jun 2010 09:27:53 +0200
changeset 732 bb70ad62c95f
parent 440 88ed40ad0d4f
permissions -rw-r--r--
Fix critical bug in preflow (#372)

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