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
21template <typename Scalar>
22Scalar fraction_to_the_boundary_rule(
23 const Eigen::Ref<const Eigen::Vector<Scalar, Eigen::Dynamic>>& x,
24 const Eigen::Ref<const Eigen::Vector<Scalar, Eigen::Dynamic>>& p,
25 Scalar τ) {
26 // α = max(α ∈ (0, 1] : x + αp ≥ (1 − τ)x)
27 //
28 // where x and τ are positive.
29 //
30 // x + αp ≥ (1 − τ)x
31 // x + αp ≥ x − τx
32 // αp ≥ −τx
33 //
34 // If the inequality is false, p < 0 and α is too big. Find the largest value
35 // of α that makes the inequality true.
36 //
37 // α = −τ/p x
38 Scalar α(1);
39 for (int i = 0; i < x.rows(); ++i) {
40 if (α * p(i) < -τ * x(i)) {
41 α = -τ / p(i) * x(i);
42 }
43 }
44
45 return α;
46}
47
48} // namespace slp