| 111 | } |
| 112 | |
| 113 | void Route::clear() |
| 114 | { |
| 115 | if (nodes.size() == 2) // then the route is already empty and we have |
| 116 | return; // nothing to do. |
| 117 | |
| 118 | for (auto *node : nodes) // only unassign if in route; node may not |
| 119 | if (node->route() == this) // be if it's been assigned to another route |
| 120 | node->unassign(); // while loading a new solution into the LS |
| 121 | |
| 122 | nodes.clear(); |
| 123 | depots_.clear(); |
| 124 | |
| 125 | depots_.emplace_back(vehicleType_.startDepot); |
| 126 | depots_.emplace_back(vehicleType_.endDepot); |
| 127 | |
| 128 | for (size_t idx : {0, 1}) |
| 129 | { |
| 130 | nodes.push_back(&depots_[idx]); |
| 131 | depots_[idx].assign(this, idx, idx); |
| 132 | } |
| 133 | |
| 134 | update(); |
| 135 | assert(empty()); |
| 136 | } |
| 137 | |
| 138 | void Route::reserve(size_t size) { nodes.reserve(size); } |
| 139 | |