WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
fraction_to_the_boundary_rule.hpp
Go to the documentation of this file.
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
11/// Applies fraction-to-the-boundary rule to a variable and its iterate, then
12/// returns a fraction of the iterate step size within (0, 1].
13///
14/// @tparam Scalar Scalar type.
15/// @param x The variable.
16/// @param p The iterate on the variable.
17/// @param τ Fraction-to-the-boundary rule scaling factor within (0, 1].
18/// @return Fraction of the iterate step size within (0, 1].
19template <typename Scalar>
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
T * p
Definition format.h:758
Definition expression_graph.hpp:11
Scalar fraction_to_the_boundary_rule(const Eigen::Vector< Scalar, Eigen::Dynamic > &x, const Eigen::Vector< Scalar, Eigen::Dynamic > &p, Scalar τ)
Applies fraction-to-the-boundary rule to a variable and its iterate, then returns a fraction of the i...
Definition fraction_to_the_boundary_rule.hpp:20