Skip to content

Commit

Permalink
Merge branch 'fix/unnecessary-range-copy'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoupey committed Aug 13, 2023
2 parents fe7a11d + 76fbd95 commit 6766a03
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Add job id to error message for unreachable step (#946)
- Reduce `compute_best_route_split_choice` complexity (#962)
- `Eval::operator<` sorts on cost, then duration (#914)
- Improved `vrptw::PDShift` implementation (#852)

### Fixed

Expand Down
9 changes: 1 addition & 8 deletions src/algorithms/local_search/local_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,15 +2282,8 @@ void LocalSearch<Route,
std::vector<Index> between_pd(_sol[v].route.begin() + r + 1,
_sol[v].route.begin() + delivery_r);

Amount delivery = _input.zero_amount();
for (unsigned i = r + 1; i < delivery_r; ++i) {
const auto& job = _input.jobs[_sol[v].route[i]];
if (job.type == JOB_TYPE::SINGLE) {
delivery += job.delivery;
}
}
_sol[v].replace(_input,
delivery,
_sol[v].delivery_in_range(r + 1, delivery_r),
between_pd.begin(),
between_pd.end(),
r,
Expand Down
22 changes: 8 additions & 14 deletions src/problems/vrptw/operators/pd_shift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ PDShift::PDShift(const Input& input,
static_cast<RawRoute&>(tw_t_route),
t_vehicle,
gain_threshold),
_source_without_pd(s_route.begin() + _s_p_rank + 1,
s_route.begin() + _s_d_rank),
_tw_s_route(tw_s_route),
_tw_t_route(tw_t_route) {
}
Expand All @@ -42,8 +40,8 @@ void PDShift::compute_gain() {
bool is_valid_removal =
_tw_s_route.is_valid_addition_for_tw(_input,
_input.zero_amount(),
_source_without_pd.begin(),
_source_without_pd.end(),
s_route.begin() + _s_p_rank + 1,
s_route.begin() + _s_d_rank,
_s_p_rank,
_s_d_rank + 1);
if (!is_valid_removal) {
Expand Down Expand Up @@ -85,17 +83,13 @@ void PDShift::apply() {
if (_s_d_rank == _s_p_rank + 1) {
_tw_s_route.remove(_input, _s_p_rank, 2);
} else {
Amount delivery = _input.zero_amount();
for (unsigned i = _s_p_rank + 1; i < _s_d_rank; ++i) {
const auto& job = _input.jobs[s_route[i]];
if (job.type == JOB_TYPE::SINGLE) {
delivery += job.delivery;
}
}
std::vector<Index> source_without_pd(s_route.begin() + _s_p_rank + 1,
s_route.begin() + _s_d_rank);

_tw_s_route.replace(_input,
delivery,
_source_without_pd.begin(),
_source_without_pd.end(),
_tw_s_route.delivery_in_range(_s_p_rank + 1, _s_d_rank),
source_without_pd.begin(),
source_without_pd.end(),
_s_p_rank,
_s_d_rank + 1);
}
Expand Down
1 change: 0 additions & 1 deletion src/problems/vrptw/operators/pd_shift.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace vroom::vrptw {

class PDShift : public cvrp::PDShift {
private:
std::vector<Index> _source_without_pd;
TWRoute& _tw_s_route;
TWRoute& _tw_t_route;
Amount _best_t_delivery;
Expand Down

0 comments on commit 6766a03

Please sign in to comment.