MBSim |
Project Page |
00001 /* Copyright (C) 2004-2012 MBSim Development Team 00002 * 00003 * This library is free software; you can redistribute it and/or 00004 * modify it under the terms of the GNU Lesser General Public 00005 * License as published by the Free Software Foundation; either 00006 * version 2.1 of the License, or (at your option) any later version. 00007 * 00008 * This library is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public 00014 * License along with this library; if not, write to the Free Software 00015 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00016 * 00017 * Contact: martin.o.foerg@googlemail.com 00018 */ 00019 00020 #ifndef NUMERICSCRITERIAFUNCTIONS_H_ 00021 #define NUMERICSCRITERIAFUNCTIONS_H_ 00022 00023 #include <fmatvec/fmatvec.h> 00024 #include <fmatvec/function.h> 00025 00026 #include <map> 00027 00028 namespace MBSim { 00029 00033 class CriteriaFunction : public fmatvec::Function<int(fmatvec::Vec)> { 00034 00035 public: 00039 CriteriaFunction(); 00040 00044 virtual ~CriteriaFunction(); 00045 00046 /* GETTER / SETTER*/ 00047 void setFunction(Function<fmatvec::Vec(fmatvec::Vec)> *function_) { 00048 function = function_; 00049 } 00050 /*****************/ 00051 00061 virtual int operator ()(const fmatvec::Vec & vector) = 0; 00062 00066 virtual void clear() = 0; 00067 00071 virtual bool isBetter(const fmatvec::Vec & vector) = 0; 00072 00073 protected: 00077 Function<fmatvec::Vec(fmatvec::Vec)> *function; 00078 00079 }; 00080 00084 class GlobalCriteriaFunction : public CriteriaFunction { 00085 00086 public: 00090 GlobalCriteriaFunction(const double & tolerance_ = 1e-10); 00091 00095 virtual ~GlobalCriteriaFunction(); 00096 00097 /* INHERITED INTERFACE */ 00098 virtual int operator ()(const fmatvec::Vec & vector); 00099 virtual bool isBetter(const fmatvec::Vec & vector); 00100 virtual void clear(); 00101 /*END - INHERITED INTERFACE*/ 00102 00103 const std::vector<double> & getResults() { 00104 return criteriaResults; 00105 } 00106 00107 protected: 00108 /*INHERITED INTERFACE*/ 00109 virtual double computeResults(const fmatvec::Vec & x) = 0; 00110 /********************/ 00111 00115 double tolerance; 00116 00120 std::vector<double> criteriaResults; 00121 }; 00122 00126 class LocalCriteriaFunction : public CriteriaFunction { 00127 00128 public: 00132 LocalCriteriaFunction(const std::map<fmatvec::Index, double> & tolerances_); 00133 00137 virtual ~LocalCriteriaFunction(); 00138 00139 /* INHERITED INTERFACE */ 00140 virtual int operator ()(const fmatvec::Vec & vector); 00141 virtual bool isBetter(const fmatvec::Vec & vector); 00142 virtual void clear(); 00143 /*END - INHERITED INTERFACE*/ 00144 00145 virtual void setTolerances(const std::map<fmatvec::Index, double> & tolerances_) { 00146 tolerances = tolerances_; 00147 } 00148 00149 protected: 00150 virtual std::vector<double> computeResults(const fmatvec::Vec & x) = 0; 00151 00152 /* 00153 * \brief saves the tolerance for a specified index sets 00154 */ 00155 std::map<fmatvec::Index, double> tolerances; 00156 00160 std::vector<std::vector<double> > criteriaResults; 00161 }; 00162 00166 class GlobalResidualCriteriaFunction : public GlobalCriteriaFunction { 00167 00168 public: 00172 GlobalResidualCriteriaFunction(const double & tolerance_ = 1e-10); 00173 00177 virtual ~GlobalResidualCriteriaFunction(); 00178 00179 protected: 00180 /* INHERITED INTERFACE */ 00181 virtual double computeResults(const fmatvec::Vec & x); 00182 /*END - INHERITED INTERFACE*/ 00183 }; 00184 00188 class LocalResidualCriteriaFunction : public LocalCriteriaFunction { 00189 00190 public: 00194 LocalResidualCriteriaFunction(const std::map<fmatvec::Index, double> & tolerances_); 00195 00199 virtual ~LocalResidualCriteriaFunction(); 00200 00201 protected: 00202 00203 virtual std::vector<double> computeResults(const fmatvec::Vec & x); 00204 }; 00205 00209 class GlobalShiftCriteriaFunction : public GlobalCriteriaFunction { 00210 public: 00214 GlobalShiftCriteriaFunction(const double & tolerance_ = 1e-10); 00215 00219 virtual ~GlobalShiftCriteriaFunction(); 00220 00221 virtual fmatvec::Vec getLastPoint() { 00222 return lastPoint; 00223 } 00224 00225 protected: 00226 /* INHERITED INTERFACE */ 00227 virtual double computeResults(const fmatvec::Vec & x); 00228 /*END - INHERITED INTERFACE*/ 00229 00233 fmatvec::Vec lastPoint; 00234 00235 }; 00236 00240 class LocalShiftCriteriaFunction : public LocalCriteriaFunction { 00241 00242 public: 00246 LocalShiftCriteriaFunction(const std::map<fmatvec::Index, double> & tolerances_); 00247 00251 virtual ~LocalShiftCriteriaFunction(); 00252 00253 virtual fmatvec::Vec getLastPoint() { 00254 return lastPoint; 00255 } 00256 00257 protected: 00258 virtual std::vector<double> computeResults(const fmatvec::Vec & x); 00259 00263 fmatvec::Vec lastPoint; 00264 }; 00265 00266 inline CriteriaFunction::~CriteriaFunction(){} 00267 inline GlobalCriteriaFunction::~GlobalCriteriaFunction(){} 00268 inline LocalCriteriaFunction::~LocalCriteriaFunction(){} 00269 inline GlobalResidualCriteriaFunction::~GlobalResidualCriteriaFunction() {} 00270 inline GlobalShiftCriteriaFunction::~GlobalShiftCriteriaFunction() {} 00271 inline LocalResidualCriteriaFunction::~LocalResidualCriteriaFunction() {} 00272 inline LocalShiftCriteriaFunction::~LocalShiftCriteriaFunction() {} 00273 } 00274 #endif //NUMERICSCRITERIAFUNCTIONS_H_
1.8.0