11using std::chrono::duration_cast;
12using std::chrono::microseconds;
14template <
class InnerSolverT>
15typename ALMSolver<InnerSolverT>::Stats
17 auto start_time = std::chrono::steady_clock::now();
19 constexpr auto sigNaN = std::numeric_limits<real_t>::signaling_NaN();
33 if (
params.preconditioning)
50 bool first_successful_iter =
true;
52 for (
unsigned int i = 0; i <
params.max_iter; ++i) {
57 bool out_of_penalty_factor_updates =
58 (first_successful_iter
62 params.max_total_num_retries);
63 bool out_of_iter = i + 1 ==
params.max_iter;
67 bool overwrite_results = out_of_iter || out_of_penalty_factor_updates;
80 auto time_elapsed = std::chrono::steady_clock::now() - start_time;
81 bool out_of_time = time_elapsed >
params.max_time;
83 not inner_converged && not overwrite_results && not out_of_time;
86 if (
params.print_interval != 0 && i %
params.print_interval == 0) {
88 auto color = inner_converged ?
"\x1b[0;32m" :
"\x1b[0;31m";
89 auto color_end =
"\x1b[0m";
90 std::cout <<
"[\x1b[0;34mALM\x1b[0m] " << std::setw(5) << i
91 <<
": ‖Σ‖ = " << std::setw(13) <<
Σ.norm()
92 <<
", ‖y‖ = " << std::setw(13) <<
y.norm()
93 <<
", δ = " << std::setw(13) << δ
94 <<
", ε = " << std::setw(13) << ps.ε
95 <<
", Δ = " << std::setw(13) << Δ
96 <<
", status = " << color << std::setw(13) << ps.status
97 << color_end <<
", iter = " << std::setw(13)
98 << ps.iterations <<
"\r\n";
107 s.
elapsed_time = duration_cast<microseconds>(time_elapsed);
109 if (
params.preconditioning)
110 y = prec_g.asDiagonal() *
y / prec_f;
126 if (not first_successful_iter) {
129 Δ = std::fmax(1., Δ *
params.Δ_lower);
131 error₁, error₂, norm_e₁, norm_e₂,
134 ρ = std::fmin(0.5, ρ *
params.ρ_increase);
135 ε = std::fmax(ρ * ε_old,
params.ε);
156 ps.ε <=
params.ε && inner_converged && norm_e₁ <=
params.δ;
157 bool exit = alm_converged || out_of_iter || out_of_time;
163 s.
elapsed_time = duration_cast<microseconds>(time_elapsed);
168 if (
params.preconditioning)
169 y = prec_g.asDiagonal() *
y / prec_f;
177 error₁, error₂, norm_e₁, norm_e₂,
180 ε_old = std::exchange(
ε, std::fmax(ρ *
ε,
params.ε));
181 first_successful_iter =
false;
184 throw std::logic_error(
"[ALM] loop error");
unsigned penalty_reduced
The number of times that the penalty update factor ALMParams::Δ was reduced, that the tolerance updat...
real_t δ
Final dual tolerance or constraint violation that was reached:
Stats operator()(const Problem &problem, rvec y, rvec x)
real_t norm_penalty
2-norm of the final penalty factors .
unsigned initial_penalty_reduced
The number of times that the initial penalty factor was reduced by ALMParams::Σ₀_lower and that the i...
InnerStatsAccumulator< typename InnerSolver::Stats > inner
The statistics of the inner solver invocations, accumulated over all ALM iterations.
unsigned inner_convergence_failures
The total number of times that the inner solver failed to converge.
real_t ε
Final primal tolerance that was reached, depends on the stopping criterion used by the inner solver,...
unsigned outer_iterations
Total number of outer ALM iterations (i.e.
std::chrono::microseconds elapsed_time
Total elapsed time.
SolverStatus status
Whether the solver converged or not.
void project_y(rvec y, crvec z_lb, crvec z_ub, real_t M)
void update_penalty_weights(const ALMParams ¶ms, real_t Δ, bool first_iter, rvec e, rvec old_e, real_t norm_e, real_t old_norm_e, crvec Σ_old, rvec Σ)
void initialize_penalty(const Problem &p, const ALMParams ¶ms, crvec x0, rvec Σ)
void apply_preconditioning(const Problem &problem, Problem &prec_problem, crvec x, real_t &prec_f, vec &prec_g)
real_t norm_inf(const Vec &v)
Get the maximum or infinity-norm of the given vector.
constexpr real_t NaN
Not a number.
@ Interrupted
Solver was interrupted by the user.
@ MaxTime
Maximum allowed execution time exceeded.
@ MaxIter
Maximum number of iterations exceeded.
@ Converged
Converged and reached given tolerance.
realvec vec
Default type for vectors.
double real_t
Default floating point type.
Eigen::Ref< vec > rvec
Default type for mutable references to vectors.
Problem description for minimization problems.