63 adaptive_diagonal_curves<ObjectiveFunction, MaxDigits>> {
75 using value_type =
typename objective_function_type::value_type;
102 return "local (last)";
106 return "global (last)";
108 return "non dividable";
110 return "invalid process";
178 "invalid state (bug in adaptive_diagonal_curve class)");
198 iteration_logger.template append<index_type>(
200 iteration_logger.template append<index_type>(
202 iteration_logger.template append<value_type>(
206 .template append<std::string_view>(
208 ->width(state_width);
265 "Maximum number of function evaluations must be a positive "
282 "Minimum rate of improvement in the function value required for "
283 "potentially optimal rectangles must be a positive value.");
298 "Rate of function value used to check whether the function value "
299 "decreased in the current phase must be a positive value.");
327 const auto [lower_vertex, upper_vertex] =
328 rectangle_type::determine_sample_points(point);
329 const auto lower_vertex_value =
value_dict_(lower_vertex);
330 const auto upper_vertex_value =
value_dict_(upper_vertex);
331 const auto ave_value =
half * (lower_vertex_value + upper_vertex_value);
334 groups_.emplace_back(rect.dist());
413 const bool is_optimal_smallest =
415 const bool is_all_smallest =
418 if ((!is_optimal_smallest) || is_all_smallest) {
435 const std::size_t max_group_index = std::max<std::size_t>(
446 const std::size_t max_group_index = std::max<std::size_t>(
456 const std::size_t max_group_index =
457 (std::max<std::size_t>(
476 for (std::size_t i = 0; i <
groups_.size(); ++i) {
482 "adaptive_diagonal_curves::init is not called.");
492 std::size_t min_group, std::size_t max_group) {
493 const auto search_rect =
495 bool divided_rectangle =
false;
496 for (
auto iter = std::rbegin(search_rect);
497 iter != std::rend(search_rect); ++iter) {
499 divided_rectangle =
true;
502 if (!divided_rectangle) {
505 "No rectangle can be divided. "
506 "Stop the iteration or tune the parameter MaxDigits.");
518 std::size_t min_group, std::size_t max_group)
const
519 -> std::vector<std::pair<std::size_t, value_type>> {
524 std::vector<std::pair<std::size_t, value_type>> search_rects;
525 search_rects.emplace_back(
526 min_group, std::numeric_limits<value_type>::max());
529 for (std::size_t i = min_group + 1; i <= max_group; ++i) {
534 const auto& [last_i, last_slope] = search_rects.back();
536 if (slope <= last_slope) {
537 search_rects.emplace_back(i, slope);
540 search_rects.pop_back();
546 const auto value_bound =
548 for (
auto iter = search_rects.begin(); iter != search_rects.end();) {
549 const auto& [ind, slope] = *iter;
550 if (
groups_[ind].min_rect().ave_value() -
555 iter = search_rects.erase(iter);
570 std::size_t group_ind1, std::size_t group_ind2)
const ->
value_type {
571 return (
groups_[group_ind1].min_rect().ave_value() -
572 groups_[group_ind2].min_rect().ave_value()) /
584 if (!
groups_[group_ind].is_dividable()) {
589 std::move(
groups_[group_ind].pop().vertex());
591 const auto [dim, digit] = vertex.
push_back(0);
592 const auto rect0 =
create_rect(vertex, group_ind + 1);
593 vertex(dim, digit) = 1;
594 const auto rect1 =
create_rect(vertex, group_ind + 1);
595 vertex(dim, digit) = 2;
596 const auto rect2 =
create_rect(vertex, group_ind + 1);
598 if (
groups_.size() == group_ind + 1) {
599 groups_.emplace_back(rect0.dist());
601 groups_[group_ind + 1].push(rect0);
602 groups_[group_ind + 1].push(rect1);
603 groups_[group_ind + 1].push(rect2);
617 const auto [vertex1, vertex2] =
618 rectangle_type::determine_sample_points(vertex);
621 const auto ave_value =
half * (value1 + value2);
Definition of adc_group class.
Definition of adc_sample_dict class.
Definition of assertion macros.
#define NUM_COLLECT_DEBUG_ASSERT(CONDITION)
Macro to check whether a condition is satisfied in debug build only.
Class of exception on failure in algorithm.
Class of exception on not satisfying a precondition.
Class to write logs of iterations.
Class of tags of logs without memory management.
auto logger() const noexcept -> const num_collect::logging::logger &
Access to the logger.
void configure_iteration_logger(logging::iterations::iteration_logger< this_type > &iteration_logger) const
Configure an iteration logger.
void init(const variable_type &lower, const variable_type &upper)
Initialize the algorithm.
std::size_t prec_optimal_group_index_
typename dict_type::ternary_vector_type ternary_vector_type
void divide_nondominated_rectangles(std::size_t min_group, std::size_t max_group)
Divide nondominated hyper-rectangles.
void change_objective_function(const objective_function_type &obj_fun)
Change the objective function.
static constexpr index_type default_max_evaluations
auto max_evaluations(index_type value) -> adaptive_diagonal_curves &
Set the maximum number of function evaluations.
auto calculate_slope(std::size_t group_ind1, std::size_t group_ind2) const -> value_type
Calculate slope.
void iterate_globally()
Iterate once in the global phase (not last iteration).
adaptive_diagonal_curves(const objective_function_type &obj_fun=objective_function_type())
Constructor.
std::size_t optimal_group_index_
index_type max_evaluations_
auto opt_value() const -> const value_type &
typename group_type::rectangle_type rectangle_type
static const auto default_decrease_rate_bound
typename objective_function_type::variable_type variable_type
auto opt_variable() const -> const variable_type &
Get current optimal variable.
auto min_nonempty_group_index() const -> std::size_t
Get the minimum index of non-empty groups.
void iterate_locally_last()
Iterate once at the last of the local phase.
auto last_state() const noexcept -> state_type
Get the last state.
static const auto default_min_rate_imp
std::vector< group_type > groups_
auto create_rect(const ternary_vector_type &vertex, std::size_t group_ind) -> rectangle_type
Create a hyper-rectangle.
void iterate_globally_last()
Iterate once at teh last of the global phase.
index_type iterations_in_current_phase_
adaptive_diagonal_curves< ObjectiveFunction, MaxDigits > this_type
This class.
static auto state_name(state_type state) -> std::string_view
Convert a state to string.
auto last_state_name() const noexcept -> std::string_view
ObjectiveFunction objective_function_type
void iterate_locally()
Iterate once in the local phase (not last iteration).
value_type prec_optimal_value_
auto evaluations() const noexcept -> index_type
Get the number of function evaluations.
auto min_rate_imp(value_type value) -> adaptive_diagonal_curves &
Set the minimum rate of improvement in the function value required for potentially optimal rectangles...
impl::adc_group< value_type, ternary_vector_type > group_type
void switch_state_on_local_last()
Switch to the next state if necessary in local_last state.
value_type optimal_value_
auto iterations() const noexcept -> index_type
value_type decrease_rate_bound_
impl::adc_sample_dict< objective_function_type, MaxDigits > dict_type
auto is_stop_criteria_satisfied() const -> bool
Determine if stopping criteria of the algorithm are satisfied.
auto decrease_rate_bound(value_type value) -> adaptive_diagonal_curves &
Set the rate of function value used to check whether the function value decreased in the current phas...
void switch_state()
Switch to the next state if necessary.
void create_first_rectangle()
Create the first hyper-rectangle.
typename objective_function_type::value_type value_type
state_type
Enumeration of states in ADC method.
@ global_last
Last iteration in global phase.
@ global
Global phase (not last iteration).
@ local_last
Last iteration in local phase.
@ non_dividable
No rectangle can be divided.
@ local
Local phase (not last iteration).
auto determine_nondominated_rectangles(std::size_t min_group, std::size_t max_group) const -> std::vector< std::pair< std::size_t, value_type > >
Determine nondominated hyper-rectangles.
void iterate()
Iterate the algorithm once.
auto divide_rectangle(std::size_t group_ind) -> bool
Divide a hyper-rectangle.
Class of groups in sergeyev2006 for num_collect::opt::adaptive_diagonal_curves.
adc_rectangle< value_type, ternary_vector_type > rectangle_type
auto empty() const -> bool
Check whether this group is empty.
Class of dictionaries of sampling points in num_collect::opt::adaptive_diagonal_curves.
Class of vectors of ternary floating-point numbers in num_collect::opt::adaptive_diagonal_curves.
auto push_back(digit_type digit) -> std::pair< index_type, index_type >
Add a digit to a dimension specified by next_divided_dimension_index().
optimizer_base(logging::log_tag_view tag)
Concept of multi-variate objective functions in optimization.
Definition of exceptions.
Definition of index_type type.
Definition of iteration_logger class.
Definition of log_tag_view class.
Definition of macros for logging.
#define NUM_COLLECT_LOG_AND_THROW(EXCEPTION_TYPE,...)
Write an error log and throw an exception for an error.
Definition of multi_variate_objective_function concept.
std::ptrdiff_t index_type
Type of indices in this library.
Namespace of optimization algorithms.
constexpr auto adaptive_diagonal_curves_tag
Tag of adaptive_diagonal_curves.
auto safe_cast(const From &value) -> To
Cast safely.
Definition of optimizer_base class.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of safe_cast function.