00001 /******************************************************************************/ 00002 /* */ 00003 /* O B J E C T I V E F U N C T I O N C L A S S H E A D E R */ 00004 /* */ 00005 /* Roberto Lopez */ 00006 /* International Center for Numerical Methods in Engineering (CIMNE) */ 00007 /* Technical University of Catalonia (UPC) */ 00008 /* Barcelona, Spain */ 00009 /* E-mail: rlopez@cimne.upc.edu */ 00010 /* */ 00011 /******************************************************************************/ 00012 00013 00014 #ifndef __OBJECTIVEFUNCTION_H__ 00015 #define __OBJECTIVEFUNCTION_H__ 00016 00017 #include "../Utilities/Vector.h" 00018 #include "../Utilities/Matrix.h" 00019 00020 namespace Purple 00021 { 00022 00023 /// This abstract class represents the concept of objective function. 00024 /// Any derived class must implement the getEvaluation(Vector<double>) method. 00025 00026 class ObjectiveFunction 00027 { 00028 00029 protected: 00030 00031 /// Number of variables in the objective function. 00032 00033 int numberOfVariables; 00034 00035 /// Lower bound of objective function domain. 00036 00037 Vector<double> lowerBound; 00038 00039 /// Upper bound of objective function domain. 00040 00041 Vector<double> upperBound; 00042 00043 /// Number of calls to the getEvaluation(Vector<double>) method. 00044 /// 00045 /// @see getEvaluation(Vector<double>). 00046 00047 int numberOfEvaluations; 00048 00049 /// Epsilon value for numerical differentiation. 00050 00051 double epsilon; 00052 00053 // Utility methods 00054 00055 double getDeterminant(Matrix<double>); 00056 00057 public: 00058 00059 // GENERAL CONSTRUCTOR 00060 00061 ObjectiveFunction(void); 00062 00063 00064 // DESTRUCTOR 00065 00066 virtual ~ObjectiveFunction(void); 00067 00068 00069 // METHODS 00070 00071 // Get methods 00072 00073 int getNumberOfVariables(void); 00074 00075 Vector<double> getLowerBound(void); 00076 Vector<double> getUpperBound(void); 00077 00078 Matrix<double> getDomain(void); 00079 00080 double getEpsilon(void); 00081 int getNumberOfEvaluations(void); 00082 00083 // Set methods 00084 00085 void setNumberOfVariables(int); 00086 00087 void setLowerBound(Vector<double>); 00088 void setUpperBound(Vector<double>); 00089 00090 void setDomain(Matrix<double>); 00091 00092 void setEpsilon(double); 00093 void setNumberOfEvaluations(int); 00094 00095 // Objective function methods 00096 00097 /// This method returns the evaluation value of an objective function for 00098 /// a given argument. 00099 /// 00100 /// @see getGradient(Vector<double>). 00101 /// @see getHessian(Vector<double>). 00102 00103 virtual double getEvaluation(Vector<double>) = 0; 00104 00105 // Objective function gradient vector methods 00106 00107 /// This method returns the objective function gradient vector for a 00108 /// given argument. 00109 /// 00110 /// @see getEvaluation(Vector<double>). 00111 /// @see getHessian(Vector<double>). 00112 00113 virtual Vector<double> getGradient(Vector<double>); 00114 00115 double getGradientNorm(Vector<double>); 00116 00117 // Objective function Hessian matrix methods 00118 00119 /// This method returns the objective function Hessian matrix for a 00120 /// given argument. 00121 /// 00122 /// @see getEvaluation(Vector<double>). 00123 /// @see getGradient(Vector<double>). 00124 00125 virtual Matrix<double> getHessian(Vector<double>); 00126 00127 /// This method returns the inverse of the Hessian matrix for a 00128 /// given argument. 00129 /// 00130 /// @see getEvaluation(Vector<double>). 00131 /// @see getGradient(Vector<double>). 00132 /// @see getHessian(Vector<double>). 00133 00134 virtual Matrix<double> getInverseHessian(Vector<double>); 00135 00136 // Utility methods 00137 00138 /// This prints to the screen any useful information of the objective function 00139 /// for a given argument during the optimization process. 00140 00141 virtual void print(Vector<double>); 00142 }; 00143 00144 } 00145 00146 #endif 00147 00148 00149 // Purple: An Open Source Numerical Optimization C++ Library. 00150 // Copyright (C) 2006 Roberto Lopez 00151 // 00152 // This library is free software; you can redistribute it and/or 00153 // modify it under the terms of the GNU Lesser General Public 00154 // License as published by the Free Software Foundation; either 00155 // version 2.1 of the License, or any later version. 00156 // 00157 // This library is distributed in the hope that it will be useful, 00158 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00159 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00160 // Lesser General Public License for more details. 00161 00162 // You should have received a copy of the GNU Lesser General Public 00163 // License along with this library; if not, write to the Free Software 00164 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA