00001 /* 00002 * This file is part of ACADO Toolkit. 00003 * 00004 * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization. 00005 * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau, 00006 * Milan Vukov, Rien Quirynen, KU Leuven. 00007 * Developed within the Optimization in Engineering Center (OPTEC) 00008 * under supervision of Moritz Diehl. All rights reserved. 00009 * 00010 * ACADO Toolkit is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 3 of the License, or (at your option) any later version. 00014 * 00015 * ACADO Toolkit is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with ACADO Toolkit; if not, write to the Free Software 00022 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00023 * 00024 */ 00025 00026 00033 #ifndef ACADO_TOOLKIT_CONJUGATE_GRADIENT_MEHTOD_HPP 00034 #define ACADO_TOOLKIT_CONJUGATE_GRADIENT_MEHTOD_HPP 00035 00036 00037 #include <acado/utils/acado_utils.hpp> 00038 00039 00040 BEGIN_NAMESPACE_ACADO 00041 00042 00057 class ConjugateGradientMethod : public SparseSolver{ 00058 00059 00060 // 00061 // PUBLIC MEMBER FUNCTIONS: 00062 // 00063 public: 00064 00066 ConjugateGradientMethod( ); 00067 00069 ConjugateGradientMethod( const ConjugateGradientMethod &arg ); 00070 00072 virtual ~ConjugateGradientMethod( ); 00073 00075 virtual SparseSolver* clone() const = 0; 00076 00077 00082 virtual returnValue setDimension( const int &n ); 00083 00084 00090 virtual returnValue setNumberOfEntries( const int &nDense_ ); 00091 00092 00093 00097 virtual returnValue setIndices( const int *rowIdx_, 00098 const int *colIdx_ ) = 0; 00099 00100 00101 00106 virtual returnValue setMatrix( double *A_ ); 00107 00108 00109 00115 virtual returnValue solve( double *b ); 00116 00117 00118 00123 virtual returnValue getX( double *x_ ); 00124 00125 00126 00137 virtual returnValue setTolerance( double TOL_ ); 00138 00139 00144 virtual returnValue setPrintLevel( PrintLevel printLevel_ ); 00145 00146 00147 00148 // 00149 // PROTECTED MEMBER FUNCTIONS: 00150 // 00151 protected: 00152 00153 00155 double scalarProduct( double *aa, double *bb ); 00156 00158 virtual void multiply( double *xx , double *result ) = 0; 00159 00161 virtual returnValue applyPreconditioner( double *b ) = 0; 00162 00164 virtual returnValue applyInversePreconditioner( double *x_ ) = 0; 00165 00167 virtual returnValue computePreconditioner( double* A_ ) = 0; 00168 00169 00170 // 00171 // DATA MEMBERS: 00172 // 00173 protected: 00174 00175 00176 // DIMENSIONS: 00177 // -------------------- 00178 int dim; // dimension of the matrix A 00179 int nDense; // number of non-zero entries in A 00180 00181 // DATA: 00182 // -------------------- 00183 double *A; // The (sparse) matrix A 00184 double *x; // The result vector x 00185 00186 00187 // AUXILIARY VARIABLES: 00188 // -------------------- 00189 double *norm2; // Auxiliary variables 00190 double **p; // conjugate basis vectors 00191 double *r; // the actual residuum 00192 int pCounter; // a counter for the iterates 00193 double *condScale; // scaling factors to improve 00194 // the conditioning of the system 00195 00196 double TOL; // The required tolerance. (default 10^(-10)) 00197 PrintLevel printLevel; // The PrintLevel. 00198 }; 00199 00200 00201 CLOSE_NAMESPACE_ACADO 00202 00203 00204 00205 #include <acado/sparse_solver/conjugate_gradient_method.ipp> 00206 00207 00208 #endif // ACADO_TOOLKIT_CONJUGATE_GRADIENT_METHOD_HPP 00209 00210 /* 00211 * end of file 00212 */ 00213