|
| 1 | +## Group B - Exercise 4 |
| 2 | + |
| 3 | +### Context |
| 4 | +In this exercise, we examine the *Heterogenous Capacitated Vehicle Routing Problem* (HCVRP). |
| 5 | + |
| 6 | +A company is about to deliver specific quantities of its product to its clients. Initially, the product in its totality is stored in the company storage. |
| 7 | + |
| 8 | +To deliver the product, the company uses a number of vehicles, possibly of different capacities. |
| 9 | + |
| 10 | +Below we can see the data for an instance of this problem, for 8 vehicles and 20 clients: |
| 11 | + |
| 12 | + vehicles([35, 40, 55, 15, 45, 25, 85, 55]). |
| 13 | + |
| 14 | + clients([c(15, 77, 97), c(23, -28, 64), c(14, 77, -39), |
| 15 | + c(13, 32, 33), c(18, 32, 8), c(18, -42, 92), |
| 16 | + c(19, -8, -3), c(10, 7, 14), c(18, 82, -17), |
| 17 | + c(20, -48, -13), c(15, 53, 82), c(19, 39, -27), |
| 18 | + c(17, -48, -13), c(12, 53, 82), c(11, 39, -27), |
| 19 | + c(15, -48, -13), c(25, 53, 82), c(14, -39, 7), |
| 20 | + c(22, 17, 8), c(23, -38, -7)]). |
| 21 | + |
| 22 | +This data are defined in [`hcvrp_data.pl`](./hcvrp_data.pl). |
| 23 | + |
| 24 | +- The list defined in `vehicles/1` represents the capacities of the company's vehicles. |
| 25 | +- The list defined in `clients/1` contains `c(D, X, Y)` tuples, one for each client: |
| 26 | + - `D` is the quantity ordered by this client. |
| 27 | + - `X` & `Y` are the client coordinates. |
| 28 | + |
| 29 | +The task is to optimally deliver the ordered produt quantity to each client: |
| 30 | +- Each vehicle **starts from the storage**, having loaded the total quantity ordered by the clients it is about to serve, which **cannot exceed its total capacity**.\ |
| 31 | +After the end of the route, the vehicle **returns to the storage**. |
| 32 | +- The storage coordinates are (0, 0). The clients are connected with each other (and with the storage), with **straight line roads**. Therefore, the distance between two clients or between a client and the storage, is their **[Euclidean Distance](https://en.wikipedia.org/wiki/Euclidean_distance)**. |
| 33 | +- The **Cost** of a route is the **total distance travelled by the vehicles**. |
| 34 | +To pretty-print the cost of a route, we mutliply it by 1000 and round it up/down to the nearest integer. |
| 35 | + |
| 36 | +### Task |
| 37 | +Implement an `hcvrp(NCl, NVe, Timeout, Solution, Cost, Time)` predicate: |
| 38 | +- The first `NCl` clients from the predefined data will be used. |
| 39 | +- The first `NVe` vehicles from the predefined data will be used. |
| 40 | +- `Timeout` is a time limit (in secs) to stop the execution and return the best solution found up to that point. |
| 41 | +- `Solution` is the best found solutiom, a list of lists. Each list represents the route of the corresponding vehicle: It contains the index numbers of the clients that will be served by this vehicle, in the order they will be served. Of course a vehicle may have no route, in which case its list will be empty. |
| 42 | +- `Cost` is the total cost of the solution, calculated as described above. |
| 43 | +- `Time` is the total CPU time elapsed. |
| 44 | + |
| 45 | +### Execution Examples |
| 46 | +- Input: |
| 47 | + |
| 48 | + ?- hcvrp(1, 1, 0, Solution, Cost, Time). |
| 49 | + |
| 50 | + Output: |
| 51 | + |
| 52 | + Found a solution with cost 247694 |
| 53 | + Solution = [[1]] |
| 54 | + Cost = 247694 |
| 55 | + Time = 0.0 |
| 56 | +*** |
| 57 | +- Input: |
| 58 | + |
| 59 | + ?- hcvrp(2, 1, 0, Solution, Cost, Time). |
| 60 | + |
| 61 | + Output: |
| 62 | + |
| 63 | + Found no solution with cost 0.0 .. 371541.0 |
| 64 | +*** |
| 65 | +- Input: |
| 66 | + |
| 67 | + ?- hcvrp(2, 2, 0, Solution, Cost, Time). |
| 68 | + |
| 69 | + Output: |
| 70 | + |
| 71 | + Found a solution with cost 303768 |
| 72 | + Found no solution with cost 0.0 .. 303767.0 |
| 73 | + Solution = [[], [2, 1]] |
| 74 | + Cost = 303768 |
| 75 | + Time = 0.0 |
| 76 | +*** |
| 77 | +- Input: |
| 78 | + |
| 79 | + ?- hcvrp(3, 2, 0, Solution, Cost, Time). |
| 80 | + |
| 81 | + Output: |
| 82 | + |
| 83 | + Found a solution with cost 485874 |
| 84 | + Found a solution with cost 476394 |
| 85 | + Found no solution with cost 0.0 .. 476393.0 |
| 86 | + Solution = [[3], [2, 1]] |
| 87 | + Cost = 476394 |
| 88 | + Time = 0.0 |
| 89 | +*** |
| 90 | +- Input: |
| 91 | + |
| 92 | + ?- hcvrp(4, 2, 0, Solution, Cost, Time). |
| 93 | + |
| 94 | + Output: |
| 95 | + |
| 96 | + Found a solution with cost 529519 |
| 97 | + Found a solution with cost 520954 |
| 98 | + Found no solution with cost 0.0 .. 520953.0 |
| 99 | + Solution = [[4, 3], [2, 1]] |
| 100 | + Cost = 520954 |
| 101 | + Time = 0.0 |
| 102 | +*** |
| 103 | +- Input: |
| 104 | + |
| 105 | + ?- hcvrp(5, 2, 0, Solution, Cost, Time). |
| 106 | + |
| 107 | + Output: |
| 108 | + |
| 109 | + Found no solution with cost 0.0 .. 1718544.0 |
| 110 | +*** |
| 111 | +- Input: |
| 112 | + |
| 113 | + ?- hcvrp(5, 3, 0, Solution, Cost, Time). |
| 114 | + |
| 115 | + Output: |
| 116 | + |
| 117 | + Found a solution with cost 606884 |
| 118 | + Found a solution with cost 572409 |
| 119 | + Found a solution with cost 569259 |
| 120 | + Found a solution with cost 552201 |
| 121 | + Found a solution with cost 541537 |
| 122 | + Found a solution with cost 526117 |
| 123 | + Found a solution with cost 523843 |
| 124 | + Found a solution with cost 506186 |
| 125 | + Found a solution with cost 488492 |
| 126 | + Found no solution with cost 0.0 .. 488491.0 |
| 127 | + Solution = [[], [5, 3], [4, 1, 2]] |
| 128 | + Cost = 488492 |
| 129 | + Time = 0.04 |
| 130 | +*** |
| 131 | +- Input: |
| 132 | + |
| 133 | + ?- hcvrp(8, 4, 0, Solution, Cost, Time). |
| 134 | + |
| 135 | + Output: |
| 136 | + |
| 137 | + Found a solution with cost 859115 |
| 138 | + Found a solution with cost 836986 |
| 139 | + Found a solution with cost 828848 |
| 140 | + Found a solution with cost 821892 |
| 141 | + Found a solution with cost 806634 |
| 142 | + Found a solution with cost 804930 |
| 143 | + Found a solution with cost 726824 |
| 144 | + Found a solution with cost 712619 |
| 145 | + Found a solution with cost 702248 |
| 146 | + Found no solution with cost 0.0 .. 702247.0 |
| 147 | + Solution = [[3, 1], [7, 5], [4, 6, 2], [8]] |
| 148 | + Cost = 702248 |
| 149 | + Time = 1.99 |
| 150 | + |
| 151 | +<small> |
| 152 | +The costs of the intermediate solutions, as well as the final solution routes may differ, but the cost of the final solution must be the same. |
| 153 | +</small> |
| 154 | + |
| 155 | +### Implementation |
| 156 | +- The `hcvrp` predicate is implemented in `hcvrp.pl`, along with several helper predicates. |
| 157 | +- The `clients/1` and `vehicles/1` predicates were pre-defined in `hcvrp_data.pl`. |
0 commit comments