47template <concepts::
objective_function ObjectiveFunction>
55template <concepts::single_variate_
objective_function ObjectiveFunction>
57 :
public optimizer_base<heuristic_global_optimizer<ObjectiveFunction>> {
69 using value_type =
typename objective_function_type::value_type;
71 static_assert(std::is_same_v<variable_type, value_type>);
91 opt1_.change_objective_function(obj_fun);
92 opt2_.change_objective_function(obj_fun);
102 opt1_.init(lower, upper);
103 opt2_.init(opt1_.lower(), opt1_.upper());
115 return opt2_.is_stop_criteria_satisfied();
124 iteration_logger.template append<index_type>(
125 "Iter.", &this_type::iterations);
126 iteration_logger.template append<index_type>(
127 "Eval.", &this_type::evaluations);
128 iteration_logger.template append<value_type>(
129 "Value", &this_type::opt_value);
136 return opt2_.opt_variable();
143 return opt2_.opt_value();
150 return opt1_.iterations() + opt2_.iterations();
157 return opt1_.evaluations() + opt2_.evaluations();
174template <concepts::multi_variate_
objective_function ObjectiveFunction>
176 :
public optimizer_base<heuristic_global_optimizer<ObjectiveFunction>> {
185 using variable_type =
typename objective_function_type::variable_type;
191 using value_type =
typename objective_function_type::value_type;
204 opt1_.max_evaluations(default_opt1_max_evaluations);
213 opt1_.change_objective_function(obj_fun);
214 opt2_.change_objective_function(obj_fun);
224 opt1_.init(lower, upper);
225 current_optimizer_index_ = 1;
232 if (current_optimizer_index_ == 1) {
233 if (!opt1_.is_stop_criteria_satisfied()) {
237 opt2_.init(opt1_.opt_variable());
238 current_optimizer_index_ = 2;
247 if (current_optimizer_index_ == 1) {
250 return opt2_.is_stop_criteria_satisfied();
259 iteration_logger.template append<index_type>(
260 "Iter.", &this_type::iterations);
261 iteration_logger.template append<index_type>(
262 "Eval.", &this_type::evaluations);
263 iteration_logger.template append<value_type>(
264 "Value", &this_type::opt_value);
265 iteration_logger.template append<index_type>(
266 "Stage", &this_type::current_optimizer_index);
273 if (current_optimizer_index_ == 1) {
274 return opt1_.opt_variable();
276 return opt2_.opt_variable();
283 if (current_optimizer_index_ == 1) {
284 return opt1_.opt_value();
286 return opt2_.opt_value();
293 if (current_optimizer_index_ == 1) {
294 return opt1_.iterations();
296 return opt1_.iterations() + opt2_.iterations();
303 if (current_optimizer_index_ == 1) {
304 return opt1_.evaluations();
306 return opt1_.evaluations() + opt2_.evaluations();
317 opt1_.max_evaluations(value);
329 opt2_.tol_simplex_size(value);
340 opt1_max_evaluations(max_evaluations);
350 constexpr index_type max_evaluations = default_opt1_max_evaluations;
351 opt1_max_evaluations(max_evaluations);
362 opt1_max_evaluations(max_evaluations);
373 return current_optimizer_index_;
386 static constexpr index_type default_opt1_max_evaluations = 1000;
Class to write logs of iterations.
Class of tags of logs without memory management.
Class of dividing rectangles (DIRECT) method jones1993 for optimization.
Class of downhill simplex method.
Class of golden section search method.
Class to perform global optimization in 1 dimension using heuristics.
auto light_mode() -> heuristic_global_optimizer &
Configure this optimizer for easy problems.
void iterate()
Iterate the algorithm once.
typename objective_function_type::value_type value_type
Type of function values.
auto opt1_max_evaluations(index_type value) -> heuristic_global_optimizer &
Set the maximum number of function evaluations in the first optimizer.
auto is_stop_criteria_satisfied() const -> bool
Determine if stopping criteria of the algorithm are satisfied.
auto middle_mode() -> heuristic_global_optimizer &
Configure this optimizer for middle problems.
auto heavy_mode() -> heuristic_global_optimizer &
Configure this optimizer for difficult problems.
dividing_rectangles< ObjectiveFunction > opt1_
First optimizer.
typename objective_function_type::variable_type variable_type
Type of variables.
auto opt_value() const -> const value_type &
Get current optimal value.
ObjectiveFunction objective_function_type
Type of the objective function.
heuristic_global_optimizer(const objective_function_type &obj_fun=objective_function_type())
Constructor.
auto evaluations() const noexcept -> index_type
Get the number of function evaluations.
void configure_iteration_logger(logging::iterations::iteration_logger< this_type > &iteration_logger) const
Configure an iteration logger.
auto current_optimizer_index() const noexcept -> index_type
Get the current optimizer index.
typename variable_type::Scalar variable_scalar_type
Type of scalars in variables.
downhill_simplex< ObjectiveFunction > opt2_
Second optimizer.
sampling_optimizer< objective_function_type > opt1_
First optimizer.
void init(const variable_type &lower, const variable_type &upper)
Initialize the algorithm.
golden_section_search< objective_function_type > opt2_
Second optimizer.
auto opt_variable() const -> const variable_type &
Get current optimal variable.
auto iterations() const noexcept -> index_type
Get the number of iterations.
auto opt2_tol_simplex_size(const variable_scalar_type &value) -> heuristic_global_optimizer &
Set tolerance of size of simplex in the second optimizer.
void change_objective_function(const objective_function_type &obj_fun)
Change the objective function.
Class to perform global optimization using heuristics.
Base class of implementations of optimization algorithms.
Class to perform optimization using samples of objective functions.
Definition of dividing_rectangles class.
Definition of downhill_simplex class.
Definition of golden_section_search class.
Definition of index_type type.
Definition of iteration_logger class.
Definition of log_tag_view class.
Definition of multi_variate_objective_function concept.
std::ptrdiff_t index_type
Type of indices in this library.
Namespace of optimization algorithms.
constexpr auto heuristic_global_optimizer_tag
Tag of heuristic_global_optimizer.
Definition of objective_function concept.
Definition of optimizer_base class.
Definition of sampling_optimizer class.
Definition of single_variate_objective_function concept.