levenberg_marquardt_dense.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2020,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  *
22  * Authors: Christoph Rösmann
23  *********************************************************************/
24 
25 #ifndef SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_SOLVER_LEVENBERG_MARQUARDT_DENSE_H_
26 #define SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_SOLVER_LEVENBERG_MARQUARDT_DENSE_H_
27 
29 
30 #include <memory>
31 
32 namespace corbo {
33 
63 {
64  public:
65  using Ptr = std::shared_ptr<LevenbergMarquardtDense>;
66  using UPtr = std::unique_ptr<LevenbergMarquardtDense>;
67 
68  // implements interface method
69  NlpSolverInterface::Ptr getInstance() const override { return std::make_shared<LevenbergMarquardtDense>(); }
70 
71  // implements interface method
72  bool isLsqSolver() const override { return true; }
73 
74  // implements interface method
75  bool initialize(OptimizationProblemInterface* problem = nullptr) override;
76  // implements interface method
77  SolverStatus solve(OptimizationProblemInterface& problem, bool new_structure = true, bool new_run = true, double* obj_value = nullptr) override;
78 
80  void setIterations(int iterations) { _iterations = iterations; }
82  void setPenaltyWeights(double weight_eq, double weight_ineq, double weight_bounds);
84  void setWeightAdapation(double factor_eq, double factor_ineq, double factor_bounds, double max_eq, double max_ineq, double max_bounds);
85 
86  // implements interface method
87  void clear() override;
88 
89 #ifdef MESSAGE_SUPPORT
90  // implements interface method
91  void toMessage(corbo::messages::NlpSolver& message) const override;
92  // implements interface method
93  void fromMessage(const corbo::messages::NlpSolver& message, std::stringstream* issues = nullptr) override;
94 #endif
95 
96  protected:
101 
103  void resetWeights();
105  void adaptWeights();
106 
107  private:
108  // parameters
109  int _iterations = 10;
110 
111  double _weight_init_eq = 2;
112  double _weight_init_ineq = 2;
114 
118 
119  double _weight_adapt_max_eq = 500;
122 
123  // internal states
124  int _param_dim = 0;
125  int _obj_dim = 0;
126  int _eq_dim = 0;
127  int _ineq_dim = 0;
129  int _val_dim = 0;
130 
131  Eigen::VectorXd _values;
132  Eigen::MatrixXd _jacobian;
133  Eigen::MatrixXd _hessian;
134  Eigen::VectorXd _delta;
135  Eigen::VectorXd _rhs;
136 
140 };
141 
143 
144 } // namespace corbo
145 
146 #endif // SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_SOLVER_LEVENBERG_MARQUARDT_DENSE_H_
SolverStatus solve(OptimizationProblemInterface &problem, bool new_structure=true, bool new_run=true, double *obj_value=nullptr) override
Solve the provided optimization problem.
void adaptWeights()
Perform single weight adapation step.
void resetWeights()
Reset weights to their original values.
std::unique_ptr< LevenbergMarquardtDense > UPtr
Levenberg-Marquardt Solver (Dense matrices version).
void computeJacobian(OptimizationProblemInterface &problem)
Compute overall jacobian including constraint approximation.
void setWeightAdapation(double factor_eq, double factor_ineq, double factor_bounds, double max_eq, double max_ineq, double max_bounds)
Set parameters for weight adaptation (refer to the class description); set factors to 1 in order to d...
bool initialize(OptimizationProblemInterface *problem=nullptr) override
Initialize the solver w.r.t. a given optimization problem.
void clear() override
Clear internal caches.
Generic interface for optimization problem definitions.
void setPenaltyWeights(double weight_eq, double weight_ineq, double weight_bounds)
Define penalty weights (equality constraints, inequality constraints, bounds)
std::shared_ptr< NlpSolverInterface > Ptr
NlpSolverInterface::Ptr getInstance() const override
Return a newly created instance of the current solver.
Generic interface for solver implementations.
void setIterations(int iterations)
Define the number of solver iterations.
std::shared_ptr< LevenbergMarquardtDense > Ptr
void computeValues(OptimizationProblemInterface &problem)
Compute overall value vector including constraint approximation.
#define FACTORY_REGISTER_NLP_SOLVER(type)
bool isLsqSolver() const override
Return true if the solver onyl supports costs in lsq form.


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Mon Feb 28 2022 22:06:59