CDT++ 1.0.0
Causal Dynamical Triangulations in C++
Loading...
Searching...
No Matches
Move_always.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 Causal Dynamical Triangulations in C++ using CGAL
3
4 Copyright © 2017 Adam Getchell
5 ******************************************************************************/
6
12
13#ifndef INCLUDE_MOVE_ALWAYS_HPP_
14#define INCLUDE_MOVE_ALWAYS_HPP_
15
16#include <utility>
17#include <variant>
18
19#include "Move_command.hpp"
20#include "Move_run.hpp"
21#include "Move_strategy.hpp"
22#include "Random.hpp"
23
24namespace cdt
25{
27 template <typename ManifoldType>
28 requires(ManifoldType::dimension == 3)
30 {
31 using CommandResults = detail::MoveCommandResults<ManifoldType>;
32 using PassResult = detail::MovePassResult<ManifoldType, std::monostate>;
33
35 MoveRunCadence m_cadence;
36
38 cdt::Random m_random;
39
41 bool m_write_files{true};
42
44 CommandResults m_command_results;
45
47 Int_precision m_checkpoint_events{};
48
49 [[nodiscard]] auto execute_pass(ManifoldType current,
50 std::monostate strategy_state,
51 Int_precision const attempts) -> PassResult
52 {
53 MoveCommand<ManifoldType> command{std::move(current)};
54 for (auto move_attempt = Int_precision{0}; move_attempt < attempts;
55 ++move_attempt)
56 {
58 }
59 command.execute(m_random);
60 auto command_results =
62 return {.manifold = std::move(command).result(),
63 .command_results = std::move(command_results),
64 .strategy_state = strategy_state};
65 }
66
67 static void print_results(CommandResults const& results)
68 {
69 fmt::print("=== Move Results ===\n");
70 fmt::print("(2,3) moves: {} attempted = {} successful and {} failed.\n",
71 results.attempted.two_three_moves(),
72 results.succeeded.two_three_moves(),
73 results.failed.two_three_moves());
74 fmt::print("(3,2) moves: {} attempted = {} successful and {} failed.\n",
75 results.attempted.three_two_moves(),
76 results.succeeded.three_two_moves(),
77 results.failed.three_two_moves());
78 fmt::print("(2,6) moves: {} attempted = {} successful and {} failed.\n",
79 results.attempted.two_six_moves(),
80 results.succeeded.two_six_moves(),
81 results.failed.two_six_moves());
82 fmt::print("(6,2) moves: {} attempted = {} successful and {} failed.\n",
83 results.attempted.six_two_moves(),
84 results.succeeded.six_two_moves(),
85 results.failed.six_two_moves());
86 fmt::print("(4,4) moves: {} attempted = {} successful and {} failed.\n",
87 results.attempted.four_four_moves(),
88 results.succeeded.four_four_moves(),
89 results.failed.four_four_moves());
90 }
91
92 public:
94 MoveStrategy() = default;
95
100 [[maybe_unused]] MoveStrategy(Int_precision const t_number_of_passes,
101 Int_precision const t_checkpoint)
102 : MoveStrategy{t_number_of_passes, t_checkpoint, cdt::Random{}, true}
103 {}
104
111 [[maybe_unused]] MoveStrategy(Int_precision const t_number_of_passes,
112 Int_precision const t_checkpoint,
113 cdt::RandomSeed const seed,
114 bool const write_files = true)
115 : MoveStrategy{t_number_of_passes, t_checkpoint, cdt::Random{seed},
116 write_files}
117 {}
118
125 [[maybe_unused]] MoveStrategy(Int_precision const t_number_of_passes,
126 Int_precision const t_checkpoint,
127 cdt::Random random,
128 bool const write_files = true)
129 : m_cadence{detail::parse_move_run_cadence(t_number_of_passes,
130 t_checkpoint, "MoveAlways")}
131 , m_random{std::move(random)}
132 , m_write_files{write_files}
133 {}
134
136 [[nodiscard]] auto passes() const noexcept { return m_cadence.passes(); }
137
139 [[nodiscard]] auto checkpoint() const noexcept
140 { return m_cadence.checkpoint(); }
141
143 [[nodiscard]] auto checkpoint_events() const noexcept
144 { return m_checkpoint_events; }
145
147 [[nodiscard]] auto seed() const noexcept { return m_random.seed(); }
148
150 [[nodiscard]] auto stream() const noexcept { return m_random.stream(); }
151
153 [[nodiscard]] auto writes_files() const noexcept { return m_write_files; }
154
156 [[nodiscard]] auto attempted() const noexcept
157 -> move_tracker::MoveTracker const&
158 { return m_command_results.attempted; }
159
161 [[nodiscard]] auto succeeded() const noexcept
162 -> move_tracker::MoveTracker const&
163 { return m_command_results.succeeded; }
164
166 [[nodiscard]] auto failed() const noexcept
167 -> move_tracker::MoveTracker const&
168 { return m_command_results.failed; }
169
180 [[nodiscard]] auto operator()(ManifoldType const& t_manifold)
181 -> ManifoldType
182 {
183#ifndef NDEBUG
184 spdlog::debug("{} called.\n", CDT_PRETTY_FUNCTION);
185#endif
186 auto result = detail::execute_move_run(
187 t_manifold, CommandResults{}, std::monostate{}, 0, m_cadence,
188 detail::MoveRunIdentity{
189 .algorithm = "Move Always", .seed = seed(), .stream = stream()},
190 m_write_files,
191 [this](ManifoldType current, std::monostate state,
192 Int_precision const attempts) {
193 return execute_pass(std::move(current), state, attempts);
194 },
195 [](ManifoldType const&, CommandResults const& results,
196 std::monostate const&) { print_results(results); },
197 [this](ManifoldType const& current, CommandResults const&,
198 std::monostate const&, Int_precision const pass_number) {
199 utilities::write_file(current, seed(), pass_number);
200 });
201
202 m_command_results = std::move(result.command_results);
203 m_checkpoint_events = result.checkpoint_events;
204 return std::move(result.manifold);
205 }
206
208 void print_results() const { print_results(m_command_results); }
209 };
210
214} // namespace cdt
215
216#endif // INCLUDE_MOVE_ALWAYS_HPP_
Do ergodic moves using the Command pattern.
Shared value-oriented orchestration for ergodic-move strategies.
auto consume_command_results(Command &command) -> MoveCommandResults< ManifoldType >
Consume cumulative MoveCommand counters exactly once.
Definition Move_run.hpp:135
auto execute_move_run(ManifoldType initial, MoveCommandResults< ManifoldType > initial_command_results, StrategyState initial_strategy_state, Int_precision const completed_passes, MoveRunCadence const cadence, MoveRunIdentity const identity, bool const writes_files, ExecutePass execute_pass, Report report, Checkpoint checkpoint) -> MoveRunResult< ManifoldType, StrategyState >
Execute shared pass, accounting, checkpoint, and report cadence.
Definition Move_run.hpp:179
Template class for move algorithms (strategies) on manifolds.
auto generate_random_move_3(Generator &generator) -> MoveType
Generate a uniformly distributed 3D move from caller-owned RNG.
Run-owned random-number generation and reproducible stream splitting.
#define CDT_PRETTY_FUNCTION
Cross-platform spelling of the current function signature for diagnostics.
Definition Settings.hpp:37
void write_file(std::filesystem::path const &filename, TriangulationType const &triangulation)
Write triangulation to file.
Queue and execute requested moves against a three-dimensional manifold while tracking attempted and s...
void execute(Generator &generator)
Execute all moves in the queue on the manifold.
void enqueue(move_tracker::MoveType const t_move)
Push a Pachner move onto the move queue.
Positive pass count and checkpoint interval for a move run.
Definition Move_run.hpp:38
MoveStrategy(Int_precision const t_number_of_passes, Int_precision const t_checkpoint)
Construct a MoveAlways run using a fresh entropy-backed stream.
auto operator()(ManifoldType const &t_manifold) -> ManifoldType
Execute a fresh run while continuing the owned random stream.
void print_results() const
Display results of the latest completed invocation.
auto attempted() const noexcept -> move_tracker::MoveTracker const &
MoveStrategy(Int_precision const t_number_of_passes, Int_precision const t_checkpoint, cdt::Random random, bool const write_files=true)
Construct a MoveAlways run from an owned PCG stream.
auto succeeded() const noexcept -> move_tracker::MoveTracker const &
MoveStrategy(Int_precision const t_number_of_passes, Int_precision const t_checkpoint, cdt::RandomSeed const seed, bool const write_files=true)
Construct a replayable MoveAlways run from an explicit seed.
auto failed() const noexcept -> move_tracker::MoveTracker const &
Select a move algorithm.
A run-owned PCG engine with a recorded seed and stream identifier.
Definition Random.hpp:137
Root entropy value used to reproduce a random run.
Definition Random.hpp:49
clang-15 does not support std::format
std::int32_t Int_precision
Definition Settings.hpp:30
MoveStrategy< MoveStrategyKind::MOVE_ALWAYS, manifolds::Manifold_3 > MoveAlways_3
Always-accept-applicable move strategy for the supported 3D manifold.