|
| 1 | +// Copyright (c) 2024-2026 Jakub Musiał |
| 2 | +// This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl). |
| 3 | +// Licensed under the MIT License. See the LICENSE file in the project root for full license information. |
| 4 | + |
| 5 | +/// @file hgl/algorithm/properties.hpp |
| 6 | +/// @brief Defines lightweight, functional utilities to evaluate the global structural properties of a hypergraph. |
| 7 | + |
| 8 | +#pragma once |
| 9 | + |
| 10 | +#include "hgl/hypergraph.hpp" |
| 11 | +#include "hgl/util.hpp" |
| 12 | + |
| 13 | +namespace hgl::algorithm { |
| 14 | + |
| 15 | +// --- degree bounds --- |
| 16 | + |
| 17 | +/// @ingroup HGL-Algorithm |
| 18 | +/// @brief Calculates the maximum degree among all vertices in a hypergraph. |
| 19 | +[[nodiscard]] size_type max_degree(const traits::c_hypergraph auto& hypergraph) noexcept { |
| 20 | + const auto degrees = hypergraph.degree_map(); |
| 21 | + return degrees.empty() ? 0uz : *std::ranges::max_element(degrees); |
| 22 | +} |
| 23 | + |
| 24 | +/// @ingroup HGL-Algorithm |
| 25 | +/// @brief Calculates the minimum degree among all vertices in a hypergraph. |
| 26 | +[[nodiscard]] size_type min_degree(const traits::c_hypergraph auto& hypergraph) noexcept { |
| 27 | + const auto degrees = hypergraph.degree_map(); |
| 28 | + return degrees.empty() ? 0uz : *std::ranges::min_element(degrees); |
| 29 | +} |
| 30 | + |
| 31 | +/// @ingroup HGL-Algorithm |
| 32 | +/// @brief Calculates the maximum out-degree among all vertices in a *BF-directed* hypergraph. |
| 33 | +[[nodiscard]] size_type max_out_degree(const traits::c_bf_directed_hypergraph auto& hypergraph |
| 34 | +) noexcept { |
| 35 | + const auto degrees = hypergraph.out_degree_map(); |
| 36 | + return degrees.empty() ? 0uz : *std::ranges::max_element(degrees); |
| 37 | +} |
| 38 | + |
| 39 | +/// @ingroup HGL-Algorithm |
| 40 | +/// @brief Calculates the minimum out-degree among all vertices in a *BF-directed* hypergraph. |
| 41 | +[[nodiscard]] size_type min_out_degree(const traits::c_bf_directed_hypergraph auto& hypergraph |
| 42 | +) noexcept { |
| 43 | + const auto degrees = hypergraph.out_degree_map(); |
| 44 | + return degrees.empty() ? 0uz : *std::ranges::min_element(degrees); |
| 45 | +} |
| 46 | + |
| 47 | +/// @ingroup HGL-Algorithm |
| 48 | +/// @brief Calculates the maximum in-degree among all vertices in a *BF-directed* hypergraph. |
| 49 | +[[nodiscard]] size_type max_in_degree(const traits::c_bf_directed_hypergraph auto& hypergraph |
| 50 | +) noexcept { |
| 51 | + const auto degrees = hypergraph.in_degree_map(); |
| 52 | + return degrees.empty() ? 0uz : *std::ranges::max_element(degrees); |
| 53 | +} |
| 54 | + |
| 55 | +/// @ingroup HGL-Algorithm |
| 56 | +/// @brief Calculates the minimum in-degree among all vertices in a *BF-directed* hypergraph. |
| 57 | +[[nodiscard]] size_type min_in_degree(const traits::c_bf_directed_hypergraph auto& hypergraph |
| 58 | +) noexcept { |
| 59 | + const auto degrees = hypergraph.in_degree_map(); |
| 60 | + return degrees.empty() ? 0uz : *std::ranges::min_element(degrees); |
| 61 | +} |
| 62 | + |
| 63 | +// --- hyperedge size bounds --- |
| 64 | + |
| 65 | +/// @ingroup HGL-Algorithm |
| 66 | +/// @brief Calculates the rank (maximum size of any hyperedge) of a hypergraph. |
| 67 | +[[nodiscard]] size_type rank(const traits::c_hypergraph auto& hypergraph) noexcept { |
| 68 | + const auto sizes = hypergraph.hyperedge_size_map(); |
| 69 | + return sizes.empty() ? 0uz : *std::ranges::max_element(sizes); |
| 70 | +} |
| 71 | + |
| 72 | +/// @ingroup HGL-Algorithm |
| 73 | +/// @brief Calculates the corank (minimum size of any hyperedge) of a hypergraph. |
| 74 | +[[nodiscard]] size_type corank(const traits::c_hypergraph auto& hypergraph) noexcept { |
| 75 | + const auto sizes = hypergraph.hyperedge_size_map(); |
| 76 | + return sizes.empty() ? 0uz : *std::ranges::min_element(sizes); |
| 77 | +} |
| 78 | + |
| 79 | +/// @ingroup HGL-Algorithm |
| 80 | +/// @brief Calculates the maximum tail size among all hyperedges in a *BF-directed* hypergraph. |
| 81 | +[[nodiscard]] size_type max_tail_size(const traits::c_bf_directed_hypergraph auto& hypergraph |
| 82 | +) noexcept { |
| 83 | + const auto sizes = hypergraph.tail_size_map(); |
| 84 | + return sizes.empty() ? 0uz : *std::ranges::max_element(sizes); |
| 85 | +} |
| 86 | + |
| 87 | +/// @ingroup HGL-Algorithm |
| 88 | +/// @brief Calculates the minimum tail size among all hyperedges in a *BF-directed* hypergraph. |
| 89 | +[[nodiscard]] size_type min_tail_size(const traits::c_bf_directed_hypergraph auto& hypergraph |
| 90 | +) noexcept { |
| 91 | + const auto sizes = hypergraph.tail_size_map(); |
| 92 | + return sizes.empty() ? 0uz : *std::ranges::min_element(sizes); |
| 93 | +} |
| 94 | + |
| 95 | +/// @ingroup HGL-Algorithm |
| 96 | +/// @brief Calculates the maximum head size among all hyperedges in a *BF-directed* hypergraph. |
| 97 | +[[nodiscard]] size_type max_head_size(const traits::c_bf_directed_hypergraph auto& hypergraph |
| 98 | +) noexcept { |
| 99 | + const auto sizes = hypergraph.head_size_map(); |
| 100 | + return sizes.empty() ? 0uz : *std::ranges::max_element(sizes); |
| 101 | +} |
| 102 | + |
| 103 | +/// @ingroup HGL-Algorithm |
| 104 | +/// @brief Calculates the minimum head size among all hyperedges in a *BF-directed* hypergraph. |
| 105 | +[[nodiscard]] size_type min_head_size(const traits::c_bf_directed_hypergraph auto& hypergraph |
| 106 | +) noexcept { |
| 107 | + const auto sizes = hypergraph.head_size_map(); |
| 108 | + return sizes.empty() ? 0uz : *std::ranges::min_element(sizes); |
| 109 | +} |
| 110 | + |
| 111 | +// --- regularity --- |
| 112 | + |
| 113 | +/// @ingroup HGL-Algorithm |
| 114 | +/// @brief Evaluates whether the given hypergraph is $k$-regular (all vertices have a degree of $k$). |
| 115 | +[[nodiscard]] bool is_regular( |
| 116 | + const traits::c_hypergraph auto& hypergraph, const size_type k |
| 117 | +) noexcept { |
| 118 | + return util::all_equal(hypergraph.degree_map(), k); |
| 119 | +} |
| 120 | + |
| 121 | +/// @ingroup HGL-Algorithm |
| 122 | +/// @brief Evaluates whether the given hypergraph is structurally regular (all vertices have the same degree). |
| 123 | +[[nodiscard]] bool is_regular(const traits::c_hypergraph auto& hypergraph) noexcept { |
| 124 | + return util::is_constant(hypergraph.degree_map()); |
| 125 | +} |
| 126 | + |
| 127 | +/// @ingroup HGL-Algorithm |
| 128 | +/// @brief Evaluates whether the given *BF-directed* hypergraph is out-$k$-regular (all vertices have an out-degree of $k$). |
| 129 | +[[nodiscard]] bool is_out_regular( |
| 130 | + const traits::c_bf_directed_hypergraph auto& hypergraph, const size_type k |
| 131 | +) noexcept { |
| 132 | + return util::all_equal(hypergraph.out_degree_map(), k); |
| 133 | +} |
| 134 | + |
| 135 | +/// @ingroup HGL-Algorithm |
| 136 | +/// @brief Evaluates whether the given *BF-directed* hypergraph is out-regular (all vertices have the same out-degree). |
| 137 | +[[nodiscard]] bool is_out_regular(const traits::c_bf_directed_hypergraph auto& hypergraph |
| 138 | +) noexcept { |
| 139 | + return util::is_constant(hypergraph.out_degree_map()); |
| 140 | +} |
| 141 | + |
| 142 | +/// @ingroup HGL-Algorithm |
| 143 | +/// @brief Evaluates whether the given *BF-directed* hypergraph is in-$k$-regular (all vertices have an in-degree of $k$). |
| 144 | +[[nodiscard]] bool is_in_regular( |
| 145 | + const traits::c_bf_directed_hypergraph auto& hypergraph, const size_type k |
| 146 | +) noexcept { |
| 147 | + return util::all_equal(hypergraph.in_degree_map(), k); |
| 148 | +} |
| 149 | + |
| 150 | +/// @ingroup HGL-Algorithm |
| 151 | +/// @brief Evaluates whether the given *BF-directed* hypergraph is in-regular (all vertices have the same in-degree). |
| 152 | +[[nodiscard]] bool is_in_regular(const traits::c_bf_directed_hypergraph auto& hypergraph) noexcept { |
| 153 | + return util::is_constant(hypergraph.in_degree_map()); |
| 154 | +} |
| 155 | + |
| 156 | +// --- uniformity --- |
| 157 | + |
| 158 | +/// @ingroup HGL-Algorithm |
| 159 | +/// @brief Evaluates whether the given hypergraph is $k$-uniform (all hyperedges have a size of $k$). |
| 160 | +[[nodiscard]] bool is_uniform( |
| 161 | + const traits::c_hypergraph auto& hypergraph, const size_type k |
| 162 | +) noexcept { |
| 163 | + return util::all_equal(hypergraph.hyperedge_size_map(), k); |
| 164 | +} |
| 165 | + |
| 166 | +/// @ingroup HGL-Algorithm |
| 167 | +/// @brief Evaluates whether the given hypergraph is structurally uniform (all hyperedges have the exact same size). |
| 168 | +[[nodiscard]] bool is_uniform(const traits::c_hypergraph auto& hypergraph) noexcept { |
| 169 | + return util::is_constant(hypergraph.hyperedge_size_map()); |
| 170 | +} |
| 171 | + |
| 172 | +/// @ingroup HGL-Algorithm |
| 173 | +/// @brief Evaluates whether the given *BF-directed* hypergraph is tail-$k$-uniform (all hyperedges have a tail size of $k$). |
| 174 | +[[nodiscard]] bool is_tail_uniform( |
| 175 | + const traits::c_bf_directed_hypergraph auto& hypergraph, const size_type k |
| 176 | +) noexcept { |
| 177 | + return util::all_equal(hypergraph.tail_size_map(), k); |
| 178 | +} |
| 179 | + |
| 180 | +/// @ingroup HGL-Algorithm |
| 181 | +/// @brief Evaluates whether the given *BF-directed* hypergraph is tail-uniform (all hyperedges have the exact same tail size). |
| 182 | +[[nodiscard]] bool is_tail_uniform(const traits::c_bf_directed_hypergraph auto& hypergraph |
| 183 | +) noexcept { |
| 184 | + return util::is_constant(hypergraph.tail_size_map()); |
| 185 | +} |
| 186 | + |
| 187 | +/// @ingroup HGL-Algorithm |
| 188 | +/// @brief Evaluates whether the given *BF-directed* hypergraph is head-$k$-uniform (all hyperedges have a head size of $k$). |
| 189 | +[[nodiscard]] bool is_head_uniform( |
| 190 | + const traits::c_bf_directed_hypergraph auto& hypergraph, const size_type k |
| 191 | +) noexcept { |
| 192 | + return util::all_equal(hypergraph.head_size_map(), k); |
| 193 | +} |
| 194 | + |
| 195 | +/// @ingroup HGL-Algorithm |
| 196 | +/// @brief Evaluates whether the given *BF-directed* hypergraph is head-uniform (all hyperedges have the exact same head size). |
| 197 | +[[nodiscard]] bool is_head_uniform(const traits::c_bf_directed_hypergraph auto& hypergraph |
| 198 | +) noexcept { |
| 199 | + return util::is_constant(hypergraph.head_size_map()); |
| 200 | +} |
| 201 | + |
| 202 | +} // namespace hgl::algorithm |
0 commit comments