* Solution(data: ProblemData, routes: list[Route] | list[list[int]]) * * Encodes VRP solutions. * * Parameters * ---------- * data * Data instance. * routes * Route list to use. Can be a list of :class:`~Route` objects, or a lists * of client visits. In case of the latter, all routes are assigned * vehicles of the first type. That need not be a feasible assignment! * *
| 37 | * type have been used, or when a client is visited more than once. |
| 38 | */ |
| 39 | class Solution |
| 40 | { |
| 41 | using Client = size_t; |
| 42 | using Depot = size_t; |
| 43 | using VehicleType = size_t; |
| 44 | |
| 45 | using Routes = std::vector<Route>; |
| 46 | using Neighbours = std::vector<std::optional<std::pair<Client, Client>>>; |
| 47 | |
| 48 | size_t numClients_ = 0; // Number of clients in the solution |
| 49 | size_t numMissingClients_ = 0; // Number of required but missing clients |
| 50 | Distance distance_ = 0; // Total travel distance over all routes |
| 51 | Cost distanceCost_ = 0; // Total cost of all routes' travel distance |
| 52 | Duration duration_ = 0; // Total duration over all routes |
| 53 | Duration overtime_ = 0; // Total overtime over all routes |
| 54 | Cost durationCost_ = 0; // Total cost of all routes' duration |
| 55 | Distance excessDistance_ = 0; // Total excess distance over all routes |
| 56 | std::vector<Load> excessLoad_; // Total excess load over all routes |
| 57 | Cost fixedVehicleCost_ = 0; // Fixed cost of all used vehicles |
| 58 | Cost prizes_ = 0; // Total collected prize value |
| 59 | Cost uncollectedPrizes_ = 0; // Total uncollected prize value |
| 60 | Duration timeWarp_ = 0; // Total time warp over all routes |
| 61 | bool isGroupFeas_ = true; // Is feasible w.r.t. client groups? |
| 62 | |
| 63 | Routes routes_; |
| 64 | Neighbours neighbours_; // client [pred, succ] pairs, null if unassigned |
| 65 | |
| 66 | // Determines the [pred, succ] pairs for assigned clients. |
| 67 | void makeNeighbours(); |
| 68 | |
| 69 | // Evaluates this solution's characteristics. |
| 70 | void evaluate(ProblemData const &data); |
| 71 | |
| 72 | // These are only available within a solution; from the outside a solution |
| 73 | // is immutable. |
| 74 | Solution &operator=(Solution const &other) = default; |
| 75 | Solution &operator=(Solution &&other) = default; |
| 76 | |
| 77 | public: |
| 78 | // Solution is empty when it has no routes and no clients. |
| 79 | [[nodiscard]] bool empty() const; |
| 80 | |
| 81 | /** |
| 82 | * Number of routes in this solution. |
| 83 | */ |
| 84 | [[nodiscard]] size_t numRoutes() const; |
| 85 | |
| 86 | /** |
| 87 | * Number of trips in this solution. |
| 88 | */ |
| 89 | [[nodiscard]] size_t numTrips() const; |
| 90 | |
| 91 | /** |
| 92 | * Number of clients in this solution. |
| 93 | * |
| 94 | * .. warning:: |
| 95 | * |
| 96 | * An empty solution typically indicates that there is a significant |
no outgoing calls