Skip to main content

Black Widow Optimization

Project description

Black Widow Optimization

gh-actions-ci GitHub license PyPI pyversions PyPi Version

From the abstract: ...a novel meta-heuristic algorithm suitable for continuous nonlinear optimization problems. The proposed method, Black Widow Optimization Algorithm (BWO), is inspired by the unique mating behavior of black widow spiders. This method includes an exclusive stage, namely, cannibalism. Due to this stage, species with inappropriate fitness are omitted from the circle, thus leading to early convergence. BWO algorithm is evaluated on 51 various benchmark functions to verify its efficiency in obtaining the optimal solutions for the problems. The obtained results indicate that the proposed algorithm has numerous advantages in different aspects such as early convergence and achieving optimized fitness value compared to other algorithms.


pip install bwo


pip install git+


As a simple example, let's find the minimum of the single objective sphere function availabel in the Landscapes Python package.

pip install landscapes

Next, let's import everything we need.

from bwo import minimize
from landscapes.single_objective import sphere

Now, we just need to call the minimize function. For this particular example, let's optimize across 5 degrees of freedom.

fbest, xbest = minimize(sphere, dof=5)

Where fbest is the best function value achieved during optimization, and xbest is the function input which yielded fbest.

You can also minimize a function given boundry constraints, represented by a list of tuples. Each tuple must follow the (min, max) format.

bounds = [(-1,1),(-2,2), (-3,3), (-4,4), (-5,5)]
fbest, xbest = minimize(sphere, bounds=bounds, disp=False)


minimize(func, x0=None, dof=None, bounds=None, pp=0.6, cr=0.44, pm=0.4, npop=10, disp=False, maxiter=50)

  • func (callable) : The objective function to be minimized.
  • x0 (list) : Initial guess (optional).
  • dof (int) : degrees of freedom (optional)
  • bounds(list of tuples) : boundary constraints as specified as a list of (xi_min, xi_max) tuples.
  • pp (float) : procreating percentage [0, 1].
  • cr (float) : cannibalism rate [0, 1].
  • pm (float) : mutation rate [0, 1].
  • maxiter (int) : maximum number of iterations.
  • disp (bool) : output intermediate results at each iteration.


author = {Hayyolalam, Vahideh and Pourhaji Kazem, Ali Asghar},
year = {2019},
month = {10},
pages = {103249},
title = {Black Widow Optimization Algorithm: A novel meta-heuristic approach for solving engineering optimization problems ✩},
volume = {87},
journal = {Engineering Applications of Artificial Intelligence},
doi = {10.1016/j.engappai.2019.103249}

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bwo, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size bwo-0.1.2-py3-none-any.whl (6.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size bwo-0.1.2.tar.gz (5.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page