MBSim

Project Page
criteria_functions.h
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 <mbsim/utils/function.h>
00024 
00025 #include <fmatvec/fmatvec.h>
00026 
00027 #include <map>
00028 
00029 namespace MBSim {
00030 
00034   class CriteriaFunction : public Function1<int, fmatvec::Vec> {
00035 
00036     public:
00040       CriteriaFunction();
00041 
00045       virtual ~CriteriaFunction();
00046 
00047       /* GETTER / SETTER*/
00048       void setFunction(Function1<fmatvec::Vec, fmatvec::Vec> * function_) {
00049         function = function_;
00050       }
00051       /*****************/
00052 
00062       virtual int operator ()(const fmatvec::Vec & vector, const void * = NULL) = 0;
00063 
00067       virtual void clear() = 0;
00068 
00072       virtual bool isBetter(const fmatvec::Vec & vector) = 0;
00073 
00074     protected:
00078       Function1<fmatvec::Vec, fmatvec::Vec> *function;
00079 
00080   };
00081 
00085   class GlobalCriteriaFunction : public CriteriaFunction {
00086 
00087     public:
00091       GlobalCriteriaFunction(const double & tolerance_ = 1e-10);
00092 
00096       virtual ~GlobalCriteriaFunction();
00097 
00098       /* INHERITED INTERFACE */
00099       virtual int operator ()(const fmatvec::Vec & vector, const void * = NULL);
00100       virtual bool isBetter(const fmatvec::Vec & vector);
00101       virtual void clear();
00102       /*END - INHERITED INTERFACE*/
00103 
00104       const std::vector<double> & getResults() {
00105         return criteriaResults;
00106       }
00107 
00108     protected:
00109       /*INHERITED INTERFACE*/
00110       virtual double computeResults(const fmatvec::Vec & x) = 0;
00111       /********************/
00112 
00116       double tolerance;
00117 
00121       std::vector<double> criteriaResults;
00122   };
00123 
00127   class LocalCriteriaFunction : public CriteriaFunction {
00128 
00129     public:
00133       LocalCriteriaFunction(const std::map<fmatvec::Index, double> & tolerances_);
00134 
00138       virtual ~LocalCriteriaFunction();
00139 
00140       /* INHERITED INTERFACE */
00141       virtual int operator ()(const fmatvec::Vec & vector, const void * = NULL);
00142       virtual bool isBetter(const fmatvec::Vec & vector);
00143       virtual void clear();
00144       /*END - INHERITED INTERFACE*/
00145 
00146       virtual void setTolerances(const std::map<fmatvec::Index, double> & tolerances_) {
00147         tolerances = tolerances_;
00148       }
00149 
00150     protected:
00151       virtual std::vector<double> computeResults(const fmatvec::Vec & x) = 0;
00152 
00153       /*
00154        * \brief saves the tolerance for a specified index sets
00155        */
00156       std::map<fmatvec::Index, double> tolerances;
00157 
00161       std::vector<std::vector<double> > criteriaResults;
00162   };
00163 
00167   class GlobalResidualCriteriaFunction : public GlobalCriteriaFunction {
00168 
00169     public:
00173       GlobalResidualCriteriaFunction(const double & tolerance_ = 1e-10);
00174 
00178       virtual ~GlobalResidualCriteriaFunction();
00179 
00180     protected:
00181       /* INHERITED INTERFACE */
00182       virtual double computeResults(const fmatvec::Vec & x);
00183       /*END - INHERITED INTERFACE*/
00184   };
00185 
00189   class LocalResidualCriteriaFunction : public LocalCriteriaFunction {
00190 
00191     public:
00195       LocalResidualCriteriaFunction(const std::map<fmatvec::Index, double> & tolerances_);
00196 
00200       virtual ~LocalResidualCriteriaFunction();
00201 
00202     protected:
00203 
00204       virtual std::vector<double> computeResults(const fmatvec::Vec & x);
00205   };
00206 
00210   class GlobalShiftCriteriaFunction : public GlobalCriteriaFunction {
00211     public:
00215       GlobalShiftCriteriaFunction(const double & tolerance_ = 1e-10);
00216 
00220       virtual ~GlobalShiftCriteriaFunction();
00221 
00222       virtual fmatvec::Vec getLastPoint() {
00223         return lastPoint;
00224       }
00225 
00226     protected:
00227       /* INHERITED INTERFACE */
00228       virtual double computeResults(const fmatvec::Vec & x);
00229       /*END - INHERITED INTERFACE*/
00230 
00234       fmatvec::Vec lastPoint;
00235 
00236   };
00237 
00241   class LocalShiftCriteriaFunction : public LocalCriteriaFunction {
00242 
00243     public:
00247       LocalShiftCriteriaFunction(const std::map<fmatvec::Index, double> & tolerances_);
00248 
00252       virtual ~LocalShiftCriteriaFunction();
00253 
00254       virtual fmatvec::Vec getLastPoint() {
00255         return lastPoint;
00256       }
00257 
00258     protected:
00259       virtual std::vector<double> computeResults(const fmatvec::Vec & x);
00260 
00264       fmatvec::Vec lastPoint;
00265   };
00266 
00267   inline CriteriaFunction::~CriteriaFunction(){}
00268   inline GlobalCriteriaFunction::~GlobalCriteriaFunction(){}
00269   inline LocalCriteriaFunction::~LocalCriteriaFunction(){}
00270   inline GlobalResidualCriteriaFunction::~GlobalResidualCriteriaFunction() {}
00271   inline GlobalShiftCriteriaFunction::~GlobalShiftCriteriaFunction() {}
00272   inline LocalResidualCriteriaFunction::~LocalResidualCriteriaFunction() {}
00273   inline LocalShiftCriteriaFunction::~LocalShiftCriteriaFunction() {}
00274 }
00275 #endif //NUMERICSCRITERIAFUNCTIONS_H_