Sleipnir C++ API
Loading...
Searching...
No Matches
step.hpp
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <algorithm>
6#include <limits>
7
8#include <Eigen/Core>
9
10namespace slp {
11
15template <typename Scalar>
16struct NewtonStep {
18 using DenseVector = Eigen::VectorX<Scalar>;
19
22
26 Scalar primal_inf_norm() const {
27 return p_x.template lpNorm<Eigen::Infinity>();
28 }
29
36 Scalar tiny_step_size(const DenseVector& x) const {
37 // A primal step αpˣ is negligible if
38 //
39 // ‖αpˣ/(1 + |x|)‖_∞ < 10ε
40 //
41 // where the absolute value and division are elementwise. Since α > 0, it
42 // factors out of the norm.
43 //
44 // α‖pˣ/(1 + |x|)‖_∞ < 10ε
45 //
46 // Dividing both sides by the norm gives
47 //
48 // α < 10ε / ‖pˣ/(1 + |x|)‖_∞
49 return Scalar(10) * std::numeric_limits<Scalar>::epsilon() /
50 (p_x.array().abs() / (Scalar(1) + x.array().abs()))
51 .matrix()
52 .template lpNorm<Eigen::Infinity>();
53 }
54};
55
59template <typename Scalar>
60struct SQPStep {
62 using DenseVector = Eigen::VectorX<Scalar>;
63
68
72 Scalar primal_inf_norm() const {
73 return p_x.template lpNorm<Eigen::Infinity>();
74 }
75
79 Scalar dual_inf_norm() const {
80 return p_y.template lpNorm<Eigen::Infinity>();
81 }
82
89 Scalar tiny_step_size(const DenseVector& x) const {
90 // A primal step αpˣ is negligible if
91 //
92 // ‖αpˣ/(1 + |x|)‖_∞ < 10ε
93 //
94 // where the absolute value and division are elementwise. Since α > 0, it
95 // factors out of the norm.
96 //
97 // α‖pˣ/(1 + |x|)‖_∞ < 10ε
98 //
99 // Dividing both sides by the norm gives
100 //
101 // α < 10ε / ‖pˣ/(1 + |x|)‖_∞
102 return Scalar(10) * std::numeric_limits<Scalar>::epsilon() /
103 (p_x.array().abs() / (Scalar(1) + x.array().abs()))
104 .matrix()
105 .template lpNorm<Eigen::Infinity>();
106 }
107};
108
112template <typename Scalar>
113struct IPMStep {
115 using DenseVector = Eigen::VectorX<Scalar>;
116
125
129 Scalar primal_inf_norm() const {
130 return std::max(p_x.template lpNorm<Eigen::Infinity>(),
131 p_s.template lpNorm<Eigen::Infinity>());
132 }
133
137 Scalar dual_inf_norm() const {
138 return std::max(p_y.template lpNorm<Eigen::Infinity>(),
139 p_z.template lpNorm<Eigen::Infinity>());
140 }
141
149 Scalar tiny_step_size(const DenseVector& x, const DenseVector& s) const {
150 // A primal step α[pˣ pˢ] is negligible if
151 //
152 // max(‖αpˣ/(1 + |x|)‖_∞, ‖αpˢ/(1 + |s|)‖_∞) < 10ε
153 //
154 // where the absolute values and division are elementwise. Since α > 0, it
155 // factors out of the norms and max.
156 //
157 // α max(‖pˣ/(1 + |x|)‖_∞, ‖pˢ/(1 + |s|)‖_∞) < 10ε
158 //
159 // Dividing both sides by the max gives
160 //
161 // α < 10ε / max(‖pˣ/(1 + |x|)‖_∞, ‖pˢ/(1 + |s|)‖_∞)
162 return Scalar(10) * std::numeric_limits<Scalar>::epsilon() /
163 std::max((p_x.array().abs() / (Scalar(1) + x.array().abs()))
164 .matrix()
165 .template lpNorm<Eigen::Infinity>(),
166 (p_s.array().abs() / (Scalar(1) + s.array().abs()))
167 .matrix()
168 .template lpNorm<Eigen::Infinity>());
169 }
170};
171
172} // namespace slp
Definition intrusive_shared_ptr.hpp:27
Definition step.hpp:113
Scalar primal_inf_norm() const
Definition step.hpp:129
Scalar tiny_step_size(const DenseVector &x, const DenseVector &s) const
Definition step.hpp:149
DenseVector p_x
Decision variable primal step.
Definition step.hpp:118
Scalar dual_inf_norm() const
Definition step.hpp:137
DenseVector p_z
Inequality constraint dual step.
Definition step.hpp:124
DenseVector p_s
Inequality constraint slack variable primal step.
Definition step.hpp:120
Eigen::VectorX< Scalar > DenseVector
Type alias for dense vector.
Definition step.hpp:115
DenseVector p_y
Equality constraint dual step.
Definition step.hpp:122
Definition step.hpp:16
Scalar tiny_step_size(const DenseVector &x) const
Definition step.hpp:36
Scalar primal_inf_norm() const
Definition step.hpp:26
Eigen::VectorX< Scalar > DenseVector
Type alias for dense vector.
Definition step.hpp:18
DenseVector p_x
Decision variable primal step.
Definition step.hpp:21
Definition step.hpp:60
DenseVector p_x
Decision variable primal step.
Definition step.hpp:65
DenseVector p_y
Equality constraint dual step.
Definition step.hpp:67
Scalar tiny_step_size(const DenseVector &x) const
Definition step.hpp:89
Scalar primal_inf_norm() const
Definition step.hpp:72
Scalar dual_inf_norm() const
Definition step.hpp:79
Eigen::VectorX< Scalar > DenseVector
Type alias for dense vector.
Definition step.hpp:62