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

Method load

pyvrp/cpp/search/Solution.cpp:27–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27void Solution::load(pyvrp::Solution const &solution)
28{
29 // Determine offsets for vehicle types.
30 std::vector<size_t> vehicleOffset(data_.numVehicleTypes(), 0);
31 for (size_t vehType = 1; vehType < data_.numVehicleTypes(); vehType++)
32 {
33 auto const prevAvail = data_.vehicleType(vehType - 1).numAvailable;
34 vehicleOffset[vehType] = vehicleOffset[vehType - 1] + prevAvail;
35 }
36
37 for (auto const &solRoute : solution.routes())
38 {
39 // Determine index of next route of this type to load, where we rely
40 // on solution to be valid to not exceed the number of vehicles per
41 // vehicle type.
42 auto const idx = vehicleOffset[solRoute.vehicleType()]++;
43 auto &route = routes[idx];
44
45 if (route == solRoute) // then the current route is still OK and we
46 continue; // can skip inserting and updating
47
48 // Else we need to clear the route and insert the updated route from
49 // the solution.
50 route.clear();
51
52 // Routes use a representation with nodes for each client, reload depot
53 // (one per trip), and start/end depots. The start depot doubles as the
54 // reload depot for the first trip.
55 route.reserve(solRoute.size() + solRoute.numTrips() + 1);
56
57 for (size_t tripIdx = 0; tripIdx != solRoute.numTrips(); ++tripIdx)
58 {
59 auto const &trip = solRoute.trip(tripIdx);
60
61 if (tripIdx != 0) // then we first insert a trip delimiter.
62 {
63 Route::Node depot = {trip.startDepot()};
64 route.push_back(&depot);
65 }
66
67 for (auto const client : trip)
68 route.push_back(&nodes[client]);
69 }
70
71 route.update();
72 }
73
74 // Finally, we clear any routes that we have not re-used or inserted from
75 // the solution.
76 size_t firstOfType = 0;
77 for (size_t vehType = 0; vehType != data_.numVehicleTypes(); ++vehType)
78 {
79 auto const numAvailable = data_.vehicleType(vehType).numAvailable;
80 auto const firstOfNextType = firstOfType + numAvailable;
81 for (size_t idx = vehicleOffset[vehType]; idx != firstOfNextType; ++idx)
82 routes[idx].clear();
83
84 firstOfType = firstOfNextType;

Callers 5

test_load_unloadFunction · 0.95
test_nodes_routes_accessFunction · 0.95

Calls 10

numVehicleTypesMethod · 0.80
reserveMethod · 0.80
tripMethod · 0.80
push_backMethod · 0.80
vehicleTypeMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45
numTripsMethod · 0.45
startDepotMethod · 0.45
updateMethod · 0.45

Tested by 5

test_load_unloadFunction · 0.76
test_nodes_routes_accessFunction · 0.76