Problem Definition

class evovaq.problem.Problem(n_params: int, param_bounds: Union[tuple, list[tuple]], obj_function: Callable, init_range: Optional[Union[tuple, list[tuple]]] = None)[source]

Bases: object

Class used to define the minimization problem to be solved.

Parameters:
  • n_params – Number of real parameters to be optimized.

  • param_bounds – Parameter bounds expressed as a tuple (min, max) or as a list of these tuples of n_params size.

  • obj_function – The objective function to be minimized defined as obj_function(params, *args) -> float , where params is an array with (n_params,) shape and args is a tuple of other fixed parameters needed to specify the function.

  • init_range – Initial sampling range used to generate random parameter values before optimization. It can be a single tuple (min, max) applied uniformly, or a list of such tuples of length n_params for individual ranges. If set to None, the initial range is inherited from param_bounds. If any parameter bound contains None, the corresponding initial range defaults to (-1, 1) for that parameter.

check_bounds(params: ndarray) ndarray[source]

Check if the solution params satisfies the parameters bounds set in param_bounds.

Parameters:

params – A possible solution as array of real parameters with (n_params,) shape.

Returns:

A possible solution with clipped values according to param_bounds.

evaluate_fitness(params: ndarray) float[source]

Evaluate the fitness function of the given parameters.

Parameters:

params – A possible solution as array of real parameters with (n_params,) shape.

Returns:

Value of the objective function.

generate_individual() ndarray[source]

Generate a random possible solution, called individual.

Returns:

A possible solution randomly generated from param_bounds.

generate_random_pop(pop_size: int) ndarray[source]

Generate a population of possible random solutions.

Parameters:

pop_size – Population size.

Returns:

A set of possible solutions randomly generated from param_bounds.