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 
62 class LevenbergMarquardtDense : public NlpSolverInterface
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 
115  double _weight_adapt_factor_eq = 1;
117  double _weight_adapt_factor_bounds = 1;
118 
119  double _weight_adapt_max_eq = 500;
120  double _weight_adapt_max_ineq = 500;
121  double _weight_adapt_max_bounds = 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;
128  int _finite_bounds_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 
137  double _weight_eq = _weight_init_eq;
140 };
141 
143 
144 } // namespace corbo
145 
146 #endif // SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_SOLVER_LEVENBERG_MARQUARDT_DENSE_H_
corbo::LevenbergMarquardtDense::_weight_init_bounds
double _weight_init_bounds
Definition: levenberg_marquardt_dense.h:157
corbo::LevenbergMarquardtDense::getInstance
NlpSolverInterface::Ptr getInstance() const override
Return a newly created instance of the current solver.
Definition: levenberg_marquardt_dense.h:113
corbo::LevenbergMarquardtDense::_val_dim
int _val_dim
Definition: levenberg_marquardt_dense.h:173
corbo::LevenbergMarquardtDense::_iterations
int _iterations
Definition: levenberg_marquardt_dense.h:153
corbo::LevenbergMarquardtDense::initialize
bool initialize(OptimizationProblemInterface *problem=nullptr) override
Initialize the solver w.r.t. a given optimization problem.
Definition: levenberg_marquardt_dense.cpp:55
corbo
Definition: communication/include/corbo-communication/utilities.h:37
corbo::LevenbergMarquardtDense::_delta
Eigen::VectorXd _delta
Definition: levenberg_marquardt_dense.h:178
corbo::LevenbergMarquardtDense::_weight_init_eq
double _weight_init_eq
Definition: levenberg_marquardt_dense.h:155
corbo::LevenbergMarquardtDense::computeJacobian
void computeJacobian(OptimizationProblemInterface &problem)
Compute overall jacobian including constraint approximation.
Definition: levenberg_marquardt_dense.cpp:248
corbo::LevenbergMarquardtDense::_weight_adapt_max_eq
double _weight_adapt_max_eq
Definition: levenberg_marquardt_dense.h:163
corbo::LevenbergMarquardtDense::_eq_dim
int _eq_dim
Definition: levenberg_marquardt_dense.h:170
corbo::LevenbergMarquardtDense::_weight_bounds
double _weight_bounds
Definition: levenberg_marquardt_dense.h:183
corbo::SolverStatus
SolverStatus
Definition: optimization/include/corbo-optimization/types.h:52
nlp_solver_interface.h
corbo::NlpSolverInterface::Ptr
std::shared_ptr< NlpSolverInterface > Ptr
Definition: nlp_solver_interface.h:114
corbo::LevenbergMarquardtDense::isLsqSolver
bool isLsqSolver() const override
Return true if the solver onyl supports costs in lsq form.
Definition: levenberg_marquardt_dense.h:116
corbo::LevenbergMarquardtDense::setPenaltyWeights
void setPenaltyWeights(double weight_eq, double weight_ineq, double weight_bounds)
Define penalty weights (equality constraints, inequality constraints, bounds)
Definition: levenberg_marquardt_dense.cpp:274
corbo::LevenbergMarquardtDense::adaptWeights
void adaptWeights()
Perform single weight adapation step.
Definition: levenberg_marquardt_dense.cpp:303
corbo::LevenbergMarquardtDense::_weight_ineq
double _weight_ineq
Definition: levenberg_marquardt_dense.h:182
corbo::LevenbergMarquardtDense::setWeightAdapation
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...
Definition: levenberg_marquardt_dense.cpp:285
corbo::LevenbergMarquardtDense::_weight_eq
double _weight_eq
Definition: levenberg_marquardt_dense.h:181
corbo::LevenbergMarquardtDense::_finite_bounds_dim
int _finite_bounds_dim
Definition: levenberg_marquardt_dense.h:172
corbo::LevenbergMarquardtDense::clear
void clear() override
Clear internal caches.
Definition: levenberg_marquardt_dense.cpp:315
corbo::LevenbergMarquardtDense::_hessian
Eigen::MatrixXd _hessian
Definition: levenberg_marquardt_dense.h:177
corbo::LevenbergMarquardtDense::_rhs
Eigen::VectorXd _rhs
Definition: levenberg_marquardt_dense.h:179
corbo::LevenbergMarquardtDense::_weight_adapt_max_bounds
double _weight_adapt_max_bounds
Definition: levenberg_marquardt_dense.h:165
corbo::LevenbergMarquardtDense::UPtr
std::unique_ptr< LevenbergMarquardtDense > UPtr
Definition: levenberg_marquardt_dense.h:110
corbo::LevenbergMarquardtDense::computeValues
void computeValues(OptimizationProblemInterface &problem)
Compute overall value vector including constraint approximation.
Definition: levenberg_marquardt_dense.cpp:222
corbo::LevenbergMarquardtDense::_weight_init_ineq
double _weight_init_ineq
Definition: levenberg_marquardt_dense.h:156
corbo::LevenbergMarquardtDense::_weight_adapt_max_ineq
double _weight_adapt_max_ineq
Definition: levenberg_marquardt_dense.h:164
corbo::LevenbergMarquardtDense::_values
Eigen::VectorXd _values
Definition: levenberg_marquardt_dense.h:175
corbo::LevenbergMarquardtDense::_weight_adapt_factor_ineq
double _weight_adapt_factor_ineq
Definition: levenberg_marquardt_dense.h:160
corbo::LevenbergMarquardtDense::_ineq_dim
int _ineq_dim
Definition: levenberg_marquardt_dense.h:171
corbo::LevenbergMarquardtDense::_obj_dim
int _obj_dim
Definition: levenberg_marquardt_dense.h:169
corbo::LevenbergMarquardtDense::_weight_adapt_factor_bounds
double _weight_adapt_factor_bounds
Definition: levenberg_marquardt_dense.h:161
FACTORY_REGISTER_NLP_SOLVER
#define FACTORY_REGISTER_NLP_SOLVER(type)
Definition: nlp_solver_interface.h:140
corbo::LevenbergMarquardtDense::_jacobian
Eigen::MatrixXd _jacobian
Definition: levenberg_marquardt_dense.h:176
corbo::LevenbergMarquardtDense::solve
SolverStatus solve(OptimizationProblemInterface &problem, bool new_structure=true, bool new_run=true, double *obj_value=nullptr) override
Solve the provided optimization problem.
Definition: levenberg_marquardt_dense.cpp:66
corbo::LevenbergMarquardtDense
Levenberg-Marquardt Solver (Dense matrices version).
Definition: levenberg_marquardt_dense.h:84
corbo::LevenbergMarquardtDense::_weight_adapt_factor_eq
double _weight_adapt_factor_eq
Definition: levenberg_marquardt_dense.h:159
corbo::OptimizationProblemInterface
Generic interface for optimization problem definitions.
Definition: optimization_problem_interface.h:92
corbo::LevenbergMarquardtDense::_param_dim
int _param_dim
Definition: levenberg_marquardt_dense.h:168
corbo::LevenbergMarquardtDense::setIterations
void setIterations(int iterations)
Define the number of solver iterations.
Definition: levenberg_marquardt_dense.h:124
corbo::LevenbergMarquardtDense::Ptr
std::shared_ptr< LevenbergMarquardtDense > Ptr
Definition: levenberg_marquardt_dense.h:109
corbo::LevenbergMarquardtDense::resetWeights
void resetWeights()
Reset weights to their original values.
Definition: levenberg_marquardt_dense.cpp:296


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:05:52