Criterion that stops after a maximum number of iterations.
| 1 | class MaxIterations: |
| 2 | """ |
| 3 | Criterion that stops after a maximum number of iterations. |
| 4 | """ |
| 5 | |
| 6 | def __init__(self, max_iterations: int): |
| 7 | if max_iterations < 0: |
| 8 | raise ValueError("max_iterations < 0 not understood.") |
| 9 | |
| 10 | self._max_iters = max_iterations |
| 11 | self._curr_iter = 0 |
| 12 | |
| 13 | def __call__(self, best_cost: float) -> bool: |
| 14 | self._curr_iter += 1 |
| 15 | |
| 16 | return self._curr_iter > self._max_iters |
no outgoing calls