Sequoia
Loading...
Searching...
No Matches
DynamicGraphUpdateTest.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2019. //
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
13
15
16namespace sequoia::testing
17{
18 class test_graph_update final : public free_test
19 {
20 public:
21 using free_test::free_test;
22
23 [[nodiscard]]
24 std::filesystem::path source_file() const;
25
26 void run_tests();
27 private:
28 template <class, class, concrete_test>
29 friend class graph_test_helper;
30
31 template
32 <
33 maths::graph_flavour GraphFlavour,
34 class EdgeWeight,
35 class NodeWeight,
36 class EdgeStorageConfig,
37 class NodeWeightStorage
38 >
39 void execute_operations();
40
41 //============================= General traversal tests ============================//
42
43 template<class Graph>
44 void test_update();
45
46 template<class Graph>
47 [[nodiscard]]
48 Graph make_graph();
49
50 template<class Graph>
51 void check_setup(const Graph& graph);
52
53 template<class Graph>
54 void check_df_update(Graph graph);
55
56 template<class Graph>
57 void check_bf_update(Graph graph);
58
59 template<class Graph>
60 void check_pr_update(Graph graph);
61
62 //============================= Breadth-first only tests ===========================//
63
64 template<class Graph>
65 void test_bf_update();
66
67 template<class Graph>
68 void test_second_edge_traversal_update(Graph& graph);
69 };
70
71 template<class G>
72 std::tuple<std::size_t, std::size_t, std::size_t>
73 nth_connection_indices(const G& graph, const std::size_t node, const std::size_t localEdgeIndex);
74
75 //=======================================================================================//
76 // Class which will be used to provide graph update functions
77
78 template <class G>
80 {
81 public:
82 graph_updater(G& graph) : m_Graph(graph) {}
83
84 void firstNodeTraversal(const std::size_t index)
85 {
86 auto iter = m_Graph.cbegin_node_weights() + index;
87 const auto newWeight = (2 + m_NodeTraversalIndex) * *iter;
88 m_Graph.set_node_weight(iter, newWeight);
89
90 ++m_NodeTraversalIndex;
91 }
92
93 void secondNodeTraversal(const std::size_t index)
94 {
95 --m_NodeTraversalIndex;
96 auto iter = m_Graph.cbegin_node_weights() + index;
97 const auto newWeight = *iter / (5 - m_NodeTraversalIndex);
98 m_Graph.set_node_weight(iter, newWeight);
99 }
100
101 template<std::input_or_output_iterator Iter>
102 void firstEdgeTraversal(Iter citer)
103 {
104 const auto newWeight = 10 + m_EdgeTraversalIndex + citer->weight();
105 m_Graph.set_edge_weight(citer, newWeight);
106
107 ++m_EdgeTraversalIndex;
108 }
109
110 template<std::input_or_output_iterator Iter>
111 void secondEdgeTraversal(Iter citer)
112 {
113 --m_EdgeTraversalIndex;
114 const auto newWeight = citer->weight() - 14 + m_EdgeTraversalIndex;
115 m_Graph.set_edge_weight(citer, newWeight);
116 }
117 private:
118 G& m_Graph;
119
120 std::size_t m_NodeTraversalIndex{},
121 m_EdgeTraversalIndex{};
122 };
123}
Headers for traversals of dynamic graphs.
class template from which all concrete tests should derive.
Definition: FreeTestCore.hpp:144
Definition: DynamicGraphTestingUtilities.hpp:115
Definition: DynamicGraphUpdateTest.hpp:80
Definition: DynamicGraphUpdateTest.hpp:19