diff --git a/src/algorithms/local_search/insertion_search.h b/src/algorithms/local_search/insertion_search.h index acbf60bab..3c6422619 100644 --- a/src/algorithms/local_search/insertion_search.h +++ b/src/algorithms/local_search/insertion_search.h @@ -178,6 +178,7 @@ RouteInsertion compute_best_insertion_pd(const Input& input, } } } + assert(result.cost <= cost_threshold); if (result.cost == cost_threshold) { result.cost = std::numeric_limits::max(); } diff --git a/src/problems/cvrp/operators/pd_shift.cpp b/src/problems/cvrp/operators/pd_shift.cpp index f2b324379..2c8e2461e 100644 --- a/src/problems/cvrp/operators/pd_shift.cpp +++ b/src/problems/cvrp/operators/pd_shift.cpp @@ -31,6 +31,7 @@ PDShift::PDShift(const Input& input, assert(s_route.size() >= 2); assert(s_p_rank < s_d_rank); assert(s_d_rank < s_route.size()); + assert(s_route.route[s_p_rank] + 1 == s_route.route[s_d_rank]); stored_gain = gain_threshold; } diff --git a/src/problems/vrptw/operators/pd_shift.cpp b/src/problems/vrptw/operators/pd_shift.cpp index e912deab2..e9e7d0457 100644 --- a/src/problems/vrptw/operators/pd_shift.cpp +++ b/src/problems/vrptw/operators/pd_shift.cpp @@ -33,7 +33,6 @@ PDShift::PDShift(const Input& input, static_cast(tw_t_route), t_vehicle, gain_threshold), - _is_valid_removal(true), _source_without_pd(s_route.begin() + _s_p_rank + 1, s_route.begin() + _s_d_rank), _tw_s_route(tw_s_route), @@ -42,19 +41,13 @@ PDShift::PDShift(const Input& input, void PDShift::compute_gain() { // Check for valid removal wrt TW constraints. - if (_s_d_rank == _s_p_rank + 1) { - _is_valid_removal = - _is_valid_removal && _tw_s_route.is_valid_removal(_input, _s_p_rank, 2); - } else { - _is_valid_removal = - _is_valid_removal && - _tw_s_route.is_valid_addition_for_tw(_input, - _source_without_pd.begin(), - _source_without_pd.end(), - _s_p_rank, - _s_d_rank + 1); - } - if (!_is_valid_removal) { + bool is_valid_removal = + _tw_s_route.is_valid_addition_for_tw(_input, + _source_without_pd.begin(), + _source_without_pd.end(), + _s_p_rank, + _s_d_rank + 1); + if (!is_valid_removal) { return; } @@ -64,12 +57,10 @@ void PDShift::compute_gain() { t_vehicle, _tw_t_route, _remove_gain - stored_gain); - assert(s_route[_s_p_rank] + 1 == s_route[_s_d_rank]); if (rs.cost < std::numeric_limits::max()) { - assert(_remove_gain + -rs.cost > stored_gain); _valid = true; - stored_gain = _remove_gain + -rs.cost; + stored_gain = _remove_gain - rs.cost; _best_t_p_rank = rs.pickup_rank; _best_t_d_rank = rs.delivery_rank; } diff --git a/src/problems/vrptw/operators/pd_shift.h b/src/problems/vrptw/operators/pd_shift.h index e929b07fe..f7827ad52 100644 --- a/src/problems/vrptw/operators/pd_shift.h +++ b/src/problems/vrptw/operators/pd_shift.h @@ -17,7 +17,6 @@ namespace vrptw { class PDShift : public cvrp::PDShift { private: - bool _is_valid_removal; std::vector _source_without_pd; TWRoute& _tw_s_route; TWRoute& _tw_t_route;