Commit 15375178 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

optimizer: add parameters to kappa improve algorithm

parent 60c975e5
......@@ -418,6 +418,18 @@ To assign parameters to solver or optimizer algorithms, use the `-p
* `bound`: stores the best and the bad solution found.
* `five`: stores the best five solution found.
| init-kappa-improve-start (optimizer only)
| real
| [0-1] The start value of kappa for the improve mode.
| init_kappa_improve_increase (optimizer only)
| real
| [0-1] The start value of kappa for the improve mode.
| init_kappa_improve_stop (optimizer only)
| real
| [init-kappa-improve-start - 1.0] The stop value of kappa for the improve mode. When the optimizer kappa exceeds this value, a new crossover and mutation will run. If `init_kappa_improve_stop` equals `init-kappa-improve-start` then improving is disabled.
|===
For example:
......
......@@ -125,7 +125,10 @@ solver_started_cb(const baryonyx::solver_parameters& params)
" - init-mutation-variable-mean: {}\n"
" - init-mutation-variable-stddev: {}\n"
" - init-mutation-value-mean: {}\n"
" - init-mutation-value-stddev: {}\n",
" - init-mutation-value-stddev: {}\n"
" - init-kappa-improve-start: {}\n"
" - init-kappa-improve-increase: {}\n"
" - init-kappa-improve-stop: {}\n",
params.init_population_size,
params.init_crossover_bastert_insertion,
params.init_crossover_solution_selection_mean,
......@@ -133,7 +136,10 @@ solver_started_cb(const baryonyx::solver_parameters& params)
params.init_mutation_variable_mean,
params.init_mutation_variable_stddev,
params.init_mutation_value_mean,
params.init_mutation_value_stddev);
params.init_mutation_value_stddev,
params.init_kappa_improve_start,
params.init_kappa_improve_increase,
params.init_kappa_improve_stop);
} else {
fmt::print(" * Random solvers:\n"
" - random: bernouilli with p=0.5\n");
......@@ -463,6 +469,9 @@ enum class command_line_status
init_mutation_variable_stddev_error,
init_mutation_value_mean_error,
init_mutation_value_stddev_error,
init_kappa_improve_start_error,
init_kappa_improve_increase_error,
init_kappa_improve_stop_error,
thread_error,
seed_error
};
......@@ -502,6 +511,9 @@ constexpr const std::string_view command_line_status_string[] = {
"init_mutation_variable_stddev",
"init_mutation_value_mean",
"init_mutation_value_stddev",
"init_kappa_improve_start",
"init_kappa_improve_increase",
"init_kappa_improve_stop",
"thread",
"seed"
};
......@@ -799,6 +811,24 @@ assign_parameter(baryonyx::solver_parameters& params,
else
params.init_mutation_value_stddev = *v;
} else if (is_equal(name, "init-kappa-improve-start")) {
if (auto v = assign_01(value); !v)
return command_line_status::init_kappa_improve_start_error;
else
params.init_kappa_improve_start = *v;
} else if (is_equal(name, "init-kappa-improve-increase")) {
if (auto v = assign_01(value); !v)
return command_line_status::init_kappa_improve_increase_error;
else
params.init_kappa_improve_increase = *v;
} else if (is_equal(name, "init-kappa-improve-stop")) {
if (auto v = assign_01(value); !v)
return command_line_status::init_kappa_improve_stop_error;
else
params.init_kappa_improve_stop = *v;
} else if (is_equal(name, "init-policy")) {
if (value == "bastert")
params.init_policy =
......
......@@ -436,6 +436,10 @@ struct BX_EXPORT solver_parameters
double init_mutation_value_mean{ 0.5 };
double init_mutation_value_stddev{ 0.2 };
double init_kappa_improve_start{ 0 };
double init_kappa_improve_increase{ 0.02 };
double init_kappa_improve_stop{ 0.2 };
double w{ 0.05 }; ///< 5% of limit
unsigned int seed{ 0 }; ///< value == 0 means automatic seed.
int thread{ 0 }; ///< value <= 0 means automatic detection.
......
......@@ -60,6 +60,11 @@ struct local_context
std::uniform_int_distribution<int> bad_solution_choose;
std::uniform_int_distribution<std::size_t> crossover_dist;
std::bernoulli_distribution crossover_bastert_insertion;
const double init_kappa_improve_start;
const double init_kappa_improve_increase;
const double init_kappa_improve_stop;
const unsigned thread_id;
local_context(const context& ctx,
......@@ -78,6 +83,9 @@ struct local_context
, crossover_dist(0)
, crossover_bastert_insertion(
ctx.parameters.init_crossover_bastert_insertion)
, init_kappa_improve_start(ctx.parameters.init_kappa_improve_start)
, init_kappa_improve_increase(ctx.parameters.init_kappa_improve_increase)
, init_kappa_improve_stop(ctx.parameters.init_kappa_improve_stop)
, thread_id(thread_id_)
{}
};
......@@ -509,14 +517,14 @@ struct best_solution_recorder
double kappa = kappa_min;
if (m_kappa_append[ctx.thread_id] < 0.2) {
m_kappa_append[ctx.thread_id] += 0.02;
if (m_kappa_append[ctx.thread_id] < ctx.init_kappa_improve_stop) {
m_kappa_append[ctx.thread_id] += ctx.init_kappa_improve_increase;
kappa = kappa_min +
(kappa_max - kappa_min) * m_kappa_append[ctx.thread_id];
to_log(stdout, 5u, "- improve with kappa {}\n", kappa);
} else {
m_kappa_append[ctx.thread_id] = 0.0;
m_kappa_append[ctx.thread_id] = ctx.init_kappa_improve_start;
crossover(ctx, x);
to_log(stdout, 5u, "- crossover\n");
......
......@@ -147,6 +147,17 @@ context_set_solver_parameters(const context_ptr& ctx,
if (params.init_population_size >= 5)
ctx->parameters.init_population_size = params.init_population_size;
ctx->parameters.init_kappa_improve_start =
std::clamp(params.init_kappa_improve_start, 0.0, 1.0);
ctx->parameters.init_kappa_improve_increase =
std::clamp(params.init_kappa_improve_increase, 0.0, 1.0);
ctx->parameters.init_kappa_improve_stop =
std::clamp(params.init_kappa_improve_stop,
ctx->parameters.init_kappa_improve_start,
1.0);
ctx->parameters.pre_order = params.pre_order;
ctx->parameters.order = params.order;
ctx->parameters.float_type = params.float_type;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment