Skip to content

Commit

Permalink
Evaluate route portion in constant time in compute_best_route_split_c…
Browse files Browse the repository at this point in the history
…hoice, fixes #962.
  • Loading branch information
jcoupey committed Aug 4, 2023
1 parent 22572a8 commit 966a03f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Switch to C++20 (#851)
- Improved error messages for file-related IO errors (#553)
- Add job id to error message for unreachable step (#946)
- Reduce `compute_best_route_split_choice` complexity (#962)

### Fixed

Expand Down
33 changes: 23 additions & 10 deletions src/algorithms/local_search/route_split_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,17 @@ compute_best_route_split_choice(const Input& input,
continue;
}

Eval current_end_eval =
utils::route_eval_for_vehicle(input,
v,
source.route.begin() + r,
source.route.end());
Eval current_end_eval(end_v.fixed_cost(), 0);
current_end_eval += sol_state.fwd_costs[s_vehicle][v].back() -
sol_state.fwd_costs[s_vehicle][v][r];
if (end_v.has_start()) {
current_end_eval += end_v.eval(end_v.start.value().index(),
input.jobs[source.route[r]].index());
}
if (end_v.has_end()) {
current_end_eval += end_v.eval(input.jobs[source.route.back()].index(),
end_v.end.value().index());
}

if (!end_v.ok_for_travel_time(current_end_eval.duration)) {
continue;
Expand Down Expand Up @@ -137,11 +143,18 @@ compute_best_route_split_choice(const Input& input,
continue;
}

Eval current_begin_eval =
utils::route_eval_for_vehicle(input,
v,
source.route.begin(),
source.route.begin() + r);
Eval current_begin_eval(begin_v.fixed_cost(), 0);
current_begin_eval += sol_state.fwd_costs[s_vehicle][v][r - 1];
if (begin_v.has_start()) {
current_begin_eval +=
begin_v.eval(begin_v.start.value().index(),
input.jobs[source.route.front()].index());
}
if (begin_v.has_end()) {
current_begin_eval +=
begin_v.eval(input.jobs[source.route[r - 1]].index(),
begin_v.end.value().index());
}

if (!begin_v.ok_for_travel_time(current_begin_eval.duration)) {
continue;
Expand Down

0 comments on commit 966a03f

Please sign in to comment.