MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / remove

Method remove

pyvrp/cpp/search/Route.cpp:173–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171void Route::push_back(Node *node) { insert(nodes.size() - 1, node); }
172
173void 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
205void Route::swap(Node *first, Node *second)
206{

Callers 8

applyMethod · 0.80
applyMethod · 0.80
applyDepotRemovalMoveMethod · 0.80
applyGroupMovesMethod · 0.80
perturbMethod · 0.80
applyMethod · 0.80
applyMethod · 0.80

Calls 8

isReloadDepotMethod · 0.80
idxMethod · 0.80
unassignMethod · 0.80
sizeMethod · 0.45
routeMethod · 0.45
dataMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected