bool Optimize::move_reduce_cost() { if (fleet.size() < 2) return false; bool moved = false; size_t from_pos(fleet.size() - 1); while (from_pos > 1) { for (size_t to_pos = 0; to_pos < from_pos; ++to_pos) { moved = move_reduce_cost(from_pos, to_pos) || moved; } --from_pos; } return moved; }
bool Optimize::move_reduce_cost() { if (fleet.size() < 2) return false; size_t from_pos(fleet.size() - 1); while (from_pos > 1) { for (size_t to_pos = 0; to_pos < from_pos; ++to_pos) { // problem->log << "\nmove_reduce_cost (" << fleet[from_pos].id() << ", " << fleet[to_pos].id() << ")"; if (move_reduce_cost(from_pos, to_pos)) { if (fleet[from_pos].empty()) { fleet.erase(fleet.begin() + from_pos); save_if_best(); } return true; } } --from_pos; } return false; }
bool Optimize::inter_swap(bool reversed) { // problem->log << tau("before sort"); sort_by_duration(); delete_empty_truck(); save_if_best(); if (reversed) { std::reverse(fleet.begin(), fleet.end()); } // problem->log << tau("after sort"); auto swapped = false; size_t from_pos(fleet.size()-1); while (from_pos > 1) { for (size_t to_pos = 0; to_pos < from_pos; ++to_pos) { swapped = swap_worse(from_pos, to_pos)? true : swapped; swapped = move_reduce_cost(from_pos, to_pos)? true : swapped; } delete_empty_truck(); --from_pos; } return swapped; }