alpaqa 0.0.1
Nonconvex constrained optimization
himmelblau.cpp
Go to the documentation of this file.
1#include <memory>
3
4namespace alpaqa {
5namespace problems {
6
8 auto sq = [](auto x) { return x * x; };
9 Box C{vec(2), vec(2)};
10 C.lowerbound << -1, -1;
11 C.upperbound << 4, 1.8;
12 return Problem{
13 2,
14 0,
15 C,
16 Box{},
17 [sq](crvec x) {
18 return sq(sq(x(0)) + x(1) - 11) + sq(x(0) + sq(x(1)) - 7);
19 },
20 [sq](crvec x, rvec g) {
21 g(0) =
22 2 * (2 * x(0) * (sq(x(0)) + x(1) - 11) + x(0) + sq(x(1)) - 7);
23 g(1) =
24 2 * (sq(x(0)) + 2 * x(1) * (x(0) + sq(x(1)) - 7) + x(1) - 11);
25 },
26 [](crvec , rvec ) {},
27 [](crvec , crvec , rvec grad) { grad.setZero(); },
28 [](crvec , unsigned, rvec grad_gi) { grad_gi.setZero(); },
29 [sq](crvec x, crvec , crvec v, rvec Hv) {
30 real_t H00 = 4 * (sq(x(0)) + x(1) - 11) + 8 * sq(x(0)) + 2;
31 real_t H01 = 4 * x(0) + 4 * x(1);
32 real_t H10 = 4 * x(0) + 4 * x(1);
33 real_t H11 = 4 * (x(0) + sq(x(1)) - 7) + 8 * sq(x(1)) + 2;
34 Hv(0) = H00 * v(0) + H01 * v(1);
35 Hv(1) = H10 * v(0) + H11 * v(1);
36 },
37 [sq](crvec x, crvec , rmat H) {
38 H(0, 0) = 4 * (sq(x(0)) + x(1) - 11) + 8 * sq(x(0)) + 2;
39 H(0, 1) = 4 * x(0) + 4 * x(1);
40 H(1, 0) = 4 * x(0) + 4 * x(1);
41 H(1, 1) = 4 * (x(0) + sq(x(1)) - 7) + 8 * sq(x(1)) + 2;
42 },
43 };
44}
45
46} // namespace problems
47} // namespace alpaqa
Problem himmelblau_problem()
Definition: himmelblau.cpp:7
Eigen::Ref< const vec > crvec
Default type for immutable references to vectors.
Definition: vec.hpp:18
realvec vec
Default type for vectors.
Definition: vec.hpp:14
Eigen::Ref< mat > rmat
Default type for mutable references to matrices.
Definition: vec.hpp:22
double real_t
Default floating point type.
Definition: vec.hpp:8
Eigen::Ref< vec > rvec
Default type for mutable references to vectors.
Definition: vec.hpp:16
H
Definition: main.py:8
Problem description for minimization problems.