CDT++ 1.0.0
Causal Dynamical Triangulations in C++
Loading...
Searching...
No Matches
Move_tracker.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 Causal Dynamical Triangulations in C++ using CGAL
3
4 Copyright © 2021 Adam Getchell
5 ******************************************************************************/
6
10
11#ifndef CDT_PLUSPLUS_MOVE_TRACKER_HPP
12#define CDT_PLUSPLUS_MOVE_TRACKER_HPP
13
14#include <array>
15#include <cstddef>
16#include <gsl/util>
17#include <numeric>
18#include <optional>
19#include <random>
20#include <span>
21#include <string_view>
22#include <type_traits>
23
24#include "Settings.hpp"
25
26namespace cdt::move_tracker
27{
29 inline constexpr std::size_t NUMBER_OF_3D_MOVES = 5;
30
34 enum class [[nodiscard("This contains data!")]] MoveType
35 {
38 TWO_SIX = 2,
39 SIX_TWO = 3,
41 };
42
46 [[nodiscard]] constexpr auto format_as(MoveType const move) noexcept
47 -> std::string_view
48 {
49 using enum MoveType;
50 switch (move)
51 {
52 case TWO_THREE: return "(2,3)";
53 case THREE_TWO: return "(3,2)";
54 case TWO_SIX: return "(2,6)";
55 case SIX_TWO: return "(6,2)";
56 case FOUR_FOUR: return "(4,4)";
57 }
58 return "unknown";
59 }
60
67 template <typename Enumeration>
68 requires std::is_enum_v<Enumeration>
69 [[nodiscard]] constexpr auto as_integer(Enumeration const value) noexcept
70 -> std::underlying_type_t<Enumeration>
71 {
72 return static_cast<std::underlying_type_t<Enumeration>>(value);
73 } // as_integer
74
80 [[nodiscard]] constexpr auto move_from_index(
81 std::size_t const move_choice) noexcept -> std::optional<MoveType>
82 {
83 using enum MoveType;
84 constexpr std::array moves{TWO_THREE, THREE_TWO, TWO_SIX, SIX_TWO,
85 FOUR_FOUR};
86 static_assert(moves.size() == NUMBER_OF_3D_MOVES);
87 if (move_choice >= moves.size()) { return std::nullopt; }
88 return moves[move_choice];
89 } // move_from_index
90
95 template <std::uniform_random_bit_generator Generator>
96 [[nodiscard]] inline auto generate_random_move_3(Generator& generator)
97 -> MoveType
98 {
99 std::uniform_int_distribution<int> distribution{
100 0, static_cast<int>(NUMBER_OF_3D_MOVES - 1)};
101 auto const move_choice = distribution(generator);
102 return *move_from_index(static_cast<std::size_t>(move_choice));
103 } // generate_random_move_3
104
109 {
110 using Container = std::array<Int_precision, NUMBER_OF_3D_MOVES>;
111
112 Container moves = {0}; // NOLINT
113
114 public:
119 [[nodiscard]] auto moves_view() const noexcept { return std::span(moves); }
120
126 [[nodiscard]] auto operator[](gsl::index const index) -> auto&
127 { return gsl::at(moves, index); } // operator[]
128
134 [[nodiscard]] auto operator[](gsl::index const index) const -> auto const&
135 { return gsl::at(moves, index); } // operator[]
136
142 [[nodiscard]] auto operator[](MoveType const move) -> auto&
143 { return gsl::at(moves, as_integer(move)); } // operator[]
144
150 [[nodiscard]] auto operator[](MoveType const move) const -> auto const&
151 { return gsl::at(moves, as_integer(move)); } // operator[]
152
158 auto operator+=(MoveTracker const& rhs) -> MoveTracker&
159 {
160 for (std::size_t i = 0; i < moves.size(); ++i)
161 {
162 moves[i] += rhs.moves[i];
163 }
164 return *this;
165 } // operator+=
166
171 [[nodiscard]] auto total() const noexcept
172 {
173 return std::accumulate(moves.begin(), moves.end(), Int_precision{0});
174 } // total
175
180 [[nodiscard]] auto size() const noexcept { return moves.size(); }
181
182 // 3D
183
188 [[nodiscard]] auto two_three_moves() -> auto& { return gsl::at(moves, 0); }
189
194 [[nodiscard]] auto two_three_moves() const { return gsl::at(moves, 0); }
195
200 [[nodiscard]] auto three_two_moves() -> auto& { return gsl::at(moves, 1); }
201
206 [[nodiscard]] auto three_two_moves() const { return gsl::at(moves, 1); }
207
212 [[nodiscard]] auto two_six_moves() -> auto& { return gsl::at(moves, 2); }
213
218 [[nodiscard]] auto two_six_moves() const { return gsl::at(moves, 2); }
219
224 [[nodiscard]] auto six_two_moves() -> auto& { return gsl::at(moves, 3); }
225
230 [[nodiscard]] auto six_two_moves() const { return gsl::at(moves, 3); }
231
236 [[nodiscard]] auto four_four_moves() -> auto& { return gsl::at(moves, 4); }
237
242 [[nodiscard]] auto four_four_moves() const { return gsl::at(moves, 4); }
243
245 void reset() { moves.fill(0); }
246 };
247
248} // namespace cdt::move_tracker
249
250#endif // CDT_PLUSPLUS_MOVE_TRACKER_HPP
constexpr auto as_integer(Enumeration const value) noexcept -> std::underlying_type_t< Enumeration >
Convert enum to integer.
MoveType
The types of 3D ergodic moves.
@ TWO_THREE
Replace two tetrahedra with three.
@ SIX_TWO
Replace six tetrahedra with two.
@ THREE_TWO
Replace three tetrahedra with two.
@ FOUR_FOUR
Exchange a causal four-tetrahedron diamond.
@ TWO_SIX
Replace two tetrahedra with six.
constexpr auto format_as(MoveType const move) noexcept -> std::string_view
Enable direct formatting through fmt/spdlog.
auto generate_random_move_3(Generator &generator) -> MoveType
Generate a uniformly distributed 3D move from caller-owned RNG.
constexpr auto move_from_index(std::size_t const move_choice) noexcept -> std::optional< MoveType >
Convert an integer index to MoveType.
constexpr std::size_t NUMBER_OF_3D_MOVES
Number of supported Pachner move kinds in three dimensions.
Global integer and precision settings.
The data and methods to track ergodic moves.
auto four_four_moves() const
Read access to (4,4) moves.
auto size() const noexcept
Container size.
auto three_two_moves() const
Read access to (3,2) moves.
auto three_two_moves() -> auto &
Write access to (3,2) moves.
auto operator[](gsl::index const index) const -> auto const &
The [] operator for a read-only MoveTracker.
auto moves_view() const noexcept
Get a view of the moves.
auto two_three_moves() -> auto &
Write access to (2,3) moves.
auto operator[](gsl::index const index) -> auto &
The [] operator for MoveTracker.
auto six_two_moves() -> auto &
Write access to (6,2) moves.
auto two_three_moves() const
Read access to (2,3) moves.
auto operator[](MoveType const move) -> auto &
The [] operator for MoveTracker.
void reset()
Reset all moves counts to zero.
auto two_six_moves() const
Read access to (2,6) moves.
auto four_four_moves() -> auto &
Write access to (4,4) moves.
auto operator+=(MoveTracker const &rhs) -> MoveTracker &
The += operator for MoveTracker.
auto operator[](MoveType const move) const -> auto const &
The [] operator for a read-only MoveTracker.
auto total() const noexcept
Total moves.
auto two_six_moves() -> auto &
Write access to (2,6) moves.
auto six_two_moves() const
Read access to (6,2) moves.
std::int32_t Int_precision
Definition Settings.hpp:30