CDT++ 1.0.0-rc3
Causal Dynamical Triangulations in C++
Loading...
Searching...
No Matches
Move_outcome.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 Causal Dynamical Triangulations in C++ using CGAL
3
4 Copyright © 2026 Adam Getchell
5 ******************************************************************************/
6
9
10#ifndef CDT_PLUSPLUS_MOVE_OUTCOME_HPP
11#define CDT_PLUSPLUS_MOVE_OUTCOME_HPP
12
13#include <cstdint>
14#include <expected>
15#include <string_view>
16
17#include "Move_tracker.hpp"
18
19namespace cdt::ergodic_moves
20{
32
36 struct MoveError
37 {
42
44 [[nodiscard]] constexpr auto reason() const noexcept -> MoveFailure
45 { return category; }
46
48 [[nodiscard]] constexpr auto move() const noexcept -> move_tracker::MoveType
49 { return requested_move; }
50
52 [[nodiscard]] constexpr auto message() const noexcept -> std::string_view
53 {
54 using enum MoveFailure;
55 switch (category)
56 {
57 case NO_CANDIDATE: return "No raw proposal site is available.";
59 return "The selected proposal site is not part of the triangulation.";
61 return "The selected proposal site violates a CDT move invariant.";
62 case STALE_CANDIDATE:
63 return "The prepared proposal site no longer exists.";
65 return "CGAL rejected execution of the prepared move.";
67 return "The executed move violated a manifold postcondition.";
68 case UNKNOWN_MOVE: return "The requested Pachner move is unknown.";
69 }
70 return "The move failed for an unknown reason.";
71 }
72
75 auto operator==(MoveError const& other) const -> bool = default;
76 };
77
79 template <typename ManifoldType>
80 using MoveResult = std::expected<ManifoldType, MoveError>;
81
91
97 {
99 MoveOutcome m_outcome;
100
101 public:
105 MoveOutcome const outcome) noexcept
106 : m_move{move}, m_outcome{outcome}
107 {}
108
110 [[nodiscard]] constexpr auto move() const noexcept -> move_tracker::MoveType
111 { return m_move; }
112
114 [[nodiscard]] constexpr auto outcome() const noexcept -> MoveOutcome
115 { return m_outcome; }
116
118 [[nodiscard]] constexpr auto successful() const noexcept -> bool
119 {
120 return m_outcome == MoveOutcome::METROPOLIS_ACCEPTED ||
122 m_outcome == MoveOutcome::SUCCEEDED;
123 }
124
126 [[nodiscard]] constexpr auto accepted() const noexcept -> bool
127 { return m_outcome == MoveOutcome::METROPOLIS_ACCEPTED; }
128
131 auto operator==(MetropolisTransition const& other) const -> bool = default;
132 };
133
137 [[nodiscard]] constexpr auto outcome_from(MoveError const error) noexcept
138 -> MoveOutcome
139 {
140 using enum MoveFailure;
141 switch (error.reason())
142 {
143 case NO_CANDIDATE:
144 case INVALID_TOPOLOGY:
146 case STALE_CANDIDATE:
150 }
152 }
153
157 [[nodiscard]] constexpr auto format_as(MoveError const error) noexcept
158 -> std::string_view
159 { return error.message(); }
160} // namespace cdt::ergodic_moves
161
162#endif // CDT_PLUSPLUS_MOVE_OUTCOME_HPP
constexpr auto format_as(MoveError const error) noexcept -> std::string_view
Enable direct formatting through fmt/spdlog.
constexpr auto outcome_from(MoveError const error) noexcept -> MoveOutcome
Classify a structured move error for counter accounting.
std::expected< ManifoldType, MoveError > MoveResult
Value returned by a fallible Pachner-move transformation.
MoveOutcome
Typed state used to route proposal and execution accounting.
@ INAPPLICABLE
The sampled raw site cannot support the move.
@ METROPOLIS_ACCEPTED
Metropolis-Hastings accepted the proposal.
@ EXECUTION_FAILED
Mutation failed after proposal preparation.
@ METROPOLIS_REJECTED
Metropolis-Hastings rejected the proposal.
@ SUCCEEDED
The requested transition completed.
MoveFailure
Actionable reasons a raw move request cannot produce a new state.
@ STALE_CANDIDATE
A prepared proposal no longer resolves.
@ NO_CANDIDATE
No raw proposal site is available.
@ INVARIANT_VIOLATION
A post-mutation manifold check failed.
@ CAUSAL_INVALIDITY
The proposal violates a causal move invariant.
@ INVALID_TOPOLOGY
The proposal site is not in the triangulation.
@ UNKNOWN_MOVE
The requested move kind is unsupported.
@ EXECUTION_FAILURE
CGAL rejected the prepared mutation.
Track ergodic moves.
MoveType
The types of 3D ergodic moves.
constexpr auto successful() const noexcept -> bool
constexpr auto outcome() const noexcept -> MoveOutcome
constexpr MetropolisTransition(move_tracker::MoveType const move, MoveOutcome const outcome) noexcept
auto operator==(MetropolisTransition const &other) const -> bool=default
constexpr auto accepted() const noexcept -> bool
constexpr auto move() const noexcept -> move_tracker::MoveType
Typed error returned by move preparation or private execution.
move_tracker::MoveType requested_move
Pachner move whose proposal or execution failed.
constexpr auto message() const noexcept -> std::string_view
constexpr auto reason() const noexcept -> MoveFailure
auto operator==(MoveError const &other) const -> bool=default
constexpr auto move() const noexcept -> move_tracker::MoveType
MoveFailure category
Structured rejection or execution-failure category.