MUQ  0.4.3
NLoptOptimizer.h
Go to the documentation of this file.
1 #ifndef NLOPTOPTIMIZATION_H_
2 #define NLOPTOPTIMIZATION_H_
3 
4 #include <boost/property_tree/ptree.hpp>
5 
6 #include <nlopt.h>
7 
10 
11 namespace muq {
12  namespace Optimization {
13 
14  class NLoptOptimizer : public Optimizer {
15  public:
16 
17  NLoptOptimizer(std::shared_ptr<muq::Modeling::ModPiece> const& cost,
18  boost::property_tree::ptree const& pt);
19 
20  virtual ~NLoptOptimizer() = default;
21 
22  virtual std::pair<Eigen::VectorXd, double> Solve(std::vector<Eigen::VectorXd> const& inputs) override;
23 
24  private:
25 
27 
34  static double Cost(unsigned int n,
35  const double* x,
36  double* grad,
37  void* f_data);
38 
39 
40  static void Constraint(unsigned int m,
41  double* result,
42  unsigned int n,
43  const double* x,
44  double* grad,
45  void* f_data);
46 
47 
49 
52  virtual void EvaluateImpl(muq::Modeling::ref_vector<boost::any> const& inputs) override;
53 
55 
59  nlopt_algorithm NLOptAlgorithm(std::string const& alg) const;
60 
62  const nlopt_algorithm algorithm;
63 
65  const bool minimize = true;
66 
67 
68  }; // class NLoptOptimizer
69 
70  } // namespace Optimization
71 } // namespace muq
72 
73 #endif
virtual void EvaluateImpl(muq::Modeling::ref_vector< boost::any > const &inputs) override
Override the evaluate impl method (solve the optimization problem)
const nlopt_algorithm algorithm
The algorithm used to solve the problem.
static double Cost(unsigned int n, const double *x, double *grad, void *f_data)
Evaluate either the cost function or a constraint.
static void Constraint(unsigned int m, double *result, unsigned int n, const double *x, double *grad, void *f_data)
NLoptOptimizer(std::shared_ptr< muq::Modeling::ModPiece > const &cost, boost::property_tree::ptree const &pt)
virtual std::pair< Eigen::VectorXd, double > Solve(std::vector< Eigen::VectorXd > const &inputs) override
Solve the optimization problem.
nlopt_algorithm NLOptAlgorithm(std::string const &alg) const
Get the NLOPT algorithm we are using.
const bool minimize
True: minimize the cost function, False: maximize the cost function.
Solve an optimization problem.
Definition: Optimizer.h:21
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
Definition: WorkPiece.h:37