Skip to main content

BMR and BWR optimization algorithms with constraint handling

Project description

Optimization Algorithms: BMR and BWR

This package implements two simple yet powerful optimization algorithms:

  • BMR (Best-Mean-Random) Algorithm
  • BWR (Best-Worst-Random) Algorithm

These algorithms are designed to solve both constrained and unconstrained optimization problems without relying on metaphors or algorithm-specific parameters. The package is based on the paper:

Ravipudi Venkata Rao and Ravikumar Shah (2024), "BMR and BWR: Two simple metaphor-free optimization algorithms for solving real-life non-convex constrained and unconstrained problems." arXiv:2407.11149v2.

Features

  • Metaphor-Free: No reliance on nature-inspired metaphors.
  • Simple: No algorithm-specific parameters to tune.
  • Flexible: Handles both constrained and unconstrained optimization problems.

Installation

You can install this package directly from PyPI:

pip install rao_algorithms

Alternatively, you can clone this repository and install it locally:

git clone https://github.com/VaidhyaMegha/optimization_algorithms.git
cd optimization_algorithms
pip install .

How to Use

Example: Constrained BMR Algorithm

import numpy as np
from rao_algorithms import run_optimization, BMR_algorithm, objective_function, constraint_1, constraint_2

# Constrained BMR
# ---------------
bounds = np.array([[-100, 100]] * 2)
num_iterations = 100
population_size = 50
constraints = [constraint_1, constraint_2]

best_solution, best_scores = run_optimization(BMR_algorithm, bounds, num_iterations, population_size, 2, objective_function, constraints)
print(f"Constrained BMR Best solution: {best_solution}")

Example: Unconstrained BMR Algorithm

import numpy as np
from rao_algorithms import BMR_algorithm, objective_function

# Unconstrained BMR
# ---------------
# Define the bounds for a 2D problem
bounds = np.array([[-100, 100]] * 2)

# Set parameters
num_iterations = 100
population_size = 50
num_variables = 2

# Run the BMR algorithm
best_solution, best_scores = BMR_algorithm(bounds, num_iterations, population_size, num_variables, objective_function)
print(f"Unconstrained BMR Best solution found: {best_solution}")

Example: Constrained BWR Algorithm

import numpy as np
from rao_algorithms import BWR_algorithm, objective_function, constraint_1, constraint_2

# Constrained BWR
# ---------------
# Define the bounds for a 2D problem
bounds = np.array([[-100, 100]] * 2)

# Set parameters
num_iterations = 100
population_size = 50
num_variables = 2
constraints = [constraint_1, constraint_2]

# Run the BWR algorithm with constraints
best_solution, best_scores = BWR_algorithm(bounds, num_iterations, population_size, num_variables, objective_function, constraints)
print(f"Constrained BWR Best solution found: {best_solution}")

Unit Testing

This package comes with unit tests. To run the tests:

python -m unittest discover -s tests

You can also run the tests using Docker:

docker build -t optimization-algorithms .
docker run -it optimization-algorithms

Algorithms Overview

BMR (Best-Mean-Random) Algorithm

The BMR algorithm is based on the best, mean, and random solutions from the population. It works by updating solutions based on their interaction with these key elements.

  • Paper Citation: R. V. Rao, R. Shah, BMR and BWR: Two simple metaphor-free optimization algorithms. arXiv:2407.11149v2.

BWR (Best-Worst-Random) Algorithm

The BWR algorithm updates solutions by considering the best, worst, and random solutions in the population. The algorithm balances exploration and exploitation through these interactions.

  • Paper Citation: R. V. Rao, R. Shah, BMR and BWR: Two simple metaphor-free optimization algorithms. arXiv:2407.11149v2.

Docker Support

You can use the included Dockerfile to build and test the package quickly. To build and run the package in Docker:

docker build -t optimization-algorithms .
docker run -it optimization-algorithms

License

This package is licensed under the MIT License. See the LICENSE file for more details.

References

  1. Ravipudi Venkata Rao, Ravikumar Shah, "BMR and BWR: Two simple metaphor-free optimization algorithms for solving real-life non-convex constrained and unconstrained problems," arXiv:2407.11149v2.

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

rao_algorithms-0.2.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rao_algorithms-0.2.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file rao_algorithms-0.2.2.tar.gz.

File metadata

  • Download URL: rao_algorithms-0.2.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for rao_algorithms-0.2.2.tar.gz
Algorithm Hash digest
SHA256 0dc979e94f80f0f071b4b77f93207facf0a243a6c62bb33cd1972af1a5a022ed
MD5 2f4eadff0e18be2523a78b8fe7191493
BLAKE2b-256 a0644a11719546d38efda7e90113c4bb3390caab7fa744f8e89549374e328c34

See more details on using hashes here.

File details

Details for the file rao_algorithms-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: rao_algorithms-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for rao_algorithms-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e48806732e50c92ba5ed7c208f2e39efce41d8d66fc23e170ffb14d7883e2f1d
MD5 37766b2797b17e11f837f30cc055a651
BLAKE2b-256 d34062a89f2f2ce8b259393b37d36f5d804d42f42f4a8c728a79876bf1e1b1a1

See more details on using hashes here.

Supported by

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