Stopping Criteria

The pycnp.stop module provides stopping criteria for controlling when the memetic algorithm terminates.

class StoppingCriterion

Protocol for algorithm stopping criteria.

__call__(best_obj_value: float) bool

Determines whether the algorithm should stop.

Parameters:

best_obj_value – The best objective value found so far.

Returns:

True if the stopping condition is met.

get_name() str

Returns the name of the stopping criterion.

Returns:

The criterion name as a string.

class MaxIterations(max_iterations: int)[source]

A stopping criterion based on the maximum number of iterations.

The algorithm stops when the number of iterations reaches a predefined limit.

__call__(best_obj_value: float) bool[source]

Checks if the maximum number of iterations has been reached.

Increments the iteration counter on each call.

Parameters:

best_obj_value (float) – The current best objective value (not used by this criterion).

Returns:

True if the current number of iterations has reached the maximum, False otherwise.

Return type:

bool

get_name() str[source]

Returns the name of the stopping criterion.

Returns:

The name of the criterion.

Return type:

str

class MaxRuntime(max_runtime_in_sec: float)[source]

A stopping criterion based on the maximum allowed runtime.

The algorithm stops when the elapsed time since initialization exceeds a predefined limit.

__call__(best_obj_value: float) bool[source]

Checks if the maximum runtime has been exceeded.

Parameters:

best_obj_value (float) – The current best objective value (not used by this criterion).

Returns:

True if the elapsed time is greater than or equal to the maximum allowed runtime, False otherwise.

Return type:

bool

get_name() str[source]

Returns the name of the stopping criterion.

Returns:

The name of the criterion.

Return type:

str

class NoImprovement(max_idle_iterations: int)[source]

A stopping criterion based on the number of iterations without improvement.

The algorithm stops if the best objective value has not improved for a specified number of consecutive iterations.

__call__(best_obj_value: float) bool[source]

Checks if the no-improvement condition is met.

Compares the current best objective value with the one from the previous iteration. If there is no improvement, the idle iteration counter is incremented.

Parameters:

best_obj_value (float) – The best objective value found so far.

Returns:

True if the number of idle iterations has reached the maximum, False otherwise.

Return type:

bool

get_name() str[source]

Returns the name of the stopping criterion.

Returns:

The name of the criterion.

Return type:

str