Problem Definitions

The pycellga.problems package provides a collection of problem definitions for optimization tasks. Each problem is structured as a class inheriting from a common abstract base, ensuring consistency and flexibility across various types of optimization tasks. This module includes both single-objective and multi-objective problems, designed to serve as benchmarks or examples for testing and applying genetic algorithms.

Abstract Problem Base

This module defines an abstract base class, AbstractProblem, which provides a standard interface for defining optimization problems. By inheriting from this base class, users can create custom problem definitions that are compatible with the rest of the pycellga framework. Key components of the base class include methods for evaluating objective values, setting constraints, and managing design variables.

class AbstractProblem(design_variables: int | List[str], bounds: List[Tuple[float, float]], objectives: str | int | List[str], constraints: str | int | List[str] = [])[source]

Bases: Problem, ABC

Abstract base class for optimization problems.

__init__(design_variables: int | List[str], bounds: List[Tuple[float, float]], objectives: str | int | List[str], constraints: str | int | List[str] = [])[source]

Initialize the problem with variables, bounds, objectives, and constraints.

Parameters:
  • design_variables (int or List[str]) – If an integer, it specifies the number of design variables. If a list of strings, it specifies the names of design variables.

  • bounds (List[Tuple[float, float]]) – Bounds for each design variable as (min, max).

  • objectives (str, int, or List[str]) – Objectives for optimization, e.g., “minimize” or “maximize”.

  • constraints (str, int, or List[str], optional) – Constraints for the problem (default is an empty list).

evaluate(x, out, *args, **kwargs)[source]

Evaluate function for compatibility with pymoo’s optimizer.

Parameters:
  • x (numpy.ndarray) – Array of input variables.

  • out (dict) – Dictionary to store the output fitness values.

abstract f(x: List[Any]) float[source]

Abstract method for evaluating the fitness of a solution.

Parameters:

x (list) – List of design variable values.

Returns:

Fitness value.

Return type:

float

Single-Objective Problems

The single_objective subpackage includes a set of benchmark functions commonly used to evaluate optimization algorithms in terms of convergence speed, accuracy, and robustness. These problems are designed for scenarios where only one objective needs to be optimized.