Sequoia
Loading...
Searching...
No Matches
GraphErrors.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2023. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
15#include <string>
16#include <stdexcept>
17
18namespace sequoia::maths::graph_errors
19{
21 {
22 std::size_t node{}, edge{};
23 };
24
26 {
27 std::size_t edge{};
28 bool inverted{};
29 };
30
31 [[nodiscard]]
32 std::string node_index_range_message(std::string_view method, std::size_t order, std::size_t node);
33
34 [[nodiscard]]
35 std::string node_index_range_message(std::string_view method, std::size_t order, std::size_t node1, std::size_t node2);
36
37 [[nodiscard]]
38 std::string edge_index_range_message(std::string_view method, edge_indices edgeIndices, std::string_view indexName, std::size_t size, std::size_t index);
39
40 [[nodiscard]]
41 std::string edge_insertion_index_message(std::string_view method, std::size_t node, std::size_t sizeAfterFirstInsertion, std::size_t index);
42
43 [[nodiscard]]
44 std::string edge_swap_indices_message(std::size_t node, std::size_t index, std::size_t numEdges);
45
46 [[nodiscard]]
47 std::string reciprocated_error_message(const edge_indices edgeIndices, const std::string_view indexName, const std::size_t reciprocatedIndex, const std::size_t index);
48
49 [[nodiscard]]
50 std::string embedded_edge_message(const std::size_t nodeIndex, const std::size_t source, const std::size_t target);
51
52 [[nodiscard]]
53 std::string inconsistent_initialization_message(std::size_t numNodes, std::size_t edgeParitions);
54
55 [[nodiscard]]
56 std::string inversion_consistency_message(std::size_t nodeIndex, edge_inversion_info zerothEdge, edge_inversion_info firstEdge);
57
58 constexpr void check_node_index_range(std::string_view method, const std::size_t order, const std::size_t node)
59 {
60 if(node >= order)
61 throw std::out_of_range{node_index_range_message(method, order, node)};
62 }
63
64 constexpr void check_node_index_range(std::string_view method, const std::size_t order, const std::size_t node1, const std::size_t node2)
65 {
66 if((node1 >= order) || (node2 >= order))
67 throw std::out_of_range{node_index_range_message(method, order, node1, node2)};
68 }
69
70 constexpr void check_edge_index_range(std::string_view method, const edge_indices edgeIndices, std::string_view indexName, const std::size_t size, const std::size_t index)
71 {
72 if(index >= size)
73 throw std::out_of_range{edge_index_range_message(method, edgeIndices, indexName, size, index)};
74 }
75
76 constexpr void check_edge_insertion_index(std::string_view method, const std::size_t node, const std::size_t sizeAfterFirstInsertion, const std::size_t index)
77 {
78 if(index > sizeAfterFirstInsertion)
79 throw std::out_of_range{edge_insertion_index_message(method, node, sizeAfterFirstInsertion, index)};
80 }
81
82 constexpr void check_edge_swap_indices(std::size_t node, std::size_t i, std::size_t j, std::size_t numEdges)
83 {
84 auto check{
85 [node, numEdges](std::size_t index){
86 if(index >= numEdges)
87 throw std::out_of_range{edge_swap_indices_message(node, index, numEdges)};
88 }
89 };
90
91 check(i);
92 check(j);
93 }
94
95 constexpr void check_reciprocated_index(const edge_indices edgeIndices, std::string_view indexName, const std::size_t reciprocatedIndex, const std::size_t index)
96 {
97 if(reciprocatedIndex != index)
98 throw std::logic_error{reciprocated_error_message(edgeIndices, indexName, reciprocatedIndex, index)};
99 }
100
101 constexpr void check_embedded_edge(const std::size_t nodeIndex, const std::size_t source, const std::size_t target)
102 {
103 if((source != nodeIndex) && (target != nodeIndex))
104 throw std::logic_error{embedded_edge_message(nodeIndex, source, target)};
105 }
106
107 constexpr void check_inversion_consistency(std::size_t nodeIndex, edge_inversion_info zerothEdge, edge_inversion_info firstEdge)
108 {
109 if(zerothEdge.inverted != firstEdge.inverted)
110 throw std::logic_error{inversion_consistency_message(nodeIndex, zerothEdge, firstEdge)};
111 }
112
113 [[nodiscard]]
114 std::string erase_edge_error(std::size_t partner, edge_indices indices);
115
116 [[nodiscard]]
117 std::string odd_num_loops_error(std::string_view method, std::size_t nodeIndex);
118
119 [[nodiscard]]
120 std::string self_referential_error(edge_indices edgeIndices, std::size_t target, std::size_t compIndex);
121
122 [[nodiscard]]
123 std::string mismatched_weights_message(std::string_view method, edge_indices edgeIndices);
124
125 [[nodiscard]]
126 std::string absent_reciprocated_partial_edge_message(std::string_view method, edge_indices edgeIndices);
127
128 [[nodiscard]]
129 std::string absent_partner_weight_message(std::string_view method, edge_indices edgeIndices);
130}
bool check(CheckType flavour, std::string description, test_logger< Mode > &logger, Iter first, Sentinel last, PredictionIter predictionFirst, PredictionSentinel predictionLast, tutor< Advisor > advisor={})
The workhorse for comparing the contents of ranges.
Definition: FreeCheckers.hpp:377
Definition: GraphErrors.hpp:21