23 Problem() : A(nx, nx), B(nx, nu) {
29 [[nodiscard]] length_t get_N()
const {
return N; }
31 [[nodiscard]] length_t get_nu()
const {
return nu; }
33 [[nodiscard]] length_t get_nx()
const {
return nx; }
35 [[nodiscard]] length_t get_nh()
const {
return nh; }
37 [[nodiscard]] length_t get_nh_N()
const {
return nh_N; }
39 [[nodiscard]] length_t get_nc()
const {
return nc; }
41 [[nodiscard]] length_t get_nc_N()
const {
return nc_N; }
44 void get_U(Box &U)
const {
45 U.lowerbound.setConstant(-1);
46 U.upperbound.setConstant(+1);
49 void get_D([[maybe_unused]] Box &D)
const {}
51 void get_D_N([[maybe_unused]] Box &D)
const {}
54 void get_x_init(rvec x_init)
const { x_init.setConstant(10.); }
57 void eval_f([[maybe_unused]] index_t timestep, crvec x, crvec u,
59 fxu.noalias() = A * x + B * u;
62 void eval_jac_f([[maybe_unused]] index_t timestep, [[maybe_unused]] crvec x,
63 [[maybe_unused]] crvec u, rmat J_fxu)
const {
64 J_fxu.leftCols(nx).noalias() = A;
65 J_fxu.rightCols(nu).noalias() = B;
68 void eval_grad_f_prod([[maybe_unused]] index_t timestep,
69 [[maybe_unused]] crvec x, [[maybe_unused]] crvec u,
70 crvec p, rvec grad_fxu_p)
const {
71 grad_fxu_p.topRows(nx).noalias() = A.transpose() * p;
72 grad_fxu_p.bottomRows(nu).noalias() = B.transpose() * p;
75 void eval_h([[maybe_unused]] index_t timestep, crvec x, crvec u,
81 void eval_h_N(crvec x, rvec h)
const { h = x; }
83 [[nodiscard]] real_t eval_l([[maybe_unused]] index_t timestep,
85 return 0.5 * h.squaredNorm();
88 [[nodiscard]] real_t eval_l_N(crvec h)
const {
89 return 5.0 * h.squaredNorm();
92 void eval_qr([[maybe_unused]] index_t timestep, [[maybe_unused]] crvec xu,
93 crvec h, rvec qr)
const {
94 auto Jh_xu = mat::Identity(nx + nu, nx + nu);
96 qr = Jh_xu.transpose() * grad_l;
99 void eval_q_N([[maybe_unused]] crvec x, crvec h, rvec q)
const {
100 auto Jh_x = mat::Identity(nx, nx);
101 auto &&grad_l = 10 * h;
102 q = Jh_x.transpose() * grad_l;
105 void eval_add_Q([[maybe_unused]] index_t timestep,
106 [[maybe_unused]] crvec xu, [[maybe_unused]] crvec h,
108 Q += mat::Identity(nx, nx);
111 void eval_add_Q_N([[maybe_unused]] crvec x, [[maybe_unused]] crvec h,
113 Q += 10 * mat::Identity(nx, nx);
116 void eval_add_R_masked([[maybe_unused]] index_t timestep,
117 [[maybe_unused]] crvec xu, [[maybe_unused]] crvec h,
118 crindexvec mask, rmat R,
119 [[maybe_unused]] rvec work)
const {
120 auto R_full = mat::Identity(nu, nu);
121 R.noalias() += R_full(mask, mask);
124 void eval_add_S_masked([[maybe_unused]] index_t timestep,
125 [[maybe_unused]] crvec xu, [[maybe_unused]] crvec h,
126 crindexvec mask, rmat S,
127 [[maybe_unused]] rvec work)
const {
129 using Eigen::indexing::all;
130 auto S_full = mat::Zero(nu, nx);
131 S += S_full(mask, all);
134 void eval_add_R_prod_masked([[maybe_unused]] index_t timestep,
135 [[maybe_unused]] crvec xu,
136 [[maybe_unused]] crvec h, crindexvec mask_J,
137 crindexvec mask_K, crvec v, rvec out,
138 [[maybe_unused]] rvec work)
const {
140 auto R_full = mat::Identity(nu, nu);
141 out.noalias() += R_full(mask_J, mask_K) * v(mask_K);
144 void eval_add_S_prod_masked([[maybe_unused]] index_t timestep,
145 [[maybe_unused]] crvec xu,
146 [[maybe_unused]] crvec h,
147 [[maybe_unused]] crindexvec mask_K,
148 [[maybe_unused]] crvec v,
149 [[maybe_unused]] rvec out,
150 [[maybe_unused]] rvec work)
const {
152 using Eigen::indexing::all;
153 auto Sᵀ = mat::Zero(nx, nu);
154 out.noalias() += Sᵀ(all, mask_K) * v(mask_K);
156 [[nodiscard]] length_t get_R_work_size()
const {
161 [[nodiscard]] length_t get_S_work_size()
const {
168 void eval_proj_multipliers([[maybe_unused]] rvec y,
169 [[maybe_unused]] real_t M)
const {
174 void eval_proj_diff_g([[maybe_unused]] crvec z,
175 [[maybe_unused]] rvec e)
const {
195 vec u = vec::Zero(n);
196 vec y = vec::Zero(m);
197 vec μ = vec::Ones(m);
208 auto stats = solver(problem, {.tolerance = 1e-8}, u, y, μ, e);
211 auto δ = e.lpNorm<Eigen::Infinity>();
212 auto time_s = std::chrono::duration<double>(stats.elapsed_time).count();
215 <<
"solver: " << solver.get_name() <<
'\n'
216 <<
"status: " << stats.status <<
'\n'
221 <<
"iter: " << std::setw(6) << stats.iterations <<
'\n'
222 <<
"line search backtrack: " << std::setw(6)
223 << stats.linesearch_backtracks <<
'\n'
224 <<
"step size backtrack: " << std::setw(6)
225 << stats.stepsize_backtracks <<
'\n'
int main(int argc, const char *argv[])
#define USING_ALPAQA_CONFIG(Conf)
unsigned print_interval
When to print progress.
unsigned gn_interval
How often to use a Gauss-Newton step. Zero to disable GN entirely.
PANOCStopCrit stop_crit
What stopping criterion to use.
Tuning parameters for the PANOC algorithm.
@ ProjGradUnitNorm
∞-norm of the projected gradient with unit step size:
std::ostream & print_python(std::ostream &os, const Eigen::DenseBase< Derived > &M, Args &&...args)
std::string float_to_str(F value, int precision)
length_t get_nc_N() const
std::shared_ptr< OCPEvalCounter > evaluations
Double-precision double configuration.