* SearchSpace(data: ProblemData, neighbours: list[list[int]]) * * Manages a search space for the local search. The search space is granular, * around the given neighbourhood, and uses the concept of promising clients * to determine which client's neighbourhoods to search. It can also be used * to define a (randomised) search ordering for clients, routes, and vehicle * types. */
| 20 | * types. |
| 21 | */ |
| 22 | class SearchSpace |
| 23 | { |
| 24 | public: |
| 25 | using Neighbours = std::vector<std::vector<size_t>>; |
| 26 | |
| 27 | private: |
| 28 | // Neighborhood restrictions: list of nearby clients for each client (size |
| 29 | // numLocations, but nothing is stored for the depots!). |
| 30 | Neighbours neighbours_; |
| 31 | |
| 32 | // Tracks clients that can likely be improved by local search operators. |
| 33 | DynamicBitset promising_; |
| 34 | |
| 35 | // Client order used for node-based search. |
| 36 | std::vector<size_t> clientOrder_; |
| 37 | |
| 38 | // Route order used for route-based search. |
| 39 | std::vector<size_t> routeOrder_; |
| 40 | |
| 41 | // Vehicle type order - pairs of [veh type, offset] - used for empty route |
| 42 | // search. |
| 43 | std::vector<std::pair<size_t, size_t>> vehTypeOrder_; |
| 44 | |
| 45 | public: |
| 46 | SearchSpace(ProblemData const &data, Neighbours neighbours); |
| 47 | |
| 48 | /** |
| 49 | * Set the neighbourhood structure of this search space. For each client, |
| 50 | * the neighbourhood structure is a vector of nearby clients. Depots have |
| 51 | * no nearby clients. |
| 52 | */ |
| 53 | void setNeighbours(Neighbours neighbours); |
| 54 | |
| 55 | /** |
| 56 | * Returns the current neighbourhood structure. |
| 57 | */ |
| 58 | Neighbours const &neighbours() const; |
| 59 | |
| 60 | /** |
| 61 | * Returns the vector of neighbours for a given client. |
| 62 | */ |
| 63 | std::vector<size_t> const &neighboursOf(size_t client) const; |
| 64 | |
| 65 | /** |
| 66 | * Returns whether the given client is a promising evaluation candidate. |
| 67 | */ |
| 68 | bool isPromising(size_t client) const; |
| 69 | |
| 70 | /** |
| 71 | * Marks the given client as promising. |
| 72 | */ |
| 73 | void markPromising(size_t client); |
| 74 | |
| 75 | /** |
| 76 | * Convenient overload for route nodes. Since this is typically used during |
| 77 | * insert and removals, this method marks the given node and its direct |
| 78 | * client neighbours as promising. The node must currently be in a route. |
| 79 | * Does not mark depots. |
no outgoing calls