Tests that local search works on a small prize-collecting instance.
(prize_collecting)
| 119 | |
| 120 | |
| 121 | def test_prize_collecting(prize_collecting): |
| 122 | """ |
| 123 | Tests that local search works on a small prize-collecting instance. |
| 124 | """ |
| 125 | rng = RandomNumberGenerator(seed=42) |
| 126 | cost_evaluator = CostEvaluator([1], 1, 0) |
| 127 | |
| 128 | sol = Solution.make_random(prize_collecting, rng) |
| 129 | sol_cost = cost_evaluator.penalised_cost(sol) |
| 130 | |
| 131 | neighbours = compute_neighbours(prize_collecting) |
| 132 | ls = LocalSearch(prize_collecting, rng, neighbours) |
| 133 | ls.add_node_operator(Exchange10(prize_collecting)) # relocate |
| 134 | ls.add_node_operator(Exchange11(prize_collecting)) # swap |
| 135 | |
| 136 | improved = ls.search(sol, cost_evaluator) |
| 137 | improved_cost = cost_evaluator.penalised_cost(improved) |
| 138 | |
| 139 | assert_(improved.num_clients() < prize_collecting.num_clients) |
| 140 | assert_(improved_cost < sol_cost) |
| 141 | |
| 142 | |
| 143 | def test_cpp_shuffle_results_in_different_solution(rc208): |
nothing calls this directly
no test coverage detected