Stopping criteria

The pyvrp.stop module contains the various stopping criteria the pyvrp package ships with. These can be used to stop the GeneticAlgorithm’s’ search 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.

__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 MaxIterations(max_iterations: int)[source]

Criterion that stops after a maximum number of iterations.

Methods

__call__(best_cost)

Call self as a function.

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.

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.

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.