Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_ca_multi_field_rule.H
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
61#ifndef TPL_CA_MULTI_FIELD_RULE_H
62#define TPL_CA_MULTI_FIELD_RULE_H
63
64#include <concepts>
65#include <cstddef>
66#include <tuple>
67#include <type_traits>
68#include <utility>
69
70#include <ca-traits.H>
71#include <tpl_ca_concepts.H>
72
73namespace Aleph {
74namespace CA {
75
76namespace ca_mf_rule_detail {
77
78template <typename T>
80{
82};
83
84template <typename Tuple>
86
87template <typename... Fields>
88struct neighbor_view_tuple<std::tuple<Fields...>>
89{
90 using type = std::tuple<Neighbor_View<Fields>...>;
91};
92
93} // namespace ca_mf_rule_detail
94
97template <typename FieldsTuple>
100
109template <typename R, typename FieldsTuple>
111 = requires(const R &r, const FieldsTuple &cur, const Field_Neighbor_Views_Tuple<FieldsTuple> &nb) {
112 { r(cur, nb) } -> std::convertible_to<FieldsTuple>;
113 };
114
124template <typename R, typename FieldsTuple, std::size_t Rank>
125concept ContextualMultiFieldRule = requires(const R &r,
126 const FieldsTuple &cur,
128 const Cell_Context<Rank> &ctx) {
129 { r(cur, nb, ctx) } -> std::convertible_to<FieldsTuple>;
130};
131
133template <typename R, typename FieldsTuple, std::size_t Rank>
136
152template <typename Rule, typename FieldsTuple, std::size_t Rank>
154 const FieldsTuple &cur,
156 const Cell_Context<Rank> &ctx)
157{
158 if constexpr (requires { r(cur, nb, ctx); })
159 return r(cur, nb, ctx);
160 else
161 return r(cur, nb);
162}
163
164// =======================================================================
165// Field_Slice_Rule
166// =======================================================================
167
180template <std::size_t I, typename Inner>
182{
184
185public:
189 constexpr explicit Field_Slice_Rule(Inner inner) : inner_(std::move(inner)) {}
190
199 template <typename FieldsTuple>
202 {
203 static_assert(I < std::tuple_size_v<FieldsTuple>, "Field_Slice_Rule: I out of range");
205 std::get<I>(out) = inner_(std::get<I>(cur), std::get<I>(nb));
206 return out;
207 }
208
213 template <typename FieldsTuple, std::size_t Rank>
216 const Cell_Context<Rank> &ctx) const
217 {
218 static_assert(I < std::tuple_size_v<FieldsTuple>, "Field_Slice_Rule: I out of range");
220 if constexpr (requires { inner_(std::get<I>(cur), std::get<I>(nb), ctx); })
221 std::get<I>(out) = inner_(std::get<I>(cur), std::get<I>(nb), ctx);
222 else
223 std::get<I>(out) = inner_(std::get<I>(cur), std::get<I>(nb));
224 return out;
225 }
226};
227
228} // namespace CA
229} // namespace Aleph
230
231#endif // TPL_CA_MULTI_FIELD_RULE_H
size_t size_t int32_t * out
Definition ca-c-api.h:120
Common typedefs and tag types for the Cellular Automata module.
Adaptor: apply a mono-field rule to field I, leave the other fields unchanged.
FieldsTuple operator()(const FieldsTuple &cur, const Field_Neighbor_Views_Tuple< FieldsTuple > &nb, const Cell_Context< Rank > &ctx) const
Contextual-form invocation.
FieldsTuple operator()(const FieldsTuple &cur, const Field_Neighbor_Views_Tuple< FieldsTuple > &nb) const
Pure-form invocation.
constexpr Field_Slice_Rule(Inner inner)
Wrap a mono-field rule.
Concept: a pure multi-field rule.
Concept: a contextual multi-field rule.
Concept: any supported multi-field rule signature.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
typename ca_mf_rule_detail::neighbor_view_tuple< FieldsTuple >::type Field_Neighbor_Views_Tuple
std::tuple<Neighbor_View<F>...> for the field tuple std::tuple<F...>.
@ R
Recovered (and immune).
std::span< const T > Neighbor_View
Read-only view over a contiguous range of neighbour values.
Definition ca-traits.H:90
FieldsTuple apply_multi_field_rule(const Rule &r, const FieldsTuple &cur, const Field_Neighbor_Views_Tuple< FieldsTuple > &nb, const Cell_Context< Rank > &ctx)
Invoke a multi-field rule with optional context forwarding.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
STL namespace.
Per-cell context handed to rules that need to know "where" and "when" they are firing.
Definition ca-traits.H:106
gsl_rng * r
C++20 concepts for the Cellular Automata module.