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.

fraction_remaining()

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

__call__(best_cost: float) bool[source]

When called, this stopping criterion should return True if the algorithm should stop, and False otherwise.

Parameters:
best_cost: float

Cost of current best solution.

Returns:

True if the algorithm should stop, False otherwise.

Return type:

bool

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

class NoImprovement(max_iterations: int)[source]

Criterion that stops if the best solution has not been improved for a fixed number of iterations.

Parameters:
max_iterations: int

The maximum number of non-improving iterations.

Methods

__call__(best_cost)

Call self as a function.

fraction_remaining