COIN-OR::LEMON - Graph Library

Changeset 1751:a2a454f1232d in lemon-0.x


Ignore:
Timestamp:
11/02/05 16:24:38 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2280
Message:

Swap col and row map

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/matrix_maps.h

    r1720 r1751  
    3636  /// Map for the coloumn view of the matrix.
    3737  template <typename _MatrixMap>
    38   class MatrixColMap : public MapTraits<_MatrixMap> {
     38  class MatrixRowMap : public MapTraits<_MatrixMap> {
    3939  public:
    4040    typedef _MatrixMap MatrixMap;
     
    4343
    4444
    45     MatrixColMap(MatrixMap& _matrix, typename MatrixMap::FirstKey _col)
    46       : matrix(_matrix), col(_col) {}
     45    MatrixRowMap(MatrixMap& _matrix, typename MatrixMap::FirstKey _row)
     46      : matrix(_matrix), row(_row) {}
    4747
    4848    /// \brief Subscription operator
     
    5050    /// Subscription operator.
    5151    typename MapTraits<MatrixMap>::ReturnValue
    52     operator[](Key row) {
    53       return matrix(col, row);
     52    operator[](Key col) {
     53      return matrix(row, col);
    5454    }
    5555
     
    5757    ///
    5858    /// Setter function.
    59     void set(Key row, const Value& val) {
    60       matrix.set(col, row, val);
     59    void set(Key col, const Value& val) {
     60      matrix.set(row, col, val);
    6161    }
    6262     
     
    6565    /// Subscription operator.
    6666    typename MapTraits<MatrixMap>::ConstReturnValue
    67     operator[](Key row) const {
    68       return matrix(col, row);
     67    operator[](Key col) const {
     68      return matrix(row, col);
    6969    }
    7070
    7171  private:
    7272    MatrixMap& matrix;
    73     typename MatrixMap::FirstKey col;
    74   };
    75 
    76   /// \brief Map for the coloumn view of the matrix
    77   ///
    78   /// Map for the coloumn view of the matrix.
     73    typename MatrixMap::FirstKey row;
     74  };
     75
     76  /// \brief Map for the row view of the matrix
     77  ///
     78  /// Map for the row view of the matrix.
    7979  template <typename _MatrixMap>
    80   class ConstMatrixColMap : public MapTraits<_MatrixMap> {
     80  class ConstMatrixRowMap : public MapTraits<_MatrixMap> {
    8181  public:
    8282    typedef _MatrixMap MatrixMap;
     
    8585
    8686
    87     ConstMatrixColMap(const MatrixMap& _matrix,
    88                       typename MatrixMap::FirstKey _col)
    89       : matrix(_matrix), col(_col) {}
     87    ConstMatrixRowMap(const MatrixMap& _matrix,
     88                      typename MatrixMap::FirstKey _row)
     89      : matrix(_matrix), row(_row) {}
    9090
    9191    /// \brief Subscription operator
     
    9393    /// Subscription operator.
    9494    typename MapTraits<MatrixMap>::ConstReturnValue
    95     operator[](Key row) const {
    96       return matrix(col, row);
     95    operator[](Key col) const {
     96      return matrix(row, col);
    9797    }
    9898
    9999  private:
    100100    const MatrixMap& matrix;
    101     typename MatrixMap::FirstKey col;
    102   };
    103 
    104   /// \brief Gives back a coloumn view of the matrix map
    105   ///
    106   /// Gives back a coloumn view of the matrix map.
     101    typename MatrixMap::FirstKey row;
     102  };
     103
     104  /// \brief Gives back a row view of the matrix map
     105  ///
     106  /// Gives back a row view of the matrix map.
    107107  template <typename MatrixMap>
    108   MatrixColMap<MatrixMap> matrixColMap(MatrixMap& matrixMap,
    109                                        typename MatrixMap::FirstKey col) {
    110     return MatrixColMap<MatrixMap>(matrixMap, col);
     108  MatrixRowMap<MatrixMap> matrixRowMap(MatrixMap& matrixMap,
     109                                       typename MatrixMap::FirstKey row) {
     110    return MatrixRowMap<MatrixMap>(matrixMap, row);
    111111  }
    112112
    113113  template <typename MatrixMap>
    114   ConstMatrixColMap<MatrixMap>
    115   matrixColMap(const MatrixMap& matrixMap, typename MatrixMap::FirstKey col) {
    116     return ConstMatrixColMap<MatrixMap>(matrixMap, col);
     114  ConstMatrixRowMap<MatrixMap>
     115  matrixRowMap(const MatrixMap& matrixMap, typename MatrixMap::FirstKey row) {
     116    return ConstMatrixRowMap<MatrixMap>(matrixMap, row);
    117117  }
    118118
     
    121121  /// Map for the row view of the matrix.
    122122  template <typename _MatrixMap>
    123   class MatrixRowMap : public MapTraits<_MatrixMap> {
     123  class MatrixColMap : public MapTraits<_MatrixMap> {
    124124  public:
    125125    typedef _MatrixMap MatrixMap;
     
    127127    typedef typename MatrixMap::Value Value;
    128128
    129     MatrixRowMap(MatrixMap& _matrix, typename MatrixMap::SecondKey _row)
    130       : matrix(_matrix), row(_row) {}
     129    MatrixColMap(MatrixMap& _matrix, typename MatrixMap::SecondKey _col)
     130      : matrix(_matrix), col(_col) {}
    131131
    132132    /// \brief Subscription operator
     
    134134    /// Subscription operator.
    135135    typename MapTraits<MatrixMap>::ReturnValue
    136     operator[](Key col) {
    137       return matrix(col, row);
     136    operator[](Key row) {
     137      return matrix(row, col);
    138138    }
    139139
     
    141141    ///
    142142    /// Setter function.
    143     void set(Key col, const Value& val) {
    144       matrix.set(col, row, val);
     143    void set(Key row, const Value& val) {
     144      matrix.set(row, col, val);
    145145    }
    146146     
     
    149149    /// Subscription operator.
    150150    typename MapTraits<MatrixMap>::ConstReturnValue
    151     operator[](Key col) const {
    152       return matrix(col, row);
     151    operator[](Key row) const {
     152      return matrix(row, col);
    153153    }
    154154
    155155  private:
    156156    MatrixMap& matrix;
    157     typename MatrixMap::SecondKey row;
    158   };
    159 
    160   /// \brief Map for the row view of the matrix
    161   ///
    162   /// Map for the row view of the matrix.
     157    typename MatrixMap::SecondKey col;
     158  };
     159
     160  /// \brief Map for the col view of the matrix
     161  ///
     162  /// Map for the col view of the matrix.
    163163  template <typename _MatrixMap>
    164   class ConstMatrixRowMap : public MapTraits<_MatrixMap> {
     164  class ConstMatrixColMap : public MapTraits<_MatrixMap> {
    165165  public:
    166166    typedef _MatrixMap MatrixMap;
     
    168168    typedef typename MatrixMap::Value Value;
    169169
    170     ConstMatrixRowMap(const MatrixMap& _matrix,
    171                       typename MatrixMap::SecondKey _row)
    172       : matrix(_matrix), row(_row) {}
     170    ConstMatrixColMap(const MatrixMap& _matrix,
     171                      typename MatrixMap::SecondKey _col)
     172      : matrix(_matrix), col(_col) {}
    173173
    174174    /// \brief Subscription operator
     
    176176    /// Subscription operator.
    177177    typename MapTraits<MatrixMap>::ConstReturnValue
    178     operator[](Key col) const {
    179       return matrix(col, row);
     178    operator[](Key row) const {
     179      return matrix(row, col);
    180180    }
    181181
    182182  private:
    183183    const MatrixMap& matrix;
    184     typename MatrixMap::SecondKey row;
    185   };
    186 
    187   /// \brief Gives back a row view of the matrix map
    188   ///
    189   /// Gives back a row view of the matrix map.
     184    typename MatrixMap::SecondKey col;
     185  };
     186
     187  /// \brief Gives back a col view of the matrix map
     188  ///
     189  /// Gives back a col view of the matrix map.
    190190  template <typename MatrixMap>
    191   MatrixRowMap<MatrixMap> matrixRowMap(MatrixMap& matrixMap,
    192                                        typename MatrixMap::SecondKey row) {
    193     return MatrixRowMap<MatrixMap>(matrixMap, row);
     191  MatrixColMap<MatrixMap> matrixColMap(MatrixMap& matrixMap,
     192                                       typename MatrixMap::SecondKey col) {
     193    return MatrixColMap<MatrixMap>(matrixMap, col);
    194194  }
    195195
    196196  template <typename MatrixMap>
    197   ConstMatrixRowMap<MatrixMap>
    198   matrixRowMap(const MatrixMap& matrixMap, typename MatrixMap::SecondKey row) {
    199     return ConstMatrixRowMap<MatrixMap>(matrixMap, row);
     197  ConstMatrixColMap<MatrixMap>
     198  matrixColMap(const MatrixMap& matrixMap, typename MatrixMap::SecondKey col) {
     199    return ConstMatrixColMap<MatrixMap>(matrixMap, col);
    200200  }
    201201
  • test/matrix_maps_test.cc

    r1728 r1751  
    5454        matrix.set(it, jt, val);
    5555        check(matrix(it, jt) == val, "Wrong assign");
    56         check(matrix(it, jt) == matrixColMap(matrix, it)[jt], "Wrong colMap");
    57         check(matrix(it, jt) == matrixRowMap(matrix, jt)[it], "Wrong rowMap");
     56        check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
     57        check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
    5858      }
    5959    }
     
    6161    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
    6262      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
    63         check(cm(it, jt) == matrixColMap(cm, it)[jt], "Wrong colMap");
    64         check(cm(it, jt) == matrixRowMap(cm, jt)[it], "Wrong rowMap");
     63        check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
     64        check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
    6565      }
    6666    }
     
    9696        check(matrix(it, jt) == val, "Wrong assign");
    9797        check(matrix(jt, it) == val, "Wrong assign");
    98         check(matrix(it, jt) == matrixColMap(matrix, it)[jt], "Wrong colMap");
    99         check(matrix(it, jt) == matrixRowMap(matrix, jt)[it], "Wrong rowMap");
     98        check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
     99        check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
    100100      }
    101101    }
     
    103103    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
    104104      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
    105         check(cm(it, jt) == matrixColMap(cm, it)[jt], "Wrong colMap");
    106         check(cm(it, jt) == matrixRowMap(cm, jt)[it], "Wrong rowMap");
     105        check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
     106        check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
    107107      }
    108108    }
Note: See TracChangeset for help on using the changeset viewer.