numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
iterative_solver_base.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
25
26namespace num_collect {
27inline namespace base {
28
34template <typename Derived>
38public:
45 : logging::logging_mixin(tag) {
46 this->logger().set_iterative();
47 }
48
55 void iterate() { derived().iterate(); }
56
62 [[nodiscard]] auto is_stop_criteria_satisfied() const -> bool {
63 return derived().is_stop_criteria_satisfied();
64 }
65
74 void solve() {
75 auto& iter_logger = this->initialize_iteration_logger();
76 iter_logger.write_iteration(&derived());
78 iterate();
79 iter_logger.write_iteration(&derived());
80 }
81 iter_logger.write_summary(&derived());
82 }
83
84protected:
90 [[nodiscard]] auto derived() noexcept -> Derived& {
91 return *static_cast<Derived*>(this);
92 }
93
99 [[nodiscard]] auto derived() const noexcept -> const Derived& {
100 return *static_cast<const Derived*>(this);
101 }
102};
103
104} // namespace base
105} // namespace num_collect
auto is_stop_criteria_satisfied() const -> bool
Determine if stopping criteria of the algorithm are satisfied.
iterative_solver_base(logging::log_tag_view tag)
Constructor.
auto derived() const noexcept -> const Derived &
Access derived object.
void iterate()
Iterate the algorithm once.
auto derived() noexcept -> Derived &
Access derived object.
Class to incorporate num_collect::logging::iterations::iteration_logger in algorithms.
auto initialize_iteration_logger() -> num_collect::logging::iterations::iteration_logger< Derived > &
Get the iteration logger.
Class of tags of logs without memory management.
Class to incorporate logging in algorithms.
logging_mixin(log_tag_view tag)
Constructor.
auto logger() const noexcept -> const num_collect::logging::logger &
Access to the logger.
Definition of iteration_logger_mixin class.
Definition of log_tag_view class.
Definition of logging_mixin class.
Namespace of num_collect source codes.