00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _SCSOLVER_NUMERIC_MATRIX_HXX_
00030 #define _SCSOLVER_NUMERIC_MATRIX_HXX_
00031
00032 #include <boost/numeric/ublas/matrix.hpp>
00033 #include <boost/numeric/ublas/matrix_proxy.hpp>
00034
00035 #include <vector>
00036 #include <memory>
00037
00038 namespace scsolver { namespace numeric {
00039
00044 class BadIndex : public ::std::exception
00045 {
00046 public:
00047 virtual const char* what() const throw();
00048 };
00049
00050 class MatrixSizeMismatch : public ::std::exception
00051 {
00052 public:
00053 virtual const char* what() const throw();
00054 };
00055
00056 class MatrixNotDiagonal : public ::std::exception
00057 {
00058 public:
00059 virtual const char* what() const throw();
00060 };
00061
00062 class OperationOnEmptyMatrix : public ::std::exception
00063 {
00064 public:
00065 virtual const char* what() const throw();
00066 };
00067
00068 class SingularMatrix : public ::std::exception
00069 {
00070 public:
00071 virtual const char* what() const throw();
00072 };
00073
00074 class NonSquareMatrix : public ::std::exception
00075 {
00076 public:
00077 virtual const char* what() const throw();
00078 };
00079
00080 class Matrix
00081 {
00082 public:
00083 typedef ::boost::numeric::ublas::matrix<double, ::boost::numeric::ublas::row_major, ::std::vector<double> >
00084 NumericMatrixType;
00085 typedef ::boost::numeric::ublas::matrix< ::std::string > StringMatrixType;
00086
00087 Matrix();
00088 Matrix(size_t row, size_t col, bool identity_matrix = false);
00089 Matrix( const Matrix& );
00090 Matrix( const Matrix* );
00091 Matrix( ::boost::numeric::ublas::matrix<double> );
00092 ~Matrix() throw();
00093
00094 void setResizable(bool resizable);
00095 void swap( Matrix& ) throw();
00096 void clear();
00097 void copy( const Matrix& );
00098 Matrix clone() const;
00099
00100 const double getValue(size_t row, size_t col) const;
00101 double& getValue(size_t row, size_t col);
00102 void setValue(size_t row, size_t col, double val);
00103
00104 StringMatrixType getDisplayElements(int prec, size_t colspace, bool formula) const;
00105
00112 void print(size_t prec = 2, size_t colspace = 1) const;
00113
00114 Matrix getColumn(size_t col);
00115 Matrix getRow(size_t row);
00116
00117 void deleteColumn( size_t );
00118 void deleteColumns( const std::vector<size_t>& );
00119 void deleteRow( size_t );
00120 void deleteRows( const std::vector<size_t>& );
00121
00129 double det() const;
00130 const Matrix inverse() const;
00131 const Matrix trans() const;
00132 double minors( size_t, size_t ) const;
00133 void resize(size_t row, size_t col);
00134
00138 size_t rows() const;
00139
00143 size_t cols() const;
00144
00145 bool empty() const;
00146 bool isRowEmpty( size_t ) const;
00147 bool isColumnEmpty( size_t ) const;
00148 bool isSameSize( const Matrix& ) const;
00149 bool isSquare() const;
00150
00151
00152
00153 Matrix& operator=( const Matrix& );
00154 const Matrix operator+( const Matrix& ) const;
00155 const Matrix operator-( const Matrix& ) const;
00156 const Matrix operator*( double ) const;
00157 const Matrix operator*( const Matrix& ) const;
00158 const Matrix operator/( double ) const;
00159 Matrix& operator+=( const Matrix& );
00160 Matrix& operator+=( double );
00161 Matrix& operator-=( const Matrix& );
00162 Matrix& operator*=( double );
00163 Matrix& operator/=( double );
00164
00165 const double operator()(size_t row, size_t col) const;
00166 double& operator()(size_t row, size_t col);
00167
00168 bool operator==( const Matrix& ) const;
00169 bool operator!=( const Matrix& ) const;
00170
00171 private:
00172 const Matrix adj() const;
00173 double cofactor( size_t, size_t ) const;
00174 void maybeExpand(size_t row, size_t col);
00175 void throwIfEmpty() const;
00176
00177 bool m_bResizable;
00178 NumericMatrixType m_aArray;
00179 };
00180
00181 const Matrix operator+(const Matrix& mx, double scalar);
00182 const Matrix operator+(double scalar, const Matrix& mx);
00183 const Matrix operator*(double scalar, const Matrix& mx);
00184
00185 }}
00186
00187 #endif //_MATRIX_HXX_