Sleipnir C++ API
Loading...
Searching...
No Matches
fraction_to_the_boundary_rule.hpp
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <Eigen/Core>
6
7// See docs/algorithms.md#Works_cited for citation definitions
8
9namespace slp {
10
19template <typename Scalar>
20Scalar fraction_to_the_boundary_rule(
21 const Eigen::Vector<Scalar, Eigen::Dynamic>& x,
22 const Eigen::Vector<Scalar, Eigen::Dynamic>& p, Scalar τ) {
23 // α = max(α ∈ (0, 1] : x + αp ≥ (1 − τ)x)
24 //
25 // where x and τ are positive.
26 //
27 // x + αp ≥ (1 − τ)x
28 // x + αp ≥ x − τx
29 // αp ≥ −τx
30 //
31 // If the inequality is false, p < 0 and α is too big. Find the largest value
32 // of α that makes the inequality true.
33 //
34 // α = −τ/p x
35 Scalar α(1);
36 for (int i = 0; i < x.rows(); ++i) {
37 if (α * p(i) < -τ * x(i)) {
38 α = -τ / p(i) * x(i);
39 }
40 }
41
42 return α;
43}
44
45} // namespace slp