proxsuite-nlp  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
Loading...
Searching...
No Matches
prox-solver.hpp
Go to the documentation of this file.
1
3#pragma once
4
13
14#include <boost/mpl/bool.hpp>
15
17
19
20namespace proxsuite {
21namespace nlp {
22
24
25enum class HessianApprox {
27 EXACT,
30};
31
33
35
39template <typename _Scalar> class ProxNLPSolverTpl {
40public:
41 using Scalar = _Scalar;
48 using CallbackPtr = shared_ptr<helpers::base_callback<Scalar>>;
51
52protected:
55
56public:
61
69
71 std::size_t max_refinement_steps_ = 5;
75
77
82 Scalar rho_init_; //< Initial primal proximal penalty parameter.
83 Scalar mu_init_; //< Initial penalty parameter.
84private:
85 Scalar rho_ = rho_init_; //< Primal proximal penalty parameter.
86 Scalar mu_ = mu_init_; //< Penalty parameter.
87 Scalar mu_inv_ = 1. / mu_; //< Inverse penalty parameter.
88public:
89 Scalar inner_tol_min = 1e-9; //< Lower safeguard for the subproblem tolerance.
90 Scalar mu_upper_ = 1.; //< Upper safeguard for the penalty parameter.
91 Scalar mu_lower_ = 1e-9; //< Lower safeguard for the penalty parameter.
92 Scalar pdal_beta_ = 0.5; //< primal-dual weight for the dual variables.
93
96
99
102
105
107
108 Scalar del_inc_k = 8.; //< Inertia corrector increase factor
109 Scalar del_inc_big = 100.; //< Inertia corrector increase factor (big)
110 Scalar del_dec_k = 1. / 3.; //< Inertia corrector decrease factor
111 Scalar DELTA_MIN = 1e-14; //< Minimum nonzero regularization strength.
112 Scalar DELTA_MAX = 1e6; //< Maximum regularization strength.
115
116 std::size_t max_iters = 100; //< Solver maximum number of iterations.
117 std::size_t max_al_iters = 1000; //< Maximum outer (AL) iterations.
118
120 std::vector<CallbackPtr> callbacks_;
121
122 unique_ptr<Workspace> workspace_;
123 unique_ptr<Results> results_;
124
125 ProxNLPSolverTpl(Problem &prob, const Scalar tol = 1e-6,
126 const Scalar mu_eq_init = 1e-2, const Scalar rho_init = 0.,
127 const VerboseLevel verbose = QUIET,
128 const Scalar mu_lower = 1e-9, const Scalar prim_alpha = 0.1,
129 const Scalar prim_beta = 0.9, const Scalar dual_alpha = 1.,
130 const Scalar dual_beta = 1.,
133
134 const Problem &problem() const { return *problem_; }
135
136 const Manifold &manifold() const { return *problem_->manifold_; }
137
138 void setup() {
139 workspace_ = std::make_unique<Workspace>(*problem_, ldlt_choice_);
140 results_ = std::make_unique<Results>(*problem_);
141 }
142
151 ConvergenceFlag solve(const ConstVectorRef &x0,
152 const std::vector<VectorRef> &lams0);
153
154 PROXSUITE_NLP_DEPRECATED
155 const Workspace &getWorkspace() const { return *workspace_; }
156 PROXSUITE_NLP_DEPRECATED
157 const Results &getResults() const { return *results_; }
158
167 ConvergenceFlag solve(const ConstVectorRef &x0,
168 const ConstVectorRef &lams0 = VectorXs(0));
169
170 void innerLoop(Workspace &workspace, Results &results);
171
172 void assembleKktMatrix(Workspace &workspace);
173
176
179 inline void updatePenalty();
180
182 void setDualPenalty(const Scalar beta) { pdal_beta_ = beta; }
183
186 void setPenalty(const Scalar &new_mu) noexcept;
187
189 void setProxParameter(const Scalar &new_rho) noexcept;
190
192 inline void registerCallback(const CallbackPtr &cb) noexcept {
193 callbacks_.push_back(cb);
194 }
195
197 void clearCallbacks() noexcept { callbacks_.clear(); }
198
205 void updateToleranceFailure() noexcept;
206
211 void updateToleranceSuccess() noexcept;
212
213 inline void tolerancePostUpdate() noexcept;
214
216 void acceptMultipliers(Results &results, Workspace &workspace) const;
217
225 void computeMultipliers(const ConstVectorRef &inner_lams_data,
226 Workspace &workspace) const;
227
237 void computeProblemDerivatives(const ConstVectorRef &x, Workspace &workspace,
238 boost::mpl::false_) const;
240 void computeProblemDerivatives(const ConstVectorRef &x, Workspace &workspace,
241 boost::mpl::true_) const;
242
249 void computePrimalResiduals(Workspace &workspace, Results &results) const;
250
258 void tryStep(Workspace &workspace, const Results &results, Scalar alpha);
259
260 void invokeCallbacks(Workspace &workspace, Results &results) {
261 for (auto cb : callbacks_) {
262 cb->call(workspace, results);
263 }
264 }
265};
266
271inline InertiaFlag checkInertia(const int ndx, const int nc,
272 const Eigen::VectorXi &signature);
273
274} // namespace nlp
275} // namespace proxsuite
276
277#include "proxsuite-nlp/prox-solver.hxx"
278
279#ifdef PROXSUITE_NLP_ENABLE_TEMPLATE_INSTANTIATION
280#include "proxsuite-nlp/prox-solver.txx"
281#endif
Scalar target_tol
Target tolerance for the problem.
void setProxParameter(const Scalar &new_rho) noexcept
Set proximal penalty parameter.
void clearCallbacks() noexcept
Remove all callbacks from the instance.
PROXSUITE_NLP_DEPRECATED const Workspace & getWorkspace() const
PROXSUITE_NLP_DEPRECATED const Results & getResults() const
unique_ptr< Results > results_
shared_ptr< helpers::base_callback< Scalar > > CallbackPtr
void setDualPenalty(const Scalar beta)
Set the dual penalty weight for the merit function.
LinesearchStrategy ls_strat
Linesearch strategy.
void computeProblemDerivatives(const ConstVectorRef &x, Workspace &workspace, boost::mpl::false_) const
unique_ptr< Workspace > workspace_
void updateToleranceFailure() noexcept
Update primal-dual subproblem tolerances upon failure (insufficient primal feasibility)
void computePrimalResiduals(Workspace &workspace, Results &results) const
ALMeritFunctionTpl< Scalar > merit_fun
Merit function.
Problem * problem_
General nonlinear program to solve.
void setPenalty(const Scalar &new_mu) noexcept
Set penalty parameter, its inverse and update the merit function.
ConvergenceFlag solve(const ConstVectorRef &x0, const std::vector< VectorRef > &lams0)
Solve the problem.
ProxNLPSolverTpl(Problem &prob, const Scalar tol=1e-6, const Scalar mu_eq_init=1e-2, const Scalar rho_init=0., const VerboseLevel verbose=QUIET, const Scalar mu_lower=1e-9, const Scalar prim_alpha=0.1, const Scalar prim_beta=0.9, const Scalar dual_alpha=1., const Scalar dual_beta=1., LDLTChoice ldlt_blocked=LDLTChoice::BUNCHKAUFMAN, const LinesearchOptions ls_options=LinesearchOptions())
void assembleKktMatrix(Workspace &workspace)
void invokeCallbacks(Workspace &workspace, Results &results)
const Problem & problem() const
ConvergenceFlag solve(const ConstVectorRef &x0, const ConstVectorRef &lams0=VectorXs(0))
Solve the problem.
std::vector< CallbackPtr > callbacks_
Callbacks.
const Manifold & manifold() const
typename Linesearch< Scalar >::Options LinesearchOptions
BCLParamsTpl< Scalar > bcl_params
BCL strategy parameters.
VerboseLevel verbose
Level of verbosity of the solver.
void innerLoop(Workspace &workspace, Results &results)
QuadraticDistanceCostTpl< Scalar > prox_penalty
Proximal regularization penalty.
void updateToleranceSuccess() noexcept
Update primal-dual subproblem tolerances upon successful outer-loop iterate (good primal feasibility)
void registerCallback(const CallbackPtr &cb) noexcept
Add a callback to the solver instance.
PROXSUITE_NLP_INLINE bool iterativeRefinement(Workspace &workspace) const
Iterative refinement of the KKT linear system.
void tryStep(Workspace &workspace, const Results &results, Scalar alpha)
void acceptMultipliers(Results &results, Workspace &workspace) const
Accept Lagrange multiplier estimates.
HessianApprox hess_approx
Use a Gauss-Newton approximation for the Lagrangian Hessian.
MultiplierUpdateMode mul_update_mode
void computeMultipliers(const ConstVectorRef &inner_lams_data, Workspace &workspace) const
std::size_t max_refinement_steps_
linear algebra opts
LinesearchOptions ls_options
Linesearch options.
Forward declarations and configuration macros.
Base structs for linesearch algorithms.
#define PROXSUITE_NLP_INLINE
Definition macros.hpp:28
#define PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
Definition math.hpp:26
Definition fwd.hpp:51
InertiaFlag checkInertia(const int ndx, const int nc, const Eigen::VectorXi &signature)
Check the matrix has the desired inertia.
VerboseLevel
Verbosity level.
Definition fwd.hpp:126
@ GAUSS_NEWTON
Gauss-Newton (or rather SCQP) approximation.
@ EXACT
Exact Hessian construction from provided function Hessians.
@ BUNCHKAUFMAN
Use Bunch-Kaufman factorization.
Main package namespace.
Definition bcl-params.hpp:5
Primal-dual augmented Lagrangian-type merit function.
Definition pdal.hpp:23
A logging utility.
Definition logger.hpp:35
Packs a ConstraintSetTpl and C2FunctionTpl together.
Definition fwd.hpp:112
Base constraint set type.
Definition fwd.hpp:104
polymorphic< Manifold > manifold_
The working manifold .
Weighted quadratic distance on a space.
Results struct, holding the returned data from the solver.
Definition results.hpp:20