porcupy.cpo

Functions

cpo(fobj, lb, ub[, pop_size, max_iter, f_ieqcons, verbose])

Crested Porcupine Optimizer (CPO) for optimization problems.

Module Contents

porcupy.cpo.cpo(fobj, lb, ub, pop_size=30, max_iter=100, f_ieqcons=None, verbose=False)[source]

Crested Porcupine Optimizer (CPO) for optimization problems.

This function implements the CPO algorithm, a nature-inspired metaheuristic that mimics the defensive behaviors of crested porcupines (sight, sound, odor, physical attack) to balance exploration and exploitation, with cyclic population reduction for convergence.

Parameters:
  • fobj (callable) – Objective function to minimize. Takes a 1D numpy array as input and returns a scalar.

  • lb (list or array-like) – Lower bounds for each dimension of the search space.

  • ub (list or array-like) – Upper bounds for each dimension of the search space.

  • pop_size (int, optional) – Number of search agents (porcupines) in the initial population (default: 30).

  • max_iter (int, optional) – Maximum number of iterations (default: 100).

  • f_ieqcons (callable, optional) – Constraint function returning a 1D array of inequality constraints (g(x) >= 0). Infeasible solutions are assigned infinite fitness (default: None).

  • verbose (bool, optional) – If True, print progress information for each iteration (default: False).

Returns:

  • best_pos (ndarray) – Best solution found (1D array of length dim).

  • best_cost (float) – Best fitness value found.

  • cost_history (ndarray) – Best fitness value recorded at each iteration (1D array of length max_iter).

Raises:

ValueError – If lb and ub have different lengths, pop_size or max_iter is non-positive, or fobj is not callable.

Notes

The CPO algorithm is based on the paper “Crested Porcupine Optimizer: A new nature-inspired metaheuristic” by Mohamed Abdel-Basset et al. It uses four defensive mechanisms and cyclic population reduction to optimize complex problems.