alpaqa 0.0.1
Nonconvex constrained optimization
CasADi/Rosenbrock/main.cpp
Go to the documentation of this file.
1/**
2 * @example CasADi/Rosenbrock/main.cpp
3 *
4 * This example shows how to generate a problem using CasADi and how to load
5 * and solve it using alpaqa.
6 *
7 * # Problem generation using CasADi
8 * @include CasADi/Rosenbrock/codegen-rosenbrock.py
9 * # Problem solution using alpaqa
10 */
11
12#include <alpaqa/decl/alm.hpp>
15
17
18#include <iostream>
19
20int main(int argc, char *argv[]) {
21 using alpaqa::inf;
22 using alpaqa::vec;
23
24 auto so_name = "examples/CasADi/Rosenbrock/librosenbrock_functions.so";
25 if (argc > 1)
26 so_name = argv[1];
27
28 // Load the problem (with 3 decision variables and 1 general constraint)
30
31 // Specify the bounds
32 p.C.upperbound = vec::Constant(3, inf);
33 p.C.lowerbound = vec::Constant(3, -inf);
34 p.D.upperbound = vec::Constant(1, 0.);
35 p.D.lowerbound = vec::Constant(1, 0.);
36
37 // Settings for the outer augmented Lagrangian method
39 almparam.ε = 1e-8; // tolerance
40 almparam.δ = 1e-8;
41 almparam.Δ = 10;
42 almparam.max_iter = 20;
43 almparam.print_interval = 1;
44
45 // Settings for the inner PANOC solver
47 panocparam.max_iter = 500;
48 panocparam.print_interval = 10;
49 // Settings for the L-BFGS algorithm used by PANOC
51 lbfgsparam.memory = 10;
52
53 // Create an ALM solver using PANOC as inner solver
55 almparam, // params for outer solver
56 {panocparam, lbfgsparam}, // inner solver
57 };
58
59 // Initial guess
60 vec x(3);
61 x << 2.5, 3.0, 0.75;
62 vec y(1);
63 y << 1;
64
65 // Solve the problem
66 auto stats = solver(p, y, x);
67
68 // Print the results
69 vec g(p.m);
70 p.g(x, g);
71 std::cout << "status: " << stats.status << std::endl;
72 std::cout << "x = " << x.transpose() << std::endl;
73 std::cout << "y = " << y.transpose() << std::endl;
74 std::cout << "g = " << g.transpose() << std::endl;
75 std::cout << "f = " << p.f(x) << std::endl;
76 std::cout << "inner: " << stats.inner.iterations << std::endl;
77 std::cout << "outer: " << stats.outer_iterations << std::endl;
78}
int main(int argc, char *argv[])
Augmented Lagrangian Method solver.
Definition: decl/alm.hpp:82
alpaqa::Problem load_CasADi_problem(const std::string &filename, unsigned n=0, unsigned m=0, bool second_order=false)
Load a problem generated by CasADi (without parameters).
constexpr real_t inf
Definition: vec.hpp:26
realvec vec
Default type for vectors.
Definition: vec.hpp:14
Parameters for the Augmented Lagrangian solver.
Definition: decl/alm.hpp:13
Parameters for the LBFGS and SpecializedLBFGS classes.
Definition: decl/lbfgs.hpp:12
Tuning parameters for the PANOC algorithm.
lbfgsparam
Definition: main.py:38
almparam
Definition: main.py:25
panocparam
Definition: main.py:33
Problem description for minimization problems.