Skip to main content

pyMetaheuristic: A Comprehensive Python Library for Optimization

Project description

pyMetaheuristic

Introduction

pyMetaheuristic is a robust Python Library crafted to provide a wide range of metaheuristic algorithms, ideal for tackling complex optimization tasks. It encompasses a diverse mix of algorithms, from traditional to modern methods. For a detailed list of these metaheuristics and their demonstrations, refer to Section 3. The library is also equipped with a selection of test functions, useful for benchmarking and evaluating algorithm performance. Details on these functions can be found in Section 4. Getting started with pyMetaheuristic is straightforward. Install the package using pip and begin exploring the available algorithms and test functions, as outlined in Sections 1 and 2. Whether you're addressing intricate optimization problems or experimenting with different algorithms, pyMetaheuristic is your essential toolkit.

Each metaheuristic includes two parameters: 'start_init' and 'target_value'. By default, 'start_init' is set to None, but it can be assigned an initial guess in the form of a NumPy array. The default value of 'target_value' is also None. However, you can specify a continuous value for it. If during the iterations, the objective function reaches a value that is equal to or less than this specified 'target_value', the iterations will halt.

Usage

  1. Install
pip install pyMetaheuristic
  1. Import
# Import PSO
from pyMetaheuristic.algorithm import particle_swarm_optimization

# Import a Test Function. Available Test Functions: https://bit.ly/3KyluPp
from pyMetaheuristic.test_function import easom

# OR Define your Custom Function. The function input should be a list of values, 
# each value representing a dimension (x1, x2, ...xn) of the problem.
import numpy as np
def easom(variables_values = [0, 0]):
    x1, x2     = variables_values
    func_value = -np.cos(x1)*np.cos(x2)*np.exp(-(x1 - np.pi)**2 - (x2 - np.pi)**2)
    return func_value

# Run PSO
parameters = {
    'swarm_size': 250,
    'min_values': (-5, -5),
    'max_values': (5, 5),
    'iterations': 500,
    'decay': 0,
    'w': 0.9,
    'c1': 2,
    'c2': 2,
    'verbose': True,
    'start_init': None,
    'target_value': None
}
pso = particle_swarm_optimization(target_function = easom, **parameters)

# Print Solution
variables = pso[:-1]
minimum   = pso[ -1]
print('Variables: ', np.around(variables, 4) , ' Minimum Value Found: ', round(minimum, 4) )

# Plot Solution
from pyMetaheuristic.utils import graphs
plot_parameters = {
    'min_values': (-5, -5),
    'max_values': (5, 5),
    'step': (0.1, 0.1),
    'solution': [variables],
    'proj_view': '3D',
    'view': 'browser'
}
graphs.plot_single_function(target_function = easom, **plot_parameters)
  1. Colab Demo

Try it in Colab:

  1. Test Functions

Multiobjective Optimization or Many Objectives Optimization

For Multiobjective Optimization or Many Objectives Optimization try pyMultiobjective

TSP (Travelling Salesman Problem)

For Travelling Salesman Problems, try pyCombinatorial

Acknowledgement

This section is dedicated to everyone who helped improve or correct the code. Thank you very much!

Project details


Download files

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

Source Distribution

pyMetaheuristic-1.9.5.tar.gz (54.9 kB view details)

Uploaded Source

Built Distribution

pyMetaheuristic-1.9.5-py3-none-any.whl (98.4 kB view details)

Uploaded Python 3

File details

Details for the file pyMetaheuristic-1.9.5.tar.gz.

File metadata

  • Download URL: pyMetaheuristic-1.9.5.tar.gz
  • Upload date:
  • Size: 54.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.25.11 tqdm/4.64.1 importlib-metadata/4.11.3 keyring/23.4.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.7.6

File hashes

Hashes for pyMetaheuristic-1.9.5.tar.gz
Algorithm Hash digest
SHA256 be10a9eb3ab3238b9b1246e57284915fc65acb774e52a21eedde6bc7ee04c4ef
MD5 f32996a64e5cbc4f87ec50643d117866
BLAKE2b-256 e0d5d03bbb31a2f876b413008278b50b7ebe9bf373ba32d4bdc511cd4e932b87

See more details on using hashes here.

File details

Details for the file pyMetaheuristic-1.9.5-py3-none-any.whl.

File metadata

  • Download URL: pyMetaheuristic-1.9.5-py3-none-any.whl
  • Upload date:
  • Size: 98.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.25.11 tqdm/4.64.1 importlib-metadata/4.11.3 keyring/23.4.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.7.6

File hashes

Hashes for pyMetaheuristic-1.9.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d558cd33274261cf8283d7d7884bce7f419a897f94c97e059ced3f4340f0ea04
MD5 eee05d5d947fe4269037ffdec6bad8ad
BLAKE2b-256 63c5b433899977085ce3e36bdbec8d77e1c3bfd4b1cea9ecf87a30513bbe2cdf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page