Commit 085c0ae3 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

initializer: add crossover option

parent 954c101c
Pipeline #5532 passed with stage
in 3 minutes and 11 seconds
......@@ -704,6 +704,9 @@ assign_parameter(baryonyx::solver_parameters& params,
else if (value == "cycle")
params.init_policy =
baryonyx::solver_parameters::init_policy_type::cycle;
else if (value == "crossover-cycle")
params.init_policy =
baryonyx::solver_parameters::init_policy_type::crossover_cycle;
else
return command_line_status::init_policy_error;
......
......@@ -334,7 +334,8 @@ struct BX_EXPORT solver_parameters
bastert,
pessimistic_solve,
optimistic_solve,
cycle
cycle,
crossover_cycle
};
enum class floating_point_type
......
......@@ -167,9 +167,11 @@ init_policy_type_to_string(solver_parameters::init_policy_type type) noexcept
using underlying_type =
typename std::underlying_type<solver_parameters::init_policy_type>::type;
static std::string_view ret[] = {
"bastert", "pessimistic-solve", "optimistic-solve", "cycle"
};
static std::string_view ret[] = { "bastert",
"pessimistic-solve",
"optimistic-solve",
"cycle",
"crossover-cycle" };
return ret[static_cast<underlying_type>(type)];
}
......
This diff is collapsed.
......@@ -52,7 +52,7 @@ struct best_solution_recorder
mutable std::mutex m_mutex;
std::multiset<raw_result<Mode>, raw_result_compare<Mode>> m_solutions;
std::atomic_bool m_have_solution{ false };
std::atomic_size_t m_solution_number{ 0 };
std::atomic_int m_remaining_constraints{ std::numeric_limits<int>::max() };
double m_value{ bad_value<Mode, double>() };
......@@ -64,10 +64,13 @@ struct best_solution_recorder
bool copy_best_solution(bit_array& x) const noexcept
{
if (!m_solution_number)
return false;
try {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_solutions.empty() || m_solutions.begin()->x.empty())
if (m_solutions.begin()->x.empty())
return false;
x = m_solutions.begin()->x;
......@@ -81,10 +84,13 @@ struct best_solution_recorder
bool copy_best_solution(bit_array& x, int from, int to) const noexcept
{
if (!m_solution_number)
return false;
try {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_solutions.empty() || m_solutions.begin()->x.empty())
if (m_solutions.begin()->x.empty())
return false;
x.assign(m_solutions.begin()->x, from, to);
......@@ -99,10 +105,13 @@ struct best_solution_recorder
template<typename Random>
bool copy_any_solution(bit_array& x, Random& rng) const noexcept
{
if (!m_solution_number)
return false;
try {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_solutions.empty() || m_solutions.begin()->x.empty())
if (m_solutions.begin()->x.empty())
return false;
const std::size_t zero{ 0 };
......@@ -125,10 +134,13 @@ struct best_solution_recorder
bool copy_any_solution(bit_array& x, Random& rng, int from, int to) const
noexcept
{
if (!m_solution_number)
return false;
try {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_solutions.empty() || m_solutions.begin()->x.empty())
if (m_solutions.begin()->x.empty())
return false;
const std::size_t zero{ 0 };
......@@ -151,7 +163,7 @@ struct best_solution_recorder
int remaining_constraints,
int loop)
{
if (m_have_solution)
if (m_solution_number)
return;
try {
......@@ -177,10 +189,8 @@ struct best_solution_recorder
{
try {
std::lock_guard<std::mutex> lock(m_mutex);
if (!m_have_solution) {
if (m_solution_number == 0)
m_solutions.clear();
m_have_solution = true;
}
auto it = m_solutions.find(value);
if (it == m_solutions.end() || it->x != solution) {
......@@ -193,12 +203,19 @@ struct best_solution_recorder
if (m_ctx->update && ret == m_solutions.begin())
m_ctx->update(0, value, loop, duration);
m_solution_number = m_solutions.size();
info(m_ctx, " - {} solutions found\n", m_solutions.size());
}
} catch (const std::exception& e) {
error(m_ctx, "sync optimization error: {}", e.what());
}
}
std::size_t size() const noexcept
{
return m_solution_number;
}
};
template<typename Solver, typename Float, typename Mode, typename Cost>
......
......@@ -227,8 +227,10 @@ get_init_policy(int type)
return bx::solver_parameters::init_policy_type::optimistic_solve;
case 3:
return bx::solver_parameters::init_policy_type::cycle;
case 4:
return bx::solver_parameters::init_policy_type::crossover_cycle;
default:
return bx::solver_parameters::init_policy_type::pessimistic_solve;
return bx::solver_parameters::init_policy_type::bastert;
}
}
......@@ -413,6 +415,7 @@ convert_result(const baryonyx::result& res, bool minimize)
//' - 1: pessimistic_solve,
//' - 2: optimistic_solve,
//' - 3: cycle
//' - 4: crossover_cycle
//'
//' @param float_type the type of real used into the solver. Default is to
//' use the C/C++ double representation.
......@@ -571,6 +574,7 @@ solve_01lp_problem(std::string file_path,
//' - 1: pessimistic_solve,
//' - 2: optimistic_solve,
//' - 3: cycle
//' - 4: crossover_cycle
//'
//' @param float_type the type of real used into the solver. Default is to
//' use the C/C++ double representation.
......
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