diff --git a/src/main.cpp b/src/main.cpp index bad13ec1..f3076c0d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -164,7 +164,7 @@ int main(int argc, char** argv) { vroom::io::update_port(cl_args.servers, port); } exploration_level = std::min(exploration_level, vroom::MAX_EXPLORATION_LEVEL); - vroom::io::set_exploration_level(cl_args, exploration_level); + cl_args.set_exploration_level(exploration_level); if (debug_depth) { cl_args.depth = debug_depth.value(); } diff --git a/src/structures/cl_args.cpp b/src/structures/cl_args.cpp index 944c1d5a..5dfeac31 100644 --- a/src/structures/cl_args.cpp +++ b/src/structures/cl_args.cpp @@ -10,6 +10,7 @@ All rights reserved (see LICENSE). #include #include "structures/cl_args.h" +#include "utils/helpers.h" namespace vroom::io { @@ -75,18 +76,10 @@ void update_port(Servers& servers, std::string_view value) { } } -void set_exploration_level(CLArgs& cl_args, unsigned exploration_level) { - cl_args.depth = exploration_level; +void CLArgs::set_exploration_level(unsigned exploration_level) { + depth = utils::get_depth(exploration_level); - assert(exploration_level <= MAX_EXPLORATION_LEVEL); - - cl_args.nb_searches = 4 * (exploration_level + 1); - if (exploration_level >= 4) { - cl_args.nb_searches += 4; - } - if (exploration_level == MAX_EXPLORATION_LEVEL) { - cl_args.nb_searches += 4; - } + nb_searches = utils::get_nb_searches(exploration_level); } } // namespace vroom::io diff --git a/src/structures/cl_args.h b/src/structures/cl_args.h index a20ca7ae..71b4ef9e 100644 --- a/src/structures/cl_args.h +++ b/src/structures/cl_args.h @@ -36,14 +36,14 @@ struct CLArgs { unsigned nb_threads; // -t unsigned nb_searches; // derived from -x unsigned depth; // derived from -x + + void set_exploration_level(unsigned exploration_level); }; void update_host(Servers& servers, std::string_view value); void update_port(Servers& servers, std::string_view value); -void set_exploration_level(CLArgs& cl_args, unsigned exploration_level); - } // namespace vroom::io #endif diff --git a/src/structures/vroom/input/input.cpp b/src/structures/vroom/input/input.cpp index 6ac64d6d..74df05fd 100644 --- a/src/structures/vroom/input/input.cpp +++ b/src/structures/vroom/input/input.cpp @@ -1118,6 +1118,17 @@ std::unique_ptr Input::get_problem() const { return std::make_unique(*this); } +Solution Input::solve(unsigned exploration_level, + unsigned nb_thread, + const Timeout& timeout, + const std::vector& h_param) { + return solve(utils::get_nb_searches(exploration_level), + utils::get_depth(exploration_level), + nb_thread, + timeout, + h_param); +} + Solution Input::solve(unsigned nb_searches, unsigned depth, unsigned nb_thread, diff --git a/src/structures/vroom/input/input.h b/src/structures/vroom/input/input.h index e4a6358f..c7122e2e 100644 --- a/src/structures/vroom/input/input.h +++ b/src/structures/vroom/input/input.h @@ -200,6 +200,14 @@ class Input { const std::vector& h_param = std::vector()); + // Overload designed to expose the same interface as the `-x` + // command-line flag for out-of-the-box setup of exploration level. + Solution solve(unsigned exploration_level, + unsigned nb_thread, + const Timeout& timeout = Timeout(), + const std::vector& h_param = + std::vector()); + Solution check(unsigned nb_thread); }; diff --git a/src/utils/helpers.h b/src/utils/helpers.h index 8a061ff3..e0917078 100644 --- a/src/utils/helpers.h +++ b/src/utils/helpers.h @@ -38,6 +38,24 @@ inline UserCost add_without_overflow(UserCost a, UserCost b) { return a + b; } +inline unsigned get_depth(unsigned exploration_level) { + return exploration_level; +} + +inline unsigned get_nb_searches(unsigned exploration_level) { + assert(exploration_level <= MAX_EXPLORATION_LEVEL); + + unsigned nb_searches = 4 * (exploration_level + 1); + if (exploration_level >= 4) { + nb_searches += 4; + } + if (exploration_level == MAX_EXPLORATION_LEVEL) { + nb_searches += 4; + } + + return nb_searches; +} + INIT get_init(std::string_view s); SORT get_sort(std::string_view s);