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 // The fraction-to-the-boundary rule is defined as:
24 //
25 // α = max(α ∈ (0, 1] : x + αp ≥ (1 − τ)x) (1)
26 //
27 // where x and τ are positive. Rearranging the inequality in (1) gives
28 //
29 // x + αp ≥ (1 − τ)x
30 // x + αp ≥ x − τx
31 // αp ≥ −τx (2)
32 //
33 // (2) is false if p < 0 and α is sufficiently large. Let p < 0.
34 //
35 // αp ≥ −τx
36 // α ≤ −τxᵢ/pᵢ for i in range(x.rows()) (3)
37 //
38 // When (2) is false, find the largest α for which (3) is true.
39 Scalar α(1);
40 for (int i = 0; i < x.rows(); ++i) {
41 if (α * p[i] < -τ * x[i]) {
42 // α = −τx/p is (3)'s upper bound
43 α = -τ * x[i] / p[i];
44 }
45 }
46
47 return α;
48}
49
50} // namespace slp