8 const std::vector<std::shared_ptr<AugmentedLagrangianForm>> &alagr_form,
9 const double initial_al_weight,
11 const double max_al_weight,
13 const std::function<
void(
const Eigen::VectorXd &)> &update_barrier_stiffness)
14 : alagr_forms{alagr_form},
15 initial_al_weight(initial_al_weight),
17 max_al_weight(max_al_weight),
19 update_barrier_stiffness(update_barrier_stiffness)
25 assert(sol.size() == nl_problem.
full_size());
27 const Eigen::VectorXd initial_sol = sol;
35 const int iters = nl_solver->stop_criteria().iterations;
37 double initial_error = 0;
39 initial_error += f->compute_error(sol);
44 f->set_initial_weight(al_weight);
46 while (!std::isfinite(nl_problem.
value(tmp_sol))
53 logger().debug(
"Solving AL Problem with weight {}", al_weight);
61 nl_solver->minimize(nl_problem, tmp_sol);
64 catch (
const std::runtime_error &e)
66 std::string err_msg = e.what();
68 if (err_msg.find(
"f(x) is nan or inf; stopping") != std::string::npos)
75 double current_error = 0;
77 f->compute_error(sol);
78 const double eta = 1 - sqrt(current_error / initial_error);
80 logger().debug(
"Current eta = {}", eta);
84 logger().debug(
"Higher error than initial, increase weight and revert to previous solution");
96 f->update_lagrangian(sol, al_weight);
103 nl_solver->stop_criteria().iterations = iters;
108 assert(sol.size() == nl_problem.
full_size());
113 if (!std::isfinite(nl_problem.
value(tmp_sol))
116 log_and_throw_error(
"Failed to apply constraints conditions; solve with augmented lagrangian first!");
121 logger().debug(
"Successfully applied constraints conditions; solving in reduced space");
123 nl_problem.
init(sol);
127 nl_solver->minimize(nl_problem, tmp_sol);
130 catch (
const std::runtime_error &e)
const double max_al_weight
std::vector< std::shared_ptr< AugmentedLagrangianForm > > alagr_forms
void set_al_weight(NLProblem &nl_problem, const Eigen::VectorXd &x, const double weight)
std::function< void(const Eigen::VectorXd &)> update_barrier_stiffness
ALSolver(const std::vector< std::shared_ptr< AugmentedLagrangianForm > > &alagr_form, const double initial_al_weight, const double scaling, const double max_al_weight, const double eta_tol, const std::function< void(const Eigen::VectorXd &)> &update_barrier_stiffness)
std::function< void(const double)> post_subsolve
const double initial_al_weight
void solve_reduced(std::shared_ptr< NLSolver > nl_solver, NLProblem &nl_problem, Eigen::MatrixXd &sol)
void solve_al(std::shared_ptr< NLSolver > nl_solver, NLProblem &nl_problem, Eigen::MatrixXd &sol)
virtual void line_search_end() override
virtual void init(const TVector &x0) override
void line_search_begin(const TVector &x0, const TVector &x1) override
virtual bool is_step_valid(const TVector &x0, const TVector &x1) override
virtual TVector full_to_reduced(const TVector &full) const
virtual bool is_step_collision_free(const TVector &x0, const TVector &x1) override
virtual TVector reduced_to_full(const TVector &reduced) const
virtual double value(const TVector &x) override
spdlog::logger & logger()
Retrieves the current logger.
void log_and_throw_error(const std::string &msg)