MUQ  0.4.3
Optimizer.h
Go to the documentation of this file.
1 #ifndef OPTIMIZER_H_
2 #define OPTIMIZER_H_
3 
4 #include <boost/property_tree/ptree.hpp>
5 
8 
10 
11 namespace muq {
12 namespace Optimization {
14 
22  public:
23 
24  Optimizer(std::shared_ptr<muq::Modeling::ModPiece> const& cost,
25  boost::property_tree::ptree const& pt);
26 
27 
28 
29  virtual ~Optimizer() = default;
30 
45  static std::shared_ptr<Optimizer> Construct(std::shared_ptr<muq::Modeling::ModPiece> const& cost,
46  boost::property_tree::ptree const& options);
47 
48 
49  typedef std::function<std::shared_ptr<Optimizer>(std::shared_ptr<muq::Modeling::ModPiece> const&, boost::property_tree::ptree)> OptimizerConstructor;
50  typedef std::map<std::string, OptimizerConstructor> OptimizerMap;
51  static std::shared_ptr<OptimizerMap> GetOptimizerMap();
52 
55  static void ListMethods(std::string prefix="");
56 
58 
61  virtual void AddInequalityConstraint(std::vector<std::shared_ptr<muq::Modeling::ModPiece>> const& ineq);
62 
64 
67  virtual void AddInequalityConstraint(std::shared_ptr<muq::Modeling::ModPiece> const& ineq);
68 
69 
72 
74 
78  virtual void AddEqualityConstraint(std::vector<std::shared_ptr<muq::Modeling::ModPiece>> const& eq);
79 
81 
85  virtual void AddEqualityConstraint(std::shared_ptr<muq::Modeling::ModPiece> const& eq);
86 
89 
91 
96  virtual std::pair<Eigen::VectorXd, double> Solve(std::vector<Eigen::VectorXd> const& inputs) = 0;
97 
98  protected:
99 
100  virtual void EvaluateImpl(muq::Modeling::ref_vector<boost::any> const& inputs) override;
101 
102  static std::shared_ptr<CostFunction> ConvertModPiece(std::shared_ptr<muq::Modeling::ModPiece> const& modCost);
103 
105  std::shared_ptr<CostFunction> opt;
106 
108  std::vector<std::shared_ptr<muq::Modeling::ModPiece>> ineqConstraints;
109 
111 
114  std::vector<std::shared_ptr<muq::Modeling::ModPiece>> eqConstraints;
115 
118 
120  const double constraint_tol;
121 
123  const unsigned int maxEvals;
124  };
125 
126 } // namespace Optimization
127 } // namespace muq
128 
129 #define REGISTER_OPTIMIZER(OPTNAME, CLASSNAME) static auto optReg ##OPTNAME = muq::Optimization::Optimizer::GetOptimizerMap()->insert(std::make_pair(#OPTNAME, muq::Utilities::shared_factory<CLASSNAME>()));
130 
131 
132 
133 #endif
Base class for MUQ's modelling envronment.
Definition: WorkPiece.h:40
Solve an optimization problem.
Definition: Optimizer.h:21
virtual ~Optimizer()=default
Optimizer(std::shared_ptr< muq::Modeling::ModPiece > const &cost, boost::property_tree::ptree const &pt)
Definition: Optimizer.cpp:11
std::function< std::shared_ptr< Optimizer >std::shared_ptr< muq::Modeling::ModPiece > const &, boost::property_tree::ptree)> OptimizerConstructor
Definition: Optimizer.h:49
std::vector< std::shared_ptr< muq::Modeling::ModPiece > > ineqConstraints
Inequality constraints.
Definition: Optimizer.h:108
const double constraint_tol
Tolerance on the constraints.
Definition: Optimizer.h:120
std::shared_ptr< CostFunction > opt
The cost function that we are trying to minimize.
Definition: Optimizer.h:105
void ClearEqualityConstraint()
Clear all equality constraints.
Definition: Optimizer.cpp:66
virtual void AddInequalityConstraint(std::vector< std::shared_ptr< muq::Modeling::ModPiece >> const &ineq)
Add an inequality constraint to the optimization.
Definition: Optimizer.cpp:46
static std::shared_ptr< Optimizer > Construct(std::shared_ptr< muq::Modeling::ModPiece > const &cost, boost::property_tree::ptree const &options)
Definition: Optimizer.cpp:78
static std::shared_ptr< CostFunction > ConvertModPiece(std::shared_ptr< muq::Modeling::ModPiece > const &modCost)
Definition: Optimizer.cpp:25
virtual void AddEqualityConstraint(std::vector< std::shared_ptr< muq::Modeling::ModPiece >> const &eq)
Add an equality constraint to the optimization.
Definition: Optimizer.cpp:58
std::vector< std::shared_ptr< muq::Modeling::ModPiece > > eqConstraints
Equality constraints.
Definition: Optimizer.h:114
virtual void EvaluateImpl(muq::Modeling::ref_vector< boost::any > const &inputs) override
User-implemented function that determines the behavior of this muq::Modeling::WorkPiece.
Definition: Optimizer.cpp:37
virtual std::pair< Eigen::VectorXd, double > Solve(std::vector< Eigen::VectorXd > const &inputs)=0
Solve the optimization problem.
const unsigned int maxEvals
Maximum number of cost function evaluations.
Definition: Optimizer.h:123
std::map< std::string, OptimizerConstructor > OptimizerMap
Definition: Optimizer.h:50
void ClearInequalityConstraint()
Clear all inequality constraints.
Definition: Optimizer.cpp:54
const double ftol_rel
Relative and absolute tolerances on the cost function value and on the difference between successive ...
Definition: Optimizer.h:117
static void ListMethods(std::string prefix="")
Definition: Optimizer.cpp:71
static std::shared_ptr< OptimizerMap > GetOptimizerMap()
Definition: Optimizer.cpp:95
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
Definition: WorkPiece.h:37