MCPcopy Index your code
hub / github.com/PyVRP/PyVRP / insert

Method insert

pyvrp/cpp/search/Route.cpp:140–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138void Route::reserve(size_t size) { nodes.reserve(size); }
139
140void Route::insert(size_t idx, Node *node)
141{
142 assert(0 < idx && idx < nodes.size());
143 auto const isDepot = node->client() < data.numDepots();
144
145 if (isDepot) // is depot, so we need to insert a copy into our own memory
146 {
147 if (depots_.size() == depots_.capacity()) // then we reallocate and
148 { // must update references
149 depots_.reserve(depots_.size() + 1);
150 for (auto &depot : depots_)
151 nodes[depot.idx()] = &depot;
152 }
153
154 node = &depots_.emplace_back(node->client());
155 }
156
157 if (numTrips() > maxTrips())
158 throw std::invalid_argument("Vehicle cannot perform this many trips.");
159
160 nodes.insert(nodes.begin() + idx, node);
161 node->assign(this, idx, nodes[idx - 1]->trip());
162
163 for (size_t after = idx; after != nodes.size(); ++after)
164 {
165 nodes[after]->idx_ = after;
166 if (isDepot) // then we need to bump each following trip index
167 nodes[after]->trip_++;
168 }
169}
170
171void Route::push_back(Node *node) { insert(nodes.size() - 1, node); }
172

Callers 10

test_route_insertFunction · 0.95
PYBIND11_MODULEFunction · 0.45
applyMethod · 0.45
applyMethod · 0.45
applyGroupMovesMethod · 0.45
perturbMethod · 0.45
applyMethod · 0.45
applyMethod · 0.45
conf.pyFile · 0.45

Calls 8

clientMethod · 0.80
reserveMethod · 0.80
idxMethod · 0.80
assignMethod · 0.80
tripMethod · 0.80
sizeMethod · 0.45
numDepotsMethod · 0.45
beginMethod · 0.45

Tested by 1

test_route_insertFunction · 0.76