akreon-convex
Typed convex modeling, conic canonicalization, and primal-dual optimization in C++26.
Loading...
Searching...
No Matches
power_cone.hpp
Go to the documentation of this file.
1/*
2 * Copyright © 2025-2026 Akreon LLC
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#pragma once
7
8#include "cone.hpp"
9
10namespace conic {
11
21template <linalg::VectorContainer Slack>
22struct PowerCone : public Cone<Slack, PowerCone<Slack>, ConeType::ASYMMETRIC> {
25
27 using ConeBase::M;
28 using typename ConeBase::T;
29
31 using AlphaVec = linalg::Vector<T, M - 1>;
32
38 constexpr explicit PowerCone(const AlphaVec& alphas_in) : alphas(alphas_in) {}
39
45 constexpr Slack x0_impl() const {
46 Slack s{};
47 for (std::size_t i = 0; i < M - 1; ++i) s(i) = T(1);
48 return s;
49 }
50
58 constexpr bool in_cone_impl(const Slack& x) const {
59 if (T(x(M - 1)) == T(0)) {
60 for (std::size_t i = 0; i < M - 1; ++i)
61 if (x(i) < T(0)) return false;
62 return true;
63 } else {
64 T res{};
65 for (std::size_t i = 0; i < M - 1; ++i) {
66 if (!(x(i) > T(0))) return false;
67 res += alphas(i) * linalg::constexpr_ln_safe(x(i));
68 }
69 const auto rhs =
70 linalg::constexpr_ln_safe(linalg::constexpr_abs(x(M - 1)));
71 return res > rhs;
72 }
73 }
74
83 constexpr T alpha_max_impl(const Slack& x,
84 const linalg::Vector<T, M>& p) const {
85 (void)x, (void)p;
87 return T(0);
88 }
89
92};
93
94} // namespace conic
cone base class
Definition cone.hpp:19
static constexpr std::size_t M
helpers to get M slack size
Definition cone.hpp:24
linalg::vector_element_t< Slack > T
alias for mat type
Definition cone.hpp:21
forward decl for power
AlphaVec alphas
member vars for power cone
constexpr PowerCone(const AlphaVec &alphas_in)
PowerCone.
linalg::Vector< T, M - 1 > AlphaVec
alpha vec
constexpr T alpha_max_impl(const Slack &x, const linalg::Vector< T, M > &p) const
fraction to boundary dK
constexpr Slack x0_impl() const
default interior point
constexpr bool in_cone_impl(const Slack &x) const
in interior of K