My Project
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 {
44 public:
45 
50 
52  typedef std::shared_ptr<CMinimizer> Pointer;
53 
56  success
57  };
58 
60  static const char *const type_descr;
61 
63  static const char *const data_descr;
64 
82  {
83  public:
84  virtual ~Problem();
85 
93  double f(size_t n, const double *x);
94 
104  void df(size_t n, const double *x, double *g);
113  double fdf(size_t n, const double *x, double *g);
114 
122  double f(const std::vector<double>& x);
123 
131  void df(const std::vector<double>& x, std::vector<double>& g);
132 
140  double fdf(const std::vector<double>& x, std::vector<double>& g);
141 
149  double f(const CDoubleVector& x);
150 
158  void df(const CDoubleVector& x, CDoubleVector& g);
159 
167  double fdf(const CDoubleVector& x, CDoubleVector& g);
168 
169 
171  size_t size() const;
172  private:
173  virtual double do_f(const CDoubleVector& x) = 0;
174  virtual void do_df(const CDoubleVector& x, CDoubleVector& g) = 0;
175  virtual double do_fdf(const CDoubleVector& x, CDoubleVector& g) = 0;
176  virtual size_t do_size() const = 0;
177  };
178 
180  typedef std::shared_ptr<Problem> PProblem;
181 
185  CMinimizer();
186 
191  void set_problem(PProblem x);
192 
193 
194  virtual ~CMinimizer();
195 
196 
202  int run(CDoubleVector& x);
203 
204 protected:
206  Problem *get_problem_pointer();
207 
209  size_t size() const;
210 
212  Problem& get_problem();
213 private:
214  virtual void do_set_problem();
215  virtual int do_run(CDoubleVector& x) = 0;
216 
217  PProblem m_problem;
218 };
219 
222 
225 
228 
231 
233 {
234  return *m_problem;
235 }
236 
237 inline
238 PMinimizer produce_minimizer(const std::string& descr)
239 {
240  return CMinimizerPluginHandler::instance().produce(descr);
241 }
242 
243 
245 
246 #endif
CMinimizer::Pointer
std::shared_ptr< CMinimizer > Pointer
Pointer type of this minimizer.
Definition: minimizer.hh:52
CMinimizer::failure
Definition: minimizer.hh:55
THandlerSingleton::instance
static const T & instance()
factory.hh
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
produce_minimizer
PMinimizer produce_minimizer(const std::string &descr)
Definition: minimizer.hh:238
PMinimizer
CMinimizer::Pointer PMinimizer
Pointer type for the CMinimizer class.
Definition: minimizer.hh:221
FACTORY_TRAIT
FACTORY_TRAIT(CMinimizerPluginHandler)
Trait to make the minimizer definition parsable on the command line.
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
CMinimizerPlugin
TFactory< CMinimizer > CMinimizerPlugin
Base class for the CMinimizer creator plugins.
Definition: minimizer.hh:224
CMinimizer
A class for generalized minimization problems.
Definition: minimizer.hh:42
THandlerSingleton
the singleton that a plug-in handler really is
Definition: handler.hh:158
CPropertyFlagHolder
This class holds a set of properties.
Definition: property_flags.hh:41
CMinimizer::get_problem
Problem & get_problem()
Definition: minimizer.hh:232
handler.hh
CMinimizer::type_descr
static const char *const type_descr
plug-in searchpath helper
Definition: minimizer.hh:60
vector.hh
CMinimizer::data_descr
static const char *const data_descr
plug-in searchpath helper
Definition: minimizer.hh:63
CMinimizer::EMinimizerResult
EMinimizerResult
enum to describe whether optimization succeeded
Definition: minimizer.hh:55
CProductBase
The base class for all plug-in created object.
Definition: product_base.hh:40
CMinimizerPluginHandler
THandlerSingleton< TFactoryPluginHandler< CMinimizerPlugin > > CMinimizerPluginHandler
The minimizer plugin handler.
Definition: minimizer.hh:227
EXPORT_CORE
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
TCArrayWrapper
A wrapper around the c-array to provide an STL like interface for iterators.
Definition: core/vector.hh:77
CMinimizer::plugin_type
CMinimizer plugin_type
plug-in searchpath typedef helper
Definition: minimizer.hh:49
CMinimizer::PProblem
std::shared_ptr< Problem > PProblem
pointer type for the optimization problem
Definition: minimizer.hh:180
CMinimizer::Problem
Base class for all optimization problems that can be run by CMinimizer.
Definition: minimizer.hh:81
CMinimizer::plugin_data
CMinimizer plugin_data
plug-in searchpath typedef helper
Definition: minimizer.hh:47
TFactory
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition: factory.hh:49