Skip to content

Commit

Permalink
Merge branch 'downstream/input-solve-signature'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoupey committed Dec 2, 2024
2 parents 9d58251 + bb36ba0 commit 82327fe
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
15 changes: 4 additions & 11 deletions src/structures/cl_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All rights reserved (see LICENSE).
#include <cassert>

#include "structures/cl_args.h"
#include "utils/helpers.h"

namespace vroom::io {

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/structures/cl_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions src/structures/vroom/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,17 @@ std::unique_ptr<VRP> Input::get_problem() const {
return std::make_unique<CVRP>(*this);
}

Solution Input::solve(unsigned exploration_level,
unsigned nb_thread,
const Timeout& timeout,
const std::vector<HeuristicParameters>& 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,
Expand Down
8 changes: 8 additions & 0 deletions src/structures/vroom/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ class Input {
const std::vector<HeuristicParameters>& h_param =
std::vector<HeuristicParameters>());

// 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<HeuristicParameters>& h_param =
std::vector<HeuristicParameters>());

Solution check(unsigned nb_thread);
};

Expand Down
18 changes: 18 additions & 0 deletions src/utils/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 82327fe

Please sign in to comment.