bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
iterative_algorithm_controller.h
Go to the documentation of this file.
1#ifndef ITERATIVE_ALGORITHM_CONTROLLER_H
2#define ITERATIVE_ALGORITHM_CONTROLLER_H
3
4#include "bitrl/bitrl_types.h"
6#include <limits>
7
8namespace bitrl
9{
10namespace utils
11{
12
17{
18 public:
23
28
33
38
43
48
53
57 bool show_iterations() const { return show_iterations_; }
58
63 bool track_residuals() const { return track_residuals_; }
64
69 void set_tolerance(real_t tol) { exit_tolerance_ = tol; }
70
74 void set_show_iterations_flag(bool flag) { show_iterations_ = flag; }
75
80 void set_track_residuals_flag(bool flag) { track_residuals_ = flag; }
81
85 void set_num_threads(uint_t nthreads) { n_threads_ = nthreads; }
86
91 void set_max_itrs(uint_t max_itrs) { max_iterations_ = max_itrs; }
92
96 uint_t get_current_iteration() const { return current_iteration_idx_; }
97
101 real_t get_exit_tolerance() const { return exit_tolerance_; }
102
106 uint_t get_max_iterations() const { return max_iterations_; }
107
111 uint_t get_num_threads() const { return n_threads_; }
112
117 real_t get_residual() const { return current_res_; }
118
123
127 void update_residual(real_t res) { current_res_ = res; }
128
132 void reset(const IterativeAlgorithmController &control);
133
137 void reset();
138
139 private:
140 uint_t max_iterations_;
141 real_t exit_tolerance_;
142 uint_t current_iteration_idx_;
143 uint_t n_threads_;
144 real_t current_res_;
145 bool show_iterations_;
146 bool track_residuals_;
147};
148
151 : max_iterations_(max_iterations), exit_tolerance_(exit_tolerance), current_iteration_idx_(0),
152 n_threads_(1), current_res_(std::numeric_limits<real_t>::max()), show_iterations_(false),
153 track_residuals_(false)
154{
155}
156
157} // namespace utils
158} // namespace bitrl
159
160#endif // ITERATIVE_ALGORITHM_CONTROLLER_H
Controller for iterative algorithms.
Definition iterative_algorithm_controller.h:17
uint_t get_current_iteration() const
Returns the current iteration index.
Definition iterative_algorithm_controller.h:96
real_t get_residual() const
get_residual
Definition iterative_algorithm_controller.h:117
bool track_residuals() const
track_residuals
Definition iterative_algorithm_controller.h:63
IterativeAlgorithmController(uint_t maxIterations, real_t exitTolerance)
Constructor.
Definition iterative_algorithm_controller.h:149
real_t get_exit_tolerance() const
Returns the exit tolerance for the algorithm.
Definition iterative_algorithm_controller.h:101
uint_t get_num_threads() const
Get the number of threads used.
Definition iterative_algorithm_controller.h:111
uint_t get_max_iterations() const
Return the maximum number of iterations.
Definition iterative_algorithm_controller.h:106
~IterativeAlgorithmController()=default
Destructor.
IterativeAlgorithmController & operator=(const IterativeAlgorithmController &)=default
copy assignement
void set_tolerance(real_t tol)
set_tolerance
Definition iterative_algorithm_controller.h:69
void set_num_threads(uint_t nthreads)
Set the number of threads.
Definition iterative_algorithm_controller.h:85
void set_track_residuals_flag(bool flag)
set_track_residuals_flag
Definition iterative_algorithm_controller.h:80
IterativeAlgorithmResult get_state() const
Returns the state of the controller.
Definition iterative_algorithm_controller.cpp:8
IterativeAlgorithmController(const IterativeAlgorithmController &)=default
Copy constructor.
void reset()
reset
Definition iterative_algorithm_controller.cpp:45
void set_max_itrs(uint_t max_itrs)
set_max_itrs
Definition iterative_algorithm_controller.h:91
IterativeAlgorithmController(IterativeAlgorithmController &&)=default
Move copy constructor.
bool continue_iterations()
Returns true if the iterations of the algorithm should be continued.
Definition iterative_algorithm_controller.cpp:19
IterativeAlgorithmController & operator=(IterativeAlgorithmController &&)=default
move copy assignement
void update_residual(real_t res)
Update the residual.
Definition iterative_algorithm_controller.h:127
bool show_iterations() const
show iterations
Definition iterative_algorithm_controller.h:57
void set_show_iterations_flag(bool flag)
show iterations
Definition iterative_algorithm_controller.h:74
OutT resolve(const std::string &name, const std::map< std::string, std::any > &input)
Definition std_map_utils.h:25
Definition bitrl_consts.h:14
double real_t
real_t
Definition bitrl_types.h:23
std::size_t uint_t
uint_t
Definition bitrl_types.h:43
The IterativeAlgorithmResult struct. Helper struct to assemble the result of an iterative algorithm.
Definition iterative_algorithm_result.h:19