Tests that a small VRPLIB-style instance is correctly parsed.
()
| 122 | |
| 123 | |
| 124 | def test_reading_vrplib_instance(): |
| 125 | """ |
| 126 | Tests that a small VRPLIB-style instance is correctly parsed. |
| 127 | """ |
| 128 | data = read("data/E-n22-k4.txt", round_func="dimacs") |
| 129 | |
| 130 | assert_equal(data.num_clients, 21) |
| 131 | assert_equal(data.num_depots, 1) |
| 132 | assert_equal(data.num_locations, 22) |
| 133 | assert_equal(data.vehicle_type(0).capacity, [60_000]) |
| 134 | |
| 135 | assert_equal(len(data.depots()), data.num_depots) |
| 136 | assert_equal(len(data.clients()), data.num_clients) |
| 137 | assert_equal(data.num_locations, data.num_depots + data.num_clients) |
| 138 | |
| 139 | # Coordinates are scaled by 10 to align with 1 decimal distance precision |
| 140 | assert_equal(data.location(0).x, 1450) # depot [x, y] location |
| 141 | assert_equal(data.location(0).y, 2150) |
| 142 | |
| 143 | assert_equal(data.location(1).x, 1510) # first customer [x, y] location |
| 144 | assert_equal(data.location(1).y, 2640) |
| 145 | |
| 146 | # The data file specifies distances as 2D Euclidean. We take that and |
| 147 | # should compute integer equivalents with up to one decimal precision. |
| 148 | # For depot -> first customer: |
| 149 | # For depot -> first customer: |
| 150 | # dX = 151 - 145 = 6 |
| 151 | # dY = 264 - 215 = 49 |
| 152 | # dist = sqrt(dX^2 + dY^2) = 49.37 |
| 153 | # int(10 * dist) = 493 |
| 154 | assert_equal(data.num_profiles, 1) |
| 155 | distances = data.distance_matrix(profile=0) |
| 156 | assert_equal(distances[0, 1], 493) |
| 157 | assert_equal(distances[1, 0], 493) |
| 158 | |
| 159 | # This is a CVRP instance, so all other fields should have default values. |
| 160 | for loc in range(1, data.num_locations): |
| 161 | assert_equal(data.location(loc).service_duration, 0) |
| 162 | assert_equal(data.location(loc).tw_early, 0) |
| 163 | assert_equal(data.location(loc).tw_late, np.iinfo(np.int64).max) |
| 164 | assert_equal(data.location(loc).release_time, 0) |
| 165 | assert_equal(data.location(loc).prize, 0) |
| 166 | assert_equal(data.location(loc).required, True) |
| 167 | |
| 168 | |
| 169 | def test_warns_about_scaling_issues(): |