Skip to content

Commit

Permalink
Have get_nb_searches and get_depth live in vroom::utils namespace ins…
Browse files Browse the repository at this point in the history
…tead.
  • Loading branch information
jcoupey committed Dec 2, 2024
1 parent 2e0bbe8 commit bb36ba0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
23 changes: 3 additions & 20 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,28 +76,10 @@ void update_port(Servers& servers, std::string_view value) {
}
}

unsigned CLArgs::get_depth(unsigned exploration_level) {
return exploration_level;
}

unsigned CLArgs::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;
}

void CLArgs::set_exploration_level(unsigned exploration_level) {
depth = get_depth(exploration_level);
depth = utils::get_depth(exploration_level);

nb_searches = get_nb_searches(exploration_level);
nb_searches = utils::get_nb_searches(exploration_level);
}

} // namespace vroom::io
4 changes: 0 additions & 4 deletions src/structures/cl_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ struct CLArgs {
unsigned nb_searches; // derived from -x
unsigned depth; // derived from -x

static unsigned get_depth(unsigned exploration_level);

static unsigned get_nb_searches(unsigned exploration_level);

void set_exploration_level(unsigned exploration_level);
};

Expand Down
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
20 changes: 6 additions & 14 deletions src/structures/vroom/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ All rights reserved (see LICENSE).
#include <unordered_map>

#include "routing/wrapper.h"
#include "structures/cl_args.h"
#include "structures/generic/matrix.h"
#include "structures/typedefs.h"
#include "structures/vroom/matrices.h"
Expand Down Expand Up @@ -194,23 +193,16 @@ class Input {
// Returns true iff both vehicles have common job candidates.
bool vehicle_ok_with_vehicle(Index v1_index, Index v2_index) const;

Solution solve(unsigned exploration_level,
Solution solve(unsigned nb_searches,
unsigned depth,
unsigned nb_thread,
const Timeout& timeout = Timeout(),
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.
return solve(io::CLArgs::get_nb_searches(exploration_level),
io::CLArgs::get_depth(exploration_level),
nb_thread,
timeout,
h_param);
}
std::vector<HeuristicParameters>());

Solution solve(unsigned nb_searches,
unsigned depth,
// 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 =
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 bb36ba0

Please sign in to comment.