alpaqa
0.0.1
Nonconvex constrained optimization
examples
CasADi
Rosenbrock
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
>
13
#include <
alpaqa/inner/decl/panoc.hpp
>
14
#include <
alpaqa/inner/directions/decl/lbfgs.hpp
>
15
16
#include <
alpaqa/interop/casadi/CasADiLoader.hpp
>
17
18
#include <iostream>
19
20
int
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)
29
alpaqa::Problem
p
=
alpaqa::load_CasADi_problem
(so_name, 3, 1);
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
38
alpaqa::ALMParams
almparam
;
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
46
alpaqa::PANOCParams
panocparam
;
47
panocparam
.max_iter = 500;
48
panocparam
.print_interval = 10;
49
// Settings for the L-BFGS algorithm used by PANOC
50
alpaqa::LBFGSParams
lbfgsparam
;
51
lbfgsparam
.memory = 10;
52
53
// Create an ALM solver using PANOC as inner solver
54
alpaqa::ALMSolver<alpaqa::PANOCSolver<>
>
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
}
CasADiLoader.hpp
main
int main(int argc, char *argv[])
Definition:
CasADi/Rosenbrock/main.cpp:20
alpaqa::ALMSolver
Augmented Lagrangian Method solver.
Definition:
decl/alm.hpp:82
alm.hpp
lbfgs.hpp
alpaqa::load_CasADi_problem
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).
Definition:
CasADiLoader.cpp:88
panoc.hpp
alpaqa::inf
constexpr real_t inf
Definition:
vec.hpp:26
alpaqa::vec
realvec vec
Default type for vectors.
Definition:
vec.hpp:14
alpaqa::ALMParams
Parameters for the Augmented Lagrangian solver.
Definition:
decl/alm.hpp:13
alpaqa::LBFGSParams
Parameters for the LBFGS and SpecializedLBFGS classes.
Definition:
decl/lbfgs.hpp:12
alpaqa::PANOCParams
Tuning parameters for the PANOC algorithm.
Definition:
inner/decl/panoc.hpp:20
bicycle-obstacle-avoidance-mpc.solver
solver
Definition:
bicycle-obstacle-avoidance-mpc.py:78
bicycle-obstacle-avoidance-mpc.stats
stats
Definition:
bicycle-obstacle-avoidance-mpc.py:103
codegen-rosenbrock.y
y
Definition:
codegen-rosenbrock.py:9
codegen-rosenbrock.g
int g
Definition:
codegen-rosenbrock.py:17
codegen-rosenbrock.x
x
Definition:
codegen-rosenbrock.py:8
getting-started.p
p
Definition:
getting-started.py:11
main.lbfgsparam
lbfgsparam
Definition:
main.py:38
main.almparam
almparam
Definition:
main.py:25
main.panocparam
panocparam
Definition:
main.py:33
alpaqa::Problem
Problem description for minimization problems.
Definition:
include/alpaqa/util/problem.hpp:26
Generated by
1.9.2