lemon/concept/matrix_maps.h
author deba
Tue, 17 Oct 2006 10:50:57 +0000
changeset 2247 269a0dcee70b
parent 1956 a055123339d5
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@1720
     1
/* -*- C++ -*-
deba@1720
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@1720
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@1720
     8
 *
deba@1720
     9
 * Permission to use, modify and distribute this software is granted
deba@1720
    10
 * provided that this copyright notice appears in all copies. For
deba@1720
    11
 * precise terms see the accompanying LICENSE file.
deba@1720
    12
 *
deba@1720
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@1720
    14
 * express or implied, and with no claim as to its suitability for any
deba@1720
    15
 * purpose.
deba@1720
    16
 *
deba@1720
    17
 */
deba@1720
    18
deba@1720
    19
#ifndef LEMON_CONCEPT_MATRIX_MAPS_H
deba@1720
    20
#define LEMON_CONCEPT_MATRIX_MAPS_H
deba@1720
    21
deba@1993
    22
#include <lemon/bits/utility.h>
deba@1720
    23
#include <lemon/concept_check.h>
deba@1720
    24
deba@1720
    25
///\ingroup concept
deba@1720
    26
///\file
deba@1720
    27
///\brief MatrixMap concepts checking classes for testing and documenting.
deba@1720
    28
deba@1720
    29
namespace lemon {
deba@1720
    30
deba@1720
    31
  namespace concept {
deba@1720
    32
  
deba@1720
    33
    /// \addtogroup concept
deba@1720
    34
    /// @{
deba@1720
    35
deba@1720
    36
    /// Readable matrix map concept
deba@1720
    37
    template <typename K1, typename K2, typename V>
deba@1720
    38
    class ReadMatrixMap
deba@1720
    39
    {
deba@1720
    40
    public:
deba@1720
    41
      /// Map's first key type.
deba@1720
    42
      typedef K1 FirstKey;    
deba@1720
    43
      /// Map's second key type.
deba@1720
    44
      typedef K2 SecondKey;    
deba@1720
    45
      /// \brief Map's value type. 
deba@1720
    46
      /// (The type of objects associated with the pairs of keys).
deba@1720
    47
      typedef V Value;
deba@1720
    48
deba@1720
    49
      // \bug Value don't need to be default constructible.
deba@1720
    50
      /// Returns the value associated with a key.
deba@1720
    51
      Value operator()(const FirstKey&, const SecondKey&) const {
deba@1720
    52
	return Value();
deba@1720
    53
      }
deba@1720
    54
deba@1720
    55
      template <typename _ReadMatrixMap>
deba@1720
    56
      struct Constraints {
deba@1720
    57
deba@1720
    58
	void constraints() {
deba@1720
    59
	  Value val = m(first_key, second_key);
deba@1720
    60
	  val = m(first_key, second_key);
deba@1720
    61
	  typename _ReadMatrixMap::Value own_val = 
deba@1720
    62
	    m(own_first_key, own_second_key); 
deba@1720
    63
	  own_val = m(own_first_key, own_second_key);
deba@1720
    64
	  ignore_unused_variable_warning(val);
deba@1720
    65
	  ignore_unused_variable_warning(own_val);
deba@1720
    66
	}
deba@1720
    67
deba@1720
    68
	FirstKey& first_key;
deba@1720
    69
	SecondKey& second_key;	
deba@1720
    70
	typename _ReadMatrixMap::FirstKey& own_first_key;
deba@1720
    71
	typename _ReadMatrixMap::SecondKey& own_second_key;
deba@1720
    72
	_ReadMatrixMap& m;
deba@1720
    73
      };
deba@1720
    74
      
deba@1720
    75
    };
deba@1720
    76
deba@1720
    77
deba@1720
    78
    /// Writable map concept
deba@1720
    79
    template <typename K1, typename K2, typename V>
deba@1720
    80
    class WriteMatrixMap {
deba@1720
    81
    public:
deba@1720
    82
      /// Map's first key type.
deba@1720
    83
      typedef K1 FirstKey;    
deba@1720
    84
      /// Map's second key type.
deba@1720
    85
      typedef K2 SecondKey;    
deba@1720
    86
      /// \brief Map's value type. 
deba@1720
    87
      /// (The type of objects associated with the pairs of keys).
deba@1720
    88
      typedef V Value;
deba@1720
    89
deba@1720
    90
      /// Sets the value associated with the pair of keys.
deba@1720
    91
      void set(const FirstKey&, const SecondKey& ,const Value&) {}
deba@1720
    92
deba@1720
    93
      template <typename _WriteMatrixMap>
deba@1720
    94
      struct Constraints {
deba@1720
    95
	void constraints() {
deba@1720
    96
	  // No constraints for constructor.
deba@1720
    97
	  m.set(first_key, second_key, val);
deba@1720
    98
	  m.set(own_first_key, own_second_key, own_val);
deba@1720
    99
	}
deba@1720
   100
deba@1720
   101
	Value& val;
deba@1720
   102
	typename _WriteMatrixMap::Value own_val;
deba@1720
   103
	FirstKey& first_key;
deba@1720
   104
	SecondKey& second_key;
deba@1720
   105
	typename _WriteMatrixMap::FirstKey& own_first_key;
deba@1720
   106
	typename _WriteMatrixMap::SecondKey& own_second_key;
deba@1720
   107
	_WriteMatrixMap& m;
deba@1720
   108
deba@1720
   109
      };
deba@1720
   110
    };
deba@1720
   111
deba@1720
   112
    ///Read/Writable map concept
deba@1720
   113
    template<typename K1, typename K2, typename V>
deba@1720
   114
    class ReadWriteMatrixMap 
deba@1720
   115
      : public ReadMatrixMap<K1, K2, V>, public WriteMatrixMap<K1, K2, V> {
deba@1720
   116
    public:
deba@1720
   117
      /// Map's first key type.
deba@1720
   118
      typedef K1 FirstKey;    
deba@1720
   119
      /// Map's second key type.
deba@1720
   120
      typedef K2 SecondKey;    
deba@1720
   121
      /// \brief Map's value type. 
deba@1720
   122
      /// (The type of objects associated with the pairs of keys).
deba@1720
   123
      typedef V Value;
deba@1720
   124
deba@1720
   125
      /// Returns the value associated with a pair of keys.
deba@1720
   126
      Value operator()(const FirstKey&, const SecondKey&) const { 
deba@1720
   127
	return Value(); 
deba@1720
   128
      }
deba@1720
   129
      /// Sets the value associated with the pair of keys.
deba@1720
   130
      void set(const FirstKey&, const SecondKey& ,const Value&) {}
deba@1720
   131
deba@1720
   132
      template<typename _ReadWriteMatrixMap>
deba@1720
   133
      struct Constraints {
deba@1720
   134
	void constraints() {
deba@1720
   135
	  checkConcept<ReadMatrixMap<K1, K2, V>, _ReadWriteMatrixMap >();
deba@1720
   136
	  checkConcept<WriteMatrixMap<K1, K2, V>, _ReadWriteMatrixMap >();
deba@1720
   137
	}
deba@1720
   138
      };
deba@1720
   139
    };
deba@1720
   140
  
deba@1720
   141
  
deba@1720
   142
    ///Dereferable matrix map concept
deba@1720
   143
    template<typename K1, typename K2, typename V, typename R, typename CR>
deba@1720
   144
    class ReferenceMatrixMap : public ReadWriteMatrixMap<K1, K2, V>
deba@1720
   145
    {
deba@1720
   146
    public:
deba@1720
   147
      /// Tag for reference maps.
deba@1720
   148
      typedef True ReferenceMapTag;
deba@1720
   149
      /// Map's first key type.
deba@1720
   150
      typedef K1 FirstKey;    
deba@1720
   151
      /// Map's second key type.
deba@1720
   152
      typedef K1 SecondKey;    
deba@1720
   153
      /// Map's value type. (The type of objects associated with the keys).
deba@1720
   154
      typedef V Value;
deba@1720
   155
      /// Map's reference type.
deba@1720
   156
      typedef R Reference;
deba@1720
   157
      /// Map's const reference type.
deba@1720
   158
      typedef CR ConstReference;
deba@1720
   159
deba@1720
   160
    protected:
deba@1720
   161
      Value tmp;
deba@1720
   162
    public:
deba@1720
   163
deba@1720
   164
      ///Returns a reference to the value associated to a pair of keys.
deba@1720
   165
      Reference operator()(const FirstKey&, const SecondKey&) { 
deba@1720
   166
	return tmp; 
deba@1720
   167
      }
deba@1720
   168
      ///Returns a const reference to the value associated to a pair of keys.
deba@1720
   169
      ConstReference operator()(const FirstKey&, const SecondKey&) const { 
deba@1720
   170
	return tmp; 
deba@1720
   171
      }
deba@1720
   172
      /// Sets the value associated with the pair of keys.
deba@1720
   173
      void set(const FirstKey&, const SecondKey& ,const Value&) {}
deba@1720
   174
deba@1720
   175
      // \todo rethink this concept
deba@1720
   176
      template<typename _ReferenceMatrixMap>
deba@1720
   177
      struct ReferenceMapConcept {
deba@1720
   178
deba@1720
   179
	void constraints() {
deba@1720
   180
	  checkConcept<ReadWriteMatrixMap, _ReferenceMatrixMap >();
deba@1720
   181
	  m(first_key, second_key) = val;
deba@1720
   182
	  val  = m(first_key, second_key);
deba@1720
   183
	  m(first_key, second_key) = ref;
deba@1720
   184
	  ref = m(first_key, second_key);
deba@1720
   185
	  m(own_first_key, own_second_key) = own_val;
deba@1720
   186
	  own_val  = m(own_first_key, own_second_key);
deba@1720
   187
	  m(own_first_key, own_second_key) = own_ref;
deba@1720
   188
	  own_ref = m(own_first_key, own_second_key); 
deba@1720
   189
	}
deba@1720
   190
deba@1720
   191
	typename _ReferenceMatrixMap::Key& own_first_key;
deba@1720
   192
	typename _ReferenceMatrixMap::Key& own_second_key;
deba@1720
   193
	typename _ReferenceMatrixMap::Value& own_val;
deba@1720
   194
	typename _ReferenceMatrixMap::Reference& own_ref;
deba@1720
   195
	FirstKey& first_key;
deba@1720
   196
	SecondKey& second_key;
deba@1720
   197
	Value& val;
deba@1720
   198
	Reference& ref;
deba@1720
   199
	_ReferenceMatrixMap& m;
deba@1720
   200
      };
deba@1720
   201
    };
deba@1720
   202
deba@1720
   203
    // @}
deba@1720
   204
deba@1720
   205
  } //namespace concept
deba@1720
   206
} //namespace lemon
deba@1720
   207
#endif // LEMON_CONCEPT_MATRIX_MAPS_H