MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / test_prize_collecting

Function test_prize_collecting

tests/search/test_LocalSearch.py:121–140  ·  view source on GitHub ↗

Tests that local search works on a small prize-collecting instance.

(prize_collecting)

Source from the content-addressed store, hash-verified

119
120
121def 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
143def test_cpp_shuffle_results_in_different_solution(rc208):

Callers

nothing calls this directly

Calls 7

add_node_operatorMethod · 0.95
searchMethod · 0.95
CostEvaluatorClass · 0.90
compute_neighboursFunction · 0.90
LocalSearchClass · 0.90
num_clientsMethod · 0.80

Tested by

no test coverage detected