9void alpaqa_setulb_c(
int n,
int m,
double *x,
const double *l,
const double *u,
10 const int *nbd,
double &f,
double *g,
double factr,
11 double pgtol,
double *wa,
int *iwa,
char *task,
int iprint,
12 char *csave,
bool *lsave,
int *isave,
double *dsave);
35 using std::chrono::nanoseconds;
36 using clock = std::chrono::steady_clock;
38 auto *os =
opts.os ?
opts.os : this->os;
39 auto max_time = params.max_time;
41 max_time = std::min(max_time, *
opts.max_time);
44 if (!problem.provides_get_box_C())
45 throw std::invalid_argument(
"LBFGSBSolver requires box constraints");
47 throw std::invalid_argument(
"LBFGSBSolver only supports "
48 "PANOCStopCrit::ProjGradUnitNorm");
50 const auto n = problem.get_n();
51 const auto m_constr = problem.get_m();
52 const auto &C = problem.get_box_C();
53 const auto mem =
static_cast<length_t>(params.memory);
74 .outer_iter =
opts.outer_iter,
80 using intvec = Eigen::VectorX<int>;
88 std::array<bool, 4>
lsave{};
93 for (
index_t i = 0; i < n; ++i) {
105 int print = params.print;
117 auto set_task = [&](std::string_view s) {
118 std::fill(std::copy(s.begin(), s.end(),
task.begin()),
task.end(),
' ');
131 *os <<
"┌─[LBFGSB]\n";
133 *os <<
"├─ " << std::setw(6) << k <<
" ──\n";
140 const auto thres = std::sqrt(std::numeric_limits<real_t>::epsilon());
147 <<
", #J = " << std::setw(6) << nJ
151 *os <<
"└─ " << status <<
" ──"
162 x_solve.data(), C.lowerbound.data(),
163 C.upperbound.data(),
nbd.data(), ψ, grad_ψ.data(),
168 if (
task_sv.starts_with(
"FG")) {
169 ψ = problem.eval_ψ_grad_ψ(
x_solve, y, Σ, grad_ψ, work_n, work_m);
173 "CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL")) {
178 else if (
task_sv.starts_with(
"NEW_X")) {
182 set_task(
"STOP: projected gradient norm");
184 }
else if (clock::now() -
start_time >= max_time) {
188 }
else if (
static_cast<unsigned>(
num_iter) >= params.max_iter) {
190 set_task(
"STOP: number iterations");
192 }
else if (stop_signal.stop_requested()) {
197 auto k =
static_cast<unsigned>(
num_iter) - 1;
198 bool do_print = params.print_interval != 0 &&
199 k % params.print_interval == 0;
211 else if (
task_sv.starts_with(
"CONVERGENCE: REL_REDUCTION_OF_F")) {
223 auto k =
static_cast<unsigned>(
num_iter) - 1;
226 else if (params.print_interval != 0)
235 *os <<
"│ \033[0;31mLBFGSB failure\033[0m: '\033[0;33m" <<
task_trimmed
236 <<
"\033[0m'" << std::endl;
238 if (params.print_interval != 0)
254 opts.always_overwrite_results) {
257 if (
err_z.size() > 0)
258 err_z = (ŷ - y).cwiseQuotient(Σ);
std::string get_name() const
Stats operator()(const Problem &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec err_z)
void alpaqa_setulb_c(int n, int m, double *x, const double *l, const double *u, const int *nbd, double &f, double *g, double factr, double pgtol, double *wa, int *iwa, char *task, int iprint, char *csave, bool *lsave, int *isave, double *dsave)
std::chrono::nanoseconds time_progress_callback
std::chrono::nanoseconds elapsed_time
@ ProjGradUnitNorm
∞-norm of the projected gradient with unit step size:
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Interrupted
Solver was interrupted by the user.
@ MaxTime
Maximum allowed execution time exceeded.
@ Exception
An unexpected exception was thrown.
@ NoProgress
No progress was made in the last iteration.
@ MaxIter
Maximum number of iterations exceeded.
@ Converged
Converged and reached given tolerance.
typename Conf::real_t real_t
typename Conf::index_t index_t
typename Conf::length_t length_t
std::string_view float_to_str_vw(auto &buf, double value, int precision=std::numeric_limits< double >::max_digits10)
typename Conf::crvec crvec