MBSim

Project Page
criteria_functions.h
1 /* Copyright (C) 2004-2012 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@googlemail.com
18  */
19 
20 #ifndef NUMERICSCRITERIAFUNCTIONS_H_
21 #define NUMERICSCRITERIAFUNCTIONS_H_
22 
23 #include <mbsim/utils/function.h>
24 
25 #include <fmatvec.h>
26 
27 #include <map>
28 
29 namespace MBSim {
30 
34  class CriteriaFunction : public Function1<int, fmatvec::Vec> {
35 
36  public:
41 
45  virtual ~CriteriaFunction();
46 
47  /* GETTER / SETTER*/
48  void setFunction(Function1<fmatvec::Vec, fmatvec::Vec> * function_) {
49  function = function_;
50  }
51  /*****************/
52 
62  virtual int operator ()(const fmatvec::Vec & vector, const void * = NULL) = 0;
63 
67  virtual void clear() = 0;
68 
72  virtual bool isBetter(const fmatvec::Vec & vector) = 0;
73 
74  protected:
79 
80  };
81 
86 
87  public:
91  GlobalCriteriaFunction(const double & tolerance_ = 1e-10);
92 
96  virtual ~GlobalCriteriaFunction();
97 
98  /* INHERITED INTERFACE */
99  virtual int operator ()(const fmatvec::Vec & vector, const void * = NULL);
100  virtual bool isBetter(const fmatvec::Vec & vector);
101  virtual void clear();
102  /*END - INHERITED INTERFACE*/
103 
104  const std::vector<double> & getResults() {
105  return criteriaResults;
106  }
107 
108  protected:
109  /*INHERITED INTERFACE*/
110  virtual double computeResults(const fmatvec::Vec & x) = 0;
111  /********************/
112 
116  double tolerance;
117 
121  std::vector<double> criteriaResults;
122  };
123 
128 
129  public:
133  LocalCriteriaFunction(const std::map<fmatvec::Index, double> & tolerances_);
134 
138  virtual ~LocalCriteriaFunction();
139 
140  /* INHERITED INTERFACE */
141  virtual int operator ()(const fmatvec::Vec & vector, const void * = NULL);
142  virtual bool isBetter(const fmatvec::Vec & vector);
143  virtual void clear();
144  /*END - INHERITED INTERFACE*/
145 
146  virtual void setTolerances(const std::map<fmatvec::Index, double> & tolerances_) {
147  tolerances = tolerances_;
148  }
149 
150  protected:
151  virtual std::vector<double> computeResults(const fmatvec::Vec & x) = 0;
152 
153  /*
154  * \brief saves the tolerance for a specified index sets
155  */
156  std::map<fmatvec::Index, double> tolerances;
157 
161  std::vector<std::vector<double> > criteriaResults;
162  };
163 
168 
169  public:
173  GlobalResidualCriteriaFunction(const double & tolerance_ = 1e-10);
174 
179 
180  protected:
181  /* INHERITED INTERFACE */
182  virtual double computeResults(const fmatvec::Vec & x);
183  /*END - INHERITED INTERFACE*/
184  };
185 
190 
191  public:
195  LocalResidualCriteriaFunction(const std::map<fmatvec::Index, double> & tolerances_);
196 
201 
202  protected:
203 
204  virtual std::vector<double> computeResults(const fmatvec::Vec & x);
205  };
206 
211  public:
215  GlobalShiftCriteriaFunction(const double & tolerance_ = 1e-10);
216 
221 
222  virtual fmatvec::Vec getLastPoint() {
223  return lastPoint;
224  }
225 
226  protected:
227  /* INHERITED INTERFACE */
228  virtual double computeResults(const fmatvec::Vec & x);
229  /*END - INHERITED INTERFACE*/
230 
234  fmatvec::Vec lastPoint;
235 
236  };
237 
242 
243  public:
247  LocalShiftCriteriaFunction(const std::map<fmatvec::Index, double> & tolerances_);
248 
252  virtual ~LocalShiftCriteriaFunction();
253 
254  virtual fmatvec::Vec getLastPoint() {
255  return lastPoint;
256  }
257 
258  protected:
259  virtual std::vector<double> computeResults(const fmatvec::Vec & x);
260 
264  fmatvec::Vec lastPoint;
265  };
266 
274 }
275 #endif //NUMERICSCRITERIAFUNCTIONS_H_