PANOC-ALM  quadratic-penalty
Nonconvex constrained optimization
box.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "vec.hpp"
4 
5 namespace pa {
6 
7 struct Box {
10 };
11 
14 template <class Vec>
15 inline auto project(const Vec &v,
16  const Box &box
17 ) {
18  using binary_real_f = real_t (*)(real_t, real_t);
19  return v.binaryExpr(box.lowerbound, binary_real_f(std::fmax))
20  .binaryExpr(box.upperbound, binary_real_f(std::fmin));
21 }
22 
26 template <class Vec>
27 inline auto
29  const Box &box
30 ) {
31  return v - project(v, box);
32 }
33 
38  const Box &box
39 ) {
40  return projecting_difference(v, box).squaredNorm();
41 }
42 
49  const Box &box,
50  crvec Σ
51 ) {
52  // TODO: Does this allocate?
53  // Does it have dangling references to temporaries?
54  auto d = v - project(v, box);
55  return d.dot(Σ.asDiagonal() * d);
56 }
57 
58 } // namespace pa
pa::vec
realvec vec
Default type for vectors.
Definition: vec.hpp:14
pa::project
auto project(const Vec &v, const Box &box)
Project a vector onto a box.
Definition: box.hpp:15
panocpy.test.v
v
Definition: test.py:42
pa
Definition: alm.hpp:10
pa::Box::lowerbound
vec lowerbound
Definition: box.hpp:9
pa::Box
Definition: box.hpp:7
pa::crvec
Eigen::Ref< const vec > crvec
Default type for immutable references to vectors.
Definition: vec.hpp:18
panocpy.test.Σ
int Σ
Definition: test.py:70
pa::Box::upperbound
vec upperbound
Definition: box.hpp:8
pa::projecting_difference
auto projecting_difference(const Vec &v, const Box &box)
Get the difference between the given vector and its projection.
Definition: box.hpp:28
vec.hpp
pa::dist_squared
real_t dist_squared(crvec v, const Box &box)
Get the distance squared between the given vector and its projection.
Definition: box.hpp:37
pa::real_t
double real_t
Default floating point type.
Definition: vec.hpp:8