Tests that solving a model initialised using the modelling interface finds the correct (known) solutions.
(ok_small)
| 319 | |
| 320 | |
| 321 | def test_model_and_solve(ok_small): |
| 322 | """ |
| 323 | Tests that solving a model initialised using the modelling interface |
| 324 | finds the correct (known) solutions. |
| 325 | """ |
| 326 | model = Model.from_data(ok_small) |
| 327 | res = model.solve(stop=MaxIterations(100), seed=0) |
| 328 | assert_equal(res.cost(), 9_155) |
| 329 | assert_(res.is_feasible()) |
| 330 | |
| 331 | # Now do the same thing, but model the instance using the modelling API. |
| 332 | # This should of course result in the same solution. |
| 333 | model = Model() |
| 334 | model.add_vehicle_type( |
| 335 | num_available=3, |
| 336 | capacity=10, |
| 337 | tw_early=0, |
| 338 | tw_late=45000, |
| 339 | ) |
| 340 | |
| 341 | depot = model.add_depot(x=2334, y=726) |
| 342 | clients = [ |
| 343 | model.add_client(226, 1297, 5, 0, 360, 15600, 22500), |
| 344 | model.add_client(590, 530, 5, 0, 360, 12000, 19500), |
| 345 | model.add_client(435, 718, 3, 0, 420, 8400, 15300), |
| 346 | model.add_client(1191, 639, 5, 0, 360, 12000, 19500), |
| 347 | ] |
| 348 | |
| 349 | edge_weights = [ |
| 350 | [0, 1544, 1944, 1931, 1476], |
| 351 | [1726, 0, 1992, 1427, 1593], |
| 352 | [1965, 1975, 0, 621, 1090], |
| 353 | [2063, 1433, 647, 0, 818], |
| 354 | [1475, 1594, 1090, 828, 0], |
| 355 | ] |
| 356 | |
| 357 | for idx, client in enumerate(clients, 1): |
| 358 | from_depot = edge_weights[0][idx] |
| 359 | to_depot = edge_weights[idx][0] |
| 360 | |
| 361 | model.add_edge(depot, client, from_depot, from_depot) |
| 362 | model.add_edge(client, depot, to_depot, to_depot) |
| 363 | |
| 364 | for other_idx, other in enumerate(clients, 1): |
| 365 | from_client = edge_weights[idx][other_idx] |
| 366 | to_client = edge_weights[other_idx][idx] |
| 367 | |
| 368 | model.add_edge(client, other, from_client, from_client) |
| 369 | model.add_edge(other, client, to_client, to_client) |
| 370 | |
| 371 | res = model.solve(stop=MaxIterations(100), seed=0) |
| 372 | |
| 373 | assert_(res.is_feasible()) |
| 374 | assert_equal(res.cost(), 9_155) |
| 375 | |
| 376 | |
| 377 | def test_model_solve_display_argument(ok_small, caplog): |
nothing calls this directly
no test coverage detected