Tests that the parsed data from the "OkSmall" instance is correct.
()
| 50 | |
| 51 | |
| 52 | def test_reading_OkSmall_instance(): |
| 53 | """ |
| 54 | Tests that the parsed data from the "OkSmall" instance is correct. |
| 55 | """ |
| 56 | data = read("data/OkSmall.txt") |
| 57 | |
| 58 | # From the DIMENSION, VEHICLES, and CAPACITY fields in the file. |
| 59 | assert_equal(data.num_clients, 4) |
| 60 | assert_equal(data.num_vehicles, 3) |
| 61 | assert_equal(data.num_vehicle_types, 1) |
| 62 | assert_equal(data.vehicle_type(0).capacity, [10]) |
| 63 | |
| 64 | # From the NODE_COORD_SECTION in the file |
| 65 | expected = [ |
| 66 | (2334, 726), |
| 67 | (226, 1297), |
| 68 | (590, 530), |
| 69 | (435, 718), |
| 70 | (1191, 639), |
| 71 | ] |
| 72 | |
| 73 | for loc in range(data.num_locations): |
| 74 | assert_equal(data.location(loc).x, expected[loc][0]) |
| 75 | assert_equal(data.location(loc).y, expected[loc][1]) |
| 76 | |
| 77 | # From the EDGE_WEIGHT_SECTION in the file |
| 78 | expected = [ |
| 79 | [0, 1544, 1944, 1931, 1476], |
| 80 | [1726, 0, 1992, 1427, 1593], |
| 81 | [1965, 1975, 0, 621, 1090], |
| 82 | [2063, 1433, 647, 0, 818], |
| 83 | [1475, 1594, 1090, 828, 0], |
| 84 | ] |
| 85 | |
| 86 | # For instances read through VRPLIB/read(), distance is duration. So the |
| 87 | # dist/durs should be the same as the expected edge weights above. |
| 88 | assert_equal(data.num_profiles, 1) |
| 89 | assert_equal(data.distance_matrix(profile=0), expected) |
| 90 | assert_equal(data.duration_matrix(profile=0), expected) |
| 91 | |
| 92 | # From the DEMAND_SECTION in the file |
| 93 | expected = [0, 5, 5, 3, 5] |
| 94 | |
| 95 | for loc in range(1, data.num_locations): # excl. depot (has no delivery) |
| 96 | assert_equal(data.location(loc).delivery, [expected[loc]]) |
| 97 | |
| 98 | # From the TIME_WINDOW_SECTION in the file |
| 99 | expected = [ |
| 100 | (0, 45000), |
| 101 | (15600, 22500), |
| 102 | (12000, 19500), |
| 103 | (8400, 15300), |
| 104 | (12000, 19500), |
| 105 | ] |
| 106 | |
| 107 | for loc in range(data.num_depots, data.num_locations): |
| 108 | assert_equal(data.location(loc).tw_early, expected[loc][0]) |
| 109 | assert_equal(data.location(loc).tw_late, expected[loc][1]) |