Tests that solving an instance with custom solver parameters works as expected by checking how solutions are accepted.
(rc208)
| 87 | |
| 88 | |
| 89 | def test_solve_custom_params(rc208): |
| 90 | """ |
| 91 | Tests that solving an instance with custom solver parameters works as |
| 92 | expected by checking how solutions are accepted. |
| 93 | """ |
| 94 | |
| 95 | def monotonically_decreasing(arr) -> np.bool_: |
| 96 | return np.all(np.diff(arr) <= 0) |
| 97 | |
| 98 | # Configure ILS to only accept improving solutions by setting |
| 99 | # ``history_length=1``. |
| 100 | params = SolveParams(IteratedLocalSearchParams(history_length=1)) |
| 101 | res = solve(rc208, stop=MaxIterations(20), params=params) |
| 102 | |
| 103 | # The current costs should now be monotonically decreasing. The first datum |
| 104 | # is skipped because it's an empty initial solution with penalised cost 0. |
| 105 | costs = [datum.current_cost for datum in res.stats.data[1:]] |
| 106 | assert_(monotonically_decreasing(costs)) |
nothing calls this directly
no test coverage detected