From 09fa5adc55547e0fab42976529a7239747f341fe Mon Sep 17 00:00:00 2001 From: Pieter Pas Date: Fri, 25 Aug 2023 21:00:16 +0200 Subject: [PATCH] Improve ALM loop --- src/alpaqa/include/alpaqa/implementation/outer/alm.tpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/alpaqa/include/alpaqa/implementation/outer/alm.tpp b/src/alpaqa/include/alpaqa/implementation/outer/alm.tpp index 6a9a10591d..d1234b08b6 100644 --- a/src/alpaqa/include/alpaqa/implementation/outer/alm.tpp +++ b/src/alpaqa/include/alpaqa/implementation/outer/alm.tpp @@ -27,7 +27,7 @@ ALMSolver::operator()(const Problem &p, rvec x, rvec y, p.check(); if (params.max_iter == 0) - return {.status=SolverStatus::MaxIter}; + return {.status = SolverStatus::MaxIter}; auto m = p.get_m(); if (m == 0) { // No general constraints, only box constraints @@ -108,10 +108,13 @@ ALMSolver::operator()(const Problem &p, rvec x, rvec y, // Inner solver // ------------ - auto time_elapsed = std::chrono::steady_clock::now() - start_time; + auto time_elapsed = std::chrono::steady_clock::now() - start_time; + auto time_remaining = time_elapsed < params.max_time + ? params.max_time - time_elapsed + : decltype(time_elapsed){0}; InnerSolveOptions opts{ .always_overwrite_results = overwrite_results, - .max_time = params.max_time - time_elapsed, + .max_time = time_remaining, .tolerance = ε, .os = os, .outer_iter = i,