| 171 | void Route::push_back(Node *node) { insert(nodes.size() - 1, node); } |
| 172 | |
| 173 | void Route::remove(size_t idx) |
| 174 | { |
| 175 | assert(0 < idx && idx < nodes.size() - 1); // is not start or end depot |
| 176 | assert(nodes[idx]->route() == this); // must be in this route |
| 177 | auto const isDepot = nodes[idx]->isReloadDepot(); |
| 178 | |
| 179 | if (isDepot) |
| 180 | { |
| 181 | // We own this node - it's in our depots vector. We erase it, and then |
| 182 | // update reload depot references that were invalidated by the erasure. |
| 183 | auto const depotIdx = std::distance(depots_.data(), nodes[idx]); |
| 184 | auto it = depots_.erase(depots_.begin() + depotIdx); |
| 185 | for (; it != depots_.end(); ++it) |
| 186 | nodes[it->idx()] = &*it; |
| 187 | } |
| 188 | else |
| 189 | // We do not own this node, so we only unassign it. |
| 190 | nodes[idx]->unassign(); |
| 191 | |
| 192 | nodes.erase(nodes.begin() + idx); // remove dangling pointer |
| 193 | for (auto after = idx; after != nodes.size(); ++after) |
| 194 | { |
| 195 | nodes[after]->idx_ = after; |
| 196 | if (isDepot) // then we need to decrease each following trip index |
| 197 | nodes[after]->trip_--; |
| 198 | } |
| 199 | |
| 200 | #ifndef NDEBUG |
| 201 | dirty = true; |
| 202 | #endif |
| 203 | } |
| 204 | |
| 205 | void Route::swap(Node *first, Node *second) |
| 206 | { |
no test coverage detected