PANOC-ALM  quadratic-penalty
Nonconvex constrained optimization
Presentation/Cpp/main.cpp
Go to the documentation of this file.
1 #include <panoc-alm/alm.hpp>
4 
5 #include <iostream>
6 
7 int main() {
8  using pa::vec;
9  using pa::rvec;
10  using pa::crvec;
11  using pa::mat;
12  using pa::inf;
13 
14  // Problem specification
15  pa::Problem problem(2, 1); // # decision variables, # constraints
16 
17  // minimize ½ xᵀHx
18  // s.t. Ax ≤ b
19  mat H(2, 2); H << 3, -1,
20  -1, 3;
21  mat A(1, 2); A << 2, 1;
22  vec b(1); b << -1;
23 
24  problem.f = [&](crvec x) { return 0.5 * x.dot(H * x); };
25  problem.grad_f = [&](crvec x, rvec gr) { gr = H * x; };
26  problem.g = [&](crvec x, rvec g) { g = A * x; };
27  problem.grad_g_prod = [&](crvec x, crvec y, rvec gr) { gr = A.transpose() * y; };
28 
29  // Specify the bounds
30  problem.C.lowerbound = vec::Constant(problem.n, -inf);
31  problem.C.upperbound = vec::Constant(problem.n, inf);
32  problem.D.lowerbound = vec::Constant(problem.m, -inf);
33  problem.D.upperbound = b;
34 
35  // Settings for the outer augmented Lagrangian method
37  almparam.ε = 1e-8; // tolerance
38  almparam.δ = 1e-8;
39  almparam.Δ = 10; // penalty update factor
40  almparam.max_iter = 20;
41  almparam.print_interval = 1;
42 
43  // Settings for the inner PANOC solver
45  panocparam.max_iter = 500;
46  panocparam.print_interval = 10;
47  // Settings for the L-BFGS algorithm used by PANOC
49  lbfgsparam.memory = 2;
50 
51  // Create an ALM solver using PANOC as inner solver
53  almparam, // params for outer solver
54  {panocparam, lbfgsparam}, // inner solver
55  };
56 
57  // Initial guess
58  vec x(2); x << 2, 2; // decision variables
59  vec y(1); y << 1; // Lagrange multipliers
60 
61  // Solve the problem
62  auto stats = solver(problem, y, x);
63  // y and x have been overwritten by the solution
64 
65  // Print the results
66  std::cout << "status: " << stats.status << std::endl;
67  std::cout << "inner iterations: " << stats.inner.iterations << std::endl;
68  std::cout << "outer iterations: " << stats.outer_iterations << std::endl;
69  std::cout << "elapsed time: " << stats.elapsed_time.count() * 1e-6 << 's' << std::endl;
70  std::cout << "x = " << x.transpose() << std::endl;
71  std::cout << "y = " << y.transpose() << std::endl;
72  std::cout << "f = " << problem.f(x) << std::endl;
73 }
panocpy.test.stats
stats
Definition: test.py:76
pa::rvec
Eigen::Ref< vec > rvec
Default type for mutable references to vectors.
Definition: vec.hpp:16
lbfgs.hpp
panoc.hpp
panocpy.test.y
y
Definition: test.py:76
main.panocparam
panocparam
Definition: main.py:33
pa::vec
realvec vec
Default type for vectors.
Definition: vec.hpp:14
main.lbfgsparam
lbfgsparam
Definition: main.py:38
main.problem
problem
Definition: main.py:16
pa::ALMSolver
Augmented Lagrangian Method solver.
Definition: decl/alm.hpp:82
pa::PANOCParams
Tuning parameters for the PANOC algorithm.
Definition: inner/decl/panoc.hpp:20
panocpy.test.x
x
Definition: test.py:40
alm.hpp
main
int main()
Definition: Presentation/Cpp/main.cpp:7
pa::ALMParams
Parameters for the Augmented Lagrangian solver.
Definition: decl/alm.hpp:13
pa::inf
constexpr real_t inf
Definition: vec.hpp:26
main.almparam
almparam
Definition: main.py:25
pa::crvec
Eigen::Ref< const vec > crvec
Default type for immutable references to vectors.
Definition: vec.hpp:18
pa::LBFGSParams
Parameters for the LBFGS and SpecializedLBFGS classes.
Definition: decl/lbfgs.hpp:12
main.b
b
Definition: main.py:11
panocpy.test.solver
solver
Definition: test.py:8
pa::mat
realmat mat
Default type for matrices.
Definition: vec.hpp:20
panocpy.test.g
g
Definition: test.py:51
main.A
A
Definition: main.py:10
pa::Problem
Problem description for minimization problems.
Definition: include/panoc-alm/util/problem.hpp:24
main.H
H
Definition: main.py:8