akreon-convex
Typed convex modeling, conic canonicalization, and primal-dual optimization in C++26.
Loading...
Searching...
No Matches
convex_set.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 "akreon/linalg/assert.hpp"
9
10#include "akreon/linalg/affine/affine_map.hpp"
13#include "akreon/linalg/vector/algebra_util.hpp"
14
15namespace convex {
16
24template <typename Meta, typename Derived, typename Child>
25struct ConvexSet : Atom<Meta, ConvexSet<Meta, Derived, Child>, Child> {
29 using typename BaseT::T;
30
31 static_assert(is_var_type_v<Child>,
32 "Convex set assumes variable in its domain");
33
39 constexpr explicit ConvexSet(const Child& child_in)
40 : BaseT(std::make_tuple(child_in)) {}
41
49 constexpr void validate_domain_impl() const {
51 "ConvexSet::validate_domain_impl expects set it to be good");
52 }
53
62 constexpr bool contains(const PointT& x, T tol = 1e-8) const {
63 return self().contains_impl(x, tol);
64 }
65
76 template <linalg::MatrixContainer Mat>
77 constexpr auto transform(const affine::AffineMap<Mat>& map) const {
78 return self().transform_impl(map);
79 }
80
88 template <typename OtherDerived, typename OtherChild>
89 constexpr bool operator==(
91 return self().is_equal_impl(other.self());
92 }
93
101 template <typename OtherDerived, typename OtherChild>
102 constexpr bool operator!=(
104 return !self().is_equal_impl(other.self());
105 }
106
114 template <AtomType Type, conic::BuilderLike Builder>
115 constexpr auto canonicalize_impl(const Builder& builder) const {
116 return self().template canonicalize_set<Type>(builder);
117 }
118
124 constexpr auto self() const { return static_cast<const Derived&>(*this); }
125};
126
127} // namespace convex
constexpr std::size_t dom_size_v
CRTP base for convex atoms.
Definition atom.hpp:22
dom_point_t< Domain > PointT
Point type accepted by the atom domain.
Definition atom.hpp:32
dom_type_t< Domain > T
Scalar field for the atom domain.
Definition atom.hpp:30
forward declaration of convex set
constexpr auto self() const
self function which returns a const ref to the derived object
constexpr void validate_domain_impl() const
is_well_formed
constexpr bool operator!=(const ConvexSet< Meta, OtherDerived, OtherChild > &other) const
inequality comparison overload
constexpr bool contains(const PointT &x, T tol=1e-8) const
contains to check if the point lies in the convex set
constexpr bool operator==(const ConvexSet< Meta, OtherDerived, OtherChild > &other) const
equality comparison overload
constexpr auto transform(const affine::AffineMap< Mat > &map) const
transform convex set by affine map
constexpr auto canonicalize_impl(const Builder &builder) const
canonicalize
constexpr ConvexSet(const Child &child_in)
CTOR.