|
15 | 15 |
|
16 | 16 | import static com.google.common.truth.Truth.assertThat; |
17 | 17 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 18 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
18 | 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
19 | 20 | import static org.junit.jupiter.api.Assertions.assertTrue; |
20 | 21 |
|
@@ -325,6 +326,37 @@ public void testRoutingModel_addDisjunction() { |
325 | 326 | assertEquals(8, solution.objectiveValue()); |
326 | 327 | } |
327 | 328 |
|
| 329 | + @Test |
| 330 | + public void testAllowedVehicles() { |
| 331 | + final IndexManager manager = new IndexManager(2, 2, 0); |
| 332 | + assertNotNull(manager); |
| 333 | + final Model model = new Model(manager); |
| 334 | + assertNotNull(model); |
| 335 | + |
| 336 | + // out of range vehicle index is allowed. |
| 337 | + model.setAllowedVehiclesForIndex(new int[] {13}, 1); |
| 338 | + assertFalse(model.isVehicleAllowedForIndex(0, 1)); |
| 339 | + assertFalse(model.isVehicleAllowedForIndex(1, 1)); |
| 340 | + assertTrue(model.isVehicleAllowedForIndex(13, 1)); |
| 341 | + |
| 342 | + // empty array means any vehicles are allowed. |
| 343 | + model.setAllowedVehiclesForIndex(new int[] {}, 1); |
| 344 | + assertTrue(model.isVehicleAllowedForIndex(0, 1)); |
| 345 | + assertTrue(model.isVehicleAllowedForIndex(1, 1)); |
| 346 | + assertTrue(model.isVehicleAllowedForIndex(42, 1)); |
| 347 | + |
| 348 | + // only allow first vehicle for node 1. |
| 349 | + model.setAllowedVehiclesForIndex(new int[] {0}, 1); |
| 350 | + assertTrue(model.isVehicleAllowedForIndex(0, 1)); |
| 351 | + assertFalse(model.isVehicleAllowedForIndex(1, 1)); |
| 352 | + assertFalse(model.isVehicleAllowedForIndex(2, 1)); |
| 353 | + |
| 354 | + final Assignment solution = model.solve(null); |
| 355 | + assertNotNull(solution); |
| 356 | + assertEquals(1, solution.value(model.nextVar(model.start(0)))); |
| 357 | + assertEquals(2, model.getVehicleClassesCount()); |
| 358 | + } |
| 359 | + |
328 | 360 | @Test |
329 | 361 | public void testRoutingModel_addConstantDimension() { |
330 | 362 | final IndexManager manager = new IndexManager(10, 1, 0); |
|
0 commit comments