Stopping criteria¶
The pyvrp.stop module contains the various stopping criteria the pyvrp package ships with.
These can be used to stop the IteratedLocalSearch whenever some criterion is met: for example, when some maximum number of iterations or run-time is exceeded.
All stopping criteria implement the StoppingCriterion protocol.
- class StoppingCriterion(*args, **kwargs)[source]¶
Protocol that stopping criteria must implement.
Methods
__call__(best_cost)When called, this stopping criterion should return True if the algorithm should stop, and False otherwise.
Returns the fraction of the stopping criterion's budget that remains.
- fraction_remaining() float | None[source]¶
Returns the fraction of the stopping criterion’s budget that remains.
- Returns:
A value between 0 and 1, where 0 means the stopping criterion is met and 1 means it is not. If the stopping criterion does not have a meaningful interpretation of remaining fraction, it should return None.
- Return type:
float | None
- class FirstFeasible[source]¶
Terminates the search after a feasible solution has been observed.
Methods
__call__(best_cost)Call self as a function.
fraction_remaining
- class MaxIterations(max_iterations: int)[source]¶
Criterion that stops after a maximum number of iterations.
Methods
__call__(best_cost)Call self as a function.
fraction_remaining
- class MaxRuntime(max_runtime: float)[source]¶
Criterion that stops after a specified maximum runtime (in seconds).
Methods
__call__(best_cost)Call self as a function.
fraction_remaining
- class MultipleCriteria(criteria: list[StoppingCriterion])[source]¶
Simple aggregate class that manages multiple stopping criteria at once.
Methods
__call__(best_cost)Call self as a function.
fraction_remaining