| 349 | } |
| 350 | |
| 351 | void LocalSearch::applyGroupMoves(Route::Node *U, |
| 352 | CostEvaluator const &costEvaluator) |
| 353 | { |
| 354 | ProblemData::Client const &uData = data.location(U->client()); |
| 355 | |
| 356 | if (!uData.group) |
| 357 | return; |
| 358 | |
| 359 | auto const &group = data.group(*uData.group); |
| 360 | assert(group.mutuallyExclusive); |
| 361 | |
| 362 | std::vector<size_t> inSol; |
| 363 | auto const pred |
| 364 | = [&](auto client) { return solution_.nodes[client].route(); }; |
| 365 | std::copy_if(group.begin(), group.end(), std::back_inserter(inSol), pred); |
| 366 | |
| 367 | if (inSol.empty()) |
| 368 | { |
| 369 | auto const required = group.required; |
| 370 | if (solution_.insert(U, searchSpace_, costEvaluator, required)) |
| 371 | { |
| 372 | update(U->route(), U->route()); |
| 373 | searchSpace_.markPromising(U); |
| 374 | } |
| 375 | |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | // We remove clients in order of increasing cost delta (biggest improvement |
| 380 | // first), and evaluate swapping the last client with U. |
| 381 | std::vector<Cost> costs; |
| 382 | for (auto const client : inSol) |
| 383 | { |
| 384 | auto cost = removeCost(&solution_.nodes[client], data, costEvaluator); |
| 385 | costs.push_back(cost); |
| 386 | } |
| 387 | |
| 388 | // Sort clients in order of increasing removal costs. |
| 389 | std::vector<size_t> range(inSol.size()); |
| 390 | std::iota(range.begin(), range.end(), 0); |
| 391 | std::sort(range.begin(), |
| 392 | range.end(), |
| 393 | [&costs](auto idx1, auto idx2) |
| 394 | { return costs[idx1] < costs[idx2]; }); |
| 395 | |
| 396 | // Remove all but the last client, whose removal is the least valuable. |
| 397 | for (auto idx = range.begin(); idx != range.end() - 1; ++idx) |
| 398 | { |
| 399 | auto const client = inSol[*idx]; |
| 400 | auto const &node = solution_.nodes[client]; |
| 401 | auto *route = node.route(); |
| 402 | |
| 403 | searchSpace_.markPromising(&node); |
| 404 | route->remove(node.idx()); |
| 405 | update(route, route); |
| 406 | } |
| 407 | |
| 408 | // Test swapping U and V, and do so if U is better to have than V. |
nothing calls this directly
no test coverage detected