Skip to content

Commit

Permalink
Merge branch 'enhance/heuristic-sync'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoupey committed Dec 10, 2024
2 parents 82327fe + 888cdc7 commit 2418e9d
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 242 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#### Internals

- Bypass matrix request in `plan` mode (#444)
- Account for heuristic time in timeout (#1196)
- Refactor heuristics to reduce code duplication (#1181)
- Refactor `Matrix` template class (#1089)
- Refactor to use `std::format` whenever possible (#1081)
Expand All @@ -22,6 +23,8 @@
- Remove amount consistency checks in `parse` in favor of upstream checks in `Input` (#1086)
- Reduce code duplication in routing wrappers (#1184)
- Allow passing `path` in `Server` ctor (#1192)
- Refactor to simplify `VRP::solve` (#1196)
- Remove heuristic synchronisation (#1188)

#### CI

Expand Down
19 changes: 9 additions & 10 deletions src/algorithms/heuristics/heuristics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,11 @@ void set_route(const Input& input,
}

template <class Route>
std::unordered_set<Index> set_initial_routes(const Input& input,
std::vector<Route>& routes) {
std::unordered_set<Index> assigned;

void set_initial_routes(const Input& input,
std::vector<Route>& routes,
std::unordered_set<Index>& assigned) {
std::ranges::for_each(routes,
[&](auto& r) { set_route(input, r, assigned); });

return assigned;
}

using RawSolution = std::vector<RawRoute>;
Expand All @@ -748,8 +745,9 @@ template Eval dynamic_vehicle_choice(const Input& input,
double lambda,
SORT sort);

template std::unordered_set<Index> set_initial_routes(const Input& input,
RawSolution& routes);
template void set_initial_routes(const Input& input,
RawSolution& routes,
std::unordered_set<Index>& assigned);

template Eval basic(const Input& input,
TWSolution& routes,
Expand All @@ -767,7 +765,8 @@ template Eval dynamic_vehicle_choice(const Input& input,
double lambda,
SORT sort);

template std::unordered_set<Index> set_initial_routes(const Input& input,
TWSolution& routes);
template void set_initial_routes(const Input& input,
TWSolution& routes,
std::unordered_set<Index>& assigned);

} // namespace vroom::heuristics
5 changes: 3 additions & 2 deletions src/algorithms/heuristics/heuristics.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ Eval dynamic_vehicle_choice(const Input& input,

// Populate routes with user-defined vehicle steps.
template <class Route>
std::unordered_set<Index> set_initial_routes(const Input& input,
std::vector<Route>& routes);
void set_initial_routes(const Input& input,
std::vector<Route>& routes,
std::unordered_set<Index>& assigned);

} // namespace vroom::heuristics

Expand Down
8 changes: 0 additions & 8 deletions src/algorithms/local_search/local_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1923,14 +1923,6 @@ void LocalSearch<Route,
TSPFix>::run() {
bool try_ls_step = true;

#ifdef LOG_LS
steps.emplace_back(utils::now(),
log::EVENT::START,
OperatorName::MAX,
_best_sol_indicators,
utils::format_solution(_input, _best_sol));
#endif

while (try_ls_step) {
// A round of local search.
run_ls_step();
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/local_search/log_local_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace vroom::ls::log {

enum class EVENT {
START,
HEURISTIC,
OPERATOR,
LOCAL_MINIMA,
JOB_ADDITION,
Expand Down
6 changes: 3 additions & 3 deletions src/problems/cvrp/cvrp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ const std::vector<HeuristicParameters> CVRP::heterogeneous_parameters =
CVRP::CVRP(const Input& input) : VRP(input) {
}

Solution CVRP::solve(unsigned nb_searches,
unsigned depth,
unsigned nb_threads,
Solution CVRP::solve(const unsigned nb_searches,
const unsigned depth,
const unsigned nb_threads,
const Timeout& timeout,
const std::vector<HeuristicParameters>& h_param) const {
if (_input.vehicles.size() == 1 && !_input.has_skills() &&
Expand Down
6 changes: 3 additions & 3 deletions src/problems/cvrp/cvrp.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class CVRP : public VRP {
explicit CVRP(const Input& input);

Solution
solve(unsigned nb_searches,
unsigned depth,
unsigned nb_threads,
solve(const unsigned nb_searches,
const unsigned depth,
const unsigned nb_threads,
const Timeout& timeout,
const std::vector<HeuristicParameters>& h_param) const override;
};
Expand Down
Loading

0 comments on commit 2418e9d

Please sign in to comment.