| 210 | } |
| 211 | |
| 212 | void RelocateWithDepot::apply(Route::Node *U, Route::Node *V) const |
| 213 | { |
| 214 | stats_.numApplications++; |
| 215 | |
| 216 | auto *uRoute = U->route(); |
| 217 | uRoute->remove(U->idx()); |
| 218 | |
| 219 | auto *vRoute = V->route(); |
| 220 | Route::Node depot = {move_.depot}; |
| 221 | |
| 222 | if (move_.type == MoveType::DEPOT_U) |
| 223 | { |
| 224 | vRoute->insert(V->idx() + 1, U); |
| 225 | vRoute->insert(V->idx() + 1, &depot); |
| 226 | } |
| 227 | |
| 228 | // We need to be careful to insert the depot last, because doing so could |
| 229 | // invalidate V (it might trigger an update to the route's internal data |
| 230 | // layout, which could invalidate V if V is a depot). |
| 231 | if (move_.type == MoveType::U_DEPOT) |
| 232 | { |
| 233 | vRoute->insert(V->idx() + 1, U); |
| 234 | vRoute->insert(V->idx() + 2, &depot); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | template <> |
| 239 | bool pyvrp::search::supports<RelocateWithDepot>(ProblemData const &data) |