Tests that the insert_cost() method works correctly on a few basic cases.
(ok_small)
| 29 | |
| 30 | |
| 31 | def test_insert_cost(ok_small): |
| 32 | """ |
| 33 | Tests that the insert_cost() method works correctly on a few basic cases. |
| 34 | """ |
| 35 | cost_eval = CostEvaluator([1], 1, 0) |
| 36 | route = make_search_route(ok_small, [1, 2]) |
| 37 | |
| 38 | # This adds arcs 1 -> 4 -> 2, and removes arcs 1 -> 2. The added distances |
| 39 | # is 1593 + 1090, the removed distance 1992. This also adds 5 additional |
| 40 | # delivery demand, which exceeds the vehicle capacity by 5, so we get an |
| 41 | # additional load penalty of 5. There is no time warp. Total delta cost: |
| 42 | # 1593 + 1090 - 1992 + 5 = 696. |
| 43 | assert_equal(insert_cost(Node(loc=4), route[1], ok_small, cost_eval), 696) |
| 44 | |
| 45 | # +5 load penalty, and delta dist is 1090 + 1475 - 1965 = 600. So total |
| 46 | # delta cost is 605 (again no time warp). |
| 47 | assert_equal(insert_cost(Node(loc=4), route[2], ok_small, cost_eval), 605) |
| 48 | |
| 49 | # Now we do have some time warp changes. +3 load penalty, delta dist is |
| 50 | # 1427 + 647 - 1992 = 82, but time warp increases because we cannot get to |
| 51 | # client 3 quick enough from client 1. In particular, we can arrive at |
| 52 | # client 1 at 15600, service for 360, and then travel to client 3 for |
| 53 | # duration 1427. Then we arrive at client 3 at 17387, which is after its |
| 54 | # closing time window of 15300. So we add 17387 - 15300 = 2087 time warp. |
| 55 | # Tallying it all up, total delta cost: |
| 56 | # 3 + 82 + 2087 = 2172. |
| 57 | assert_equal(insert_cost(Node(loc=3), route[1], ok_small, cost_eval), 2172) |
| 58 | |
| 59 | # +3 load penalty, delta dist is 621 + 2063 - 1965 = 719. Time warp |
| 60 | # increases because we have to visit clients 1 and 2 before we visit |
| 61 | # client 3. We get to client 1 at 15600, service for 360, travel to client |
| 62 | # 2 for 1992, service for 360, and then travel to client 3 for 621, where |
| 63 | # we arrive at 18933, after its closing time window of 15300. This adds |
| 64 | # 18933 - 15300 = 3633 time warp. Tallying it all up, total delta cost: |
| 65 | # 3 + 719 + 3633 = 4355. |
| 66 | assert_equal(insert_cost(Node(loc=3), route[2], ok_small, cost_eval), 4355) |
| 67 | |
| 68 | |
| 69 | def test_insert_cost_between_different_depots(ok_small_multi_depot): |
nothing calls this directly
no test coverage detected