minimizer.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_core_minimizer_hh
22 #define mia_core_minimizer_hh
23 
24 #include <memory>
25 #include <vector>
26 
27 #include <mia/core/factory.hh>
28 #include <mia/core/handler.hh>
29 #include <mia/core/vector.hh>
30 
32 
33 
43 public:
44 
49 
51  typedef std::shared_ptr<CMinimizer> Pointer;
52 
55  success
56  };
57 
59  static const char *const type_descr;
60 
62  static const char *const data_descr;
63 
80  class Problem : public CPropertyFlagHolder{
81  public:
82  virtual ~Problem();
83 
91  double f(size_t n, const double *x);
92 
102  void df(size_t n, const double *x, double *g);
111  double fdf(size_t n, const double *x, double *g);
112 
120  double f(const std::vector<double>& x);
121 
129  void df(const std::vector<double>& x, std::vector<double>& g);
130 
138  double fdf(const std::vector<double>& x, std::vector<double>& g);
139 
147  double f(const CDoubleVector& x);
148 
156  void df(const CDoubleVector& x, CDoubleVector& g);
157 
165  double fdf(const CDoubleVector& x, CDoubleVector& g);
166 
167 
169  size_t size() const;
170  private:
171  virtual double do_f(const CDoubleVector& x) = 0;
172  virtual void do_df(const CDoubleVector& x, CDoubleVector& g) = 0;
173  virtual double do_fdf(const CDoubleVector& x, CDoubleVector& g) = 0;
174  virtual size_t do_size() const = 0;
175  };
176 
178  typedef std::shared_ptr<Problem> PProblem;
179 
183  CMinimizer();
184 
189  void set_problem(PProblem x);
190 
191 
192  virtual ~CMinimizer();
193 
194 
200  int run(CDoubleVector& x);
201 
202 protected:
204  Problem *get_problem_pointer();
205 
207  size_t size() const;
208 
210  Problem& get_problem();
211 private:
212  virtual void do_set_problem();
213  virtual int do_run(CDoubleVector& x) = 0;
214 
215  PProblem m_problem;
216 };
217 
220 
223 
226 
229 
231 {
232  return *m_problem;
233 }
234 
235 inline
236 PMinimizer produce_minimizer(const std::string& descr)
237 {
238  return CMinimizerPluginHandler::instance().produce(descr);
239 }
240 
241 
243 
244 #endif
the singleton that a plug-in handler really is
Definition: handler.hh:157
TFactory< CMinimizer > CMinimizerPlugin
Base class for the CMinimizer creator plugins.
Definition: minimizer.hh:222
EMinimizerResult
enum to describe whether optimization succeeded
Definition: minimizer.hh:54
A wrapper around the c-array to provide an STL like interface for iterators.
Definition: core/vector.hh:75
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
CMinimizer plugin_type
plug-in searchpath typedef helper
Definition: minimizer.hh:48
THandlerSingleton< TFactoryPluginHandler< CMinimizerPlugin > > CMinimizerPluginHandler
The minimizer plugin handler.
Definition: minimizer.hh:225
FACTORY_TRAIT(CMinimizerPluginHandler)
Trait to make the minimizer definition parsable on the command line.
A class for generalized minimization problems.
Definition: minimizer.hh:42
std::shared_ptr< Problem > PProblem
pointer type for the optimization problem
Definition: minimizer.hh:178
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition: factory.hh:49
CMinimizer plugin_data
plug-in searchpath typedef helper
Definition: minimizer.hh:46
std::shared_ptr< CMinimizer > Pointer
Pointer type of this minimizer.
Definition: minimizer.hh:51
CMinimizer::Pointer PMinimizer
Pointer type for the CMinimizer class.
Definition: minimizer.hh:219
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
The base class for all plug-in created object.
Definition: product_base.hh:40
static const T & instance()
Problem & get_problem()
Definition: minimizer.hh:230
This class holds a set of properties.
static const char *const type_descr
plug-in searchpath helper
Definition: minimizer.hh:59
static const char *const data_descr
plug-in searchpath helper
Definition: minimizer.hh:62
Base class for all optimization problems that can be run by CMinimizer.
Definition: minimizer.hh:80
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
PMinimizer produce_minimizer(const std::string &descr)
Definition: minimizer.hh:236