Skip to main content

Optimization algorithms by Prof. R.V. Rao with constraint handling

Project description

Optimization Algorithms by Prof. R.V. Rao

This package implements several powerful optimization algorithms developed by Prof. Ravipudi Venkata Rao:

  • BMR (Best-Mean-Random) Algorithm
  • BWR (Best-Worst-Random) Algorithm
  • Jaya Algorithm
  • Rao Algorithms (Rao-1, Rao-2, Rao-3)
  • TLBO (Teaching-Learning-Based Optimization) Algorithm
  • QOJAYA (Quasi-Oppositional Jaya) Algorithm
  • GOTLBO (Generalized Oppositional TLBO) Algorithm
  • ITLBO (Improved TLBO) Algorithm
  • Multi-objective TLBO Algorithm

These algorithms are designed to solve both constrained and unconstrained optimization problems without relying on metaphors or algorithm-specific parameters. The BMR and BWR algorithms are 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: Most algorithms have no algorithm-specific parameters to tune.
  • Flexible: Handles both constrained and unconstrained optimization problems.
  • Versatile: Includes a variety of algorithms suitable for different types of optimization problems.
  • Multi-objective Optimization: Support for problems with multiple competing objectives.

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: Jaya Algorithm

import numpy as np
from rao_algorithms import Jaya_algorithm, objective_function

# Unconstrained Jaya
# -----------------
# 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 Jaya algorithm
best_solution, best_scores = Jaya_algorithm(bounds, num_iterations, population_size, num_variables, objective_function)
print(f"Jaya Best solution found: {best_solution}")

Example: TLBO Algorithm

import numpy as np
from rao_algorithms import TLBO_algorithm, objective_function

# Unconstrained TLBO
# -----------------
# 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 TLBO algorithm
best_solution, best_scores = TLBO_algorithm(bounds, num_iterations, population_size, num_variables, objective_function)
print(f"TLBO Best solution found: {best_solution}")

Example: Rao Algorithms

import numpy as np
from rao_algorithms import Rao1_algorithm, Rao2_algorithm, Rao3_algorithm, objective_function

# 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 Rao-1 algorithm
best_solution_rao1, best_scores_rao1 = Rao1_algorithm(bounds, num_iterations, population_size, num_variables, objective_function)
print(f"Rao-1 Best solution found: {best_solution_rao1}")

# Run the Rao-2 algorithm
best_solution_rao2, best_scores_rao2 = Rao2_algorithm(bounds, num_iterations, population_size, num_variables, objective_function)
print(f"Rao-2 Best solution found: {best_solution_rao2}")

# Run the Rao-3 algorithm
best_solution_rao3, best_scores_rao3 = Rao3_algorithm(bounds, num_iterations, population_size, num_variables, objective_function)
print(f"Rao-3 Best solution found: {best_solution_rao3}")

Example: QOJAYA Algorithm

import numpy as np
from rao_algorithms import QOJAYA_algorithm, objective_function

# Unconstrained QOJAYA
# -------------------
# 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 QOJAYA algorithm
best_solution, best_scores = QOJAYA_algorithm(bounds, num_iterations, population_size, num_variables, objective_function)
print(f"QOJAYA Best solution found: {best_solution}")

Example: GOTLBO Algorithm

import numpy as np
from rao_algorithms import GOTLBO_algorithm, objective_function

# Unconstrained GOTLBO
# -------------------
# 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 GOTLBO algorithm
best_solution, best_scores = GOTLBO_algorithm(bounds, num_iterations, population_size, num_variables, objective_function)
print(f"GOTLBO Best solution found: {best_solution}")

Example: ITLBO Algorithm

import numpy as np
from rao_algorithms import ITLBO_algorithm, objective_function

# Unconstrained ITLBO
# ------------------
# 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 ITLBO algorithm
best_solution, best_scores = ITLBO_algorithm(bounds, num_iterations, population_size, num_variables, objective_function)
print(f"ITLBO Best solution found: {best_solution}")

Example: Multi-objective TLBO Algorithm

import numpy as np
from rao_algorithms import MultiObjective_TLBO_algorithm

# Define two objective functions
def objective_function1(x):
    return np.sum(x**2)  # Minimize the sum of squares

def objective_function2(x):
    return np.sum((x-2)**2)  # Minimize the sum of squares from point (2,2,...)

# Multi-objective TLBO
# -------------------
# 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 Multi-objective TLBO algorithm
pareto_front, pareto_fitness, best_scores_history = MultiObjective_TLBO_algorithm(
    bounds, 
    num_iterations, 
    population_size, 
    num_variables, 
    [objective_function1, objective_function2]
)

print(f"Number of solutions in Pareto front: {len(pareto_front)}")
print(f"First Pareto optimal solution: {pareto_front[0]}")
print(f"Corresponding objective values: {pareto_fitness[0]}")

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.

Jaya Algorithm

The Jaya algorithm is a parameter-free algorithm that always tries to move toward the best solution and away from the worst solution. The name "Jaya" means "victory" in Sanskrit.

  • Paper Citation: R. V. Rao, "Jaya: A simple and new optimization algorithm for solving constrained and unconstrained optimization problems", International Journal of Industrial Engineering Computations, 7(1), 2016, 19-34.

Rao Algorithms (Rao-1, Rao-2, Rao-3)

The Rao algorithms are a family of three metaphor-less optimization algorithms. Each algorithm uses a different strategy to guide the search process:

  • Rao-1: Uses the best solution and solution comparison

  • Rao-2: Uses the best, worst, and average fitness

  • Rao-3: Uses the best solution and a phase factor

  • Paper Citation: R. V. Rao, "Rao algorithms: Three metaphor-less simple algorithms for solving optimization problems", International Journal of Industrial Engineering Computations, 11(2), 2020, 193-212.

TLBO (Teaching-Learning-Based Optimization)

TLBO is a parameter-free algorithm inspired by the teaching-learning process in a classroom. It consists of two phases: Teacher Phase and Learner Phase.

  • Paper Citation: R. V. Rao, V. J. Savsani, D. P. Vakharia, "Teaching-Learning-Based Optimization: An optimization method for continuous non-linear large scale problems", Information Sciences, 183(1), 2012, 1-15.

QOJAYA (Quasi-Oppositional Jaya) Algorithm

QOJAYA enhances the standard Jaya algorithm by incorporating quasi-oppositional learning to improve convergence speed and solution quality. It generates and evaluates quasi-opposite solutions alongside the standard Jaya updates.

  • Paper Citation: R. V. Rao, D. P. Rai, "Optimization of welding processes using quasi-oppositional-based Jaya algorithm", Journal of Mechanical Science and Technology, 31(5), 2017, 2513-2522.
  • Real-world Application: The algorithm has been successfully applied to optimize welding processes, including tungsten inert gas (TIG) welding and friction stir welding. It determines optimal parameters like welding current, voltage, and speed to maximize weld strength while minimizing defects.

GOTLBO (Generalized Oppositional TLBO) Algorithm

GOTLBO combines TLBO with generalized opposition-based learning to enhance exploration capabilities and convergence speed. It applies opposition in both teacher and learner phases.

  • Paper Citation: R. V. Rao, V. Patel, "An improved teaching-learning-based optimization algorithm for solving unconstrained optimization problems", Scientia Iranica, 20(3), 2013, 710-720.
  • Real-world Application: GOTLBO has been applied to mechanical design optimization problems, including the design of pressure vessels, spring design, and gear train design. It effectively finds optimal dimensions and parameters that minimize weight while satisfying safety constraints.

ITLBO (Improved TLBO) Algorithm

ITLBO enhances the standard TLBO algorithm with an adaptive teaching factor, elite solution influence, and three-way interaction in the learner phase.

  • Paper Citation: R. V. Rao, V. Patel, "An elitist teaching-learning-based optimization algorithm for solving complex constrained optimization problems", International Journal of Industrial Engineering Computations, 3(4), 2012, 535-560.
  • Real-world Application: ITLBO has been successfully applied to optimize heat exchangers, finding the optimal design parameters that maximize heat transfer while minimizing pressure drop and material costs. It has also been used for power system optimization to minimize generation costs and transmission losses.

Multi-objective TLBO Algorithm

Multi-objective TLBO extends TLBO to handle multiple competing objectives using Pareto dominance and crowding distance for selection. It returns a set of non-dominated solutions (Pareto front).

  • Paper Citation: R. V. Rao, V. D. Kalyankar, "Multi-objective TLBO algorithm for optimization of modern machining processes", Advances in Intelligent Systems and Computing, 236, 2014, 21-31.
  • Real-world Application: The algorithm has been applied to optimize machining processes like turning, milling, and grinding operations. It simultaneously optimizes multiple objectives such as surface roughness, material removal rate, and tool wear, helping manufacturers achieve high-quality parts with efficient production.

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.
  2. Ravipudi Venkata Rao, "Jaya: A simple and new optimization algorithm for solving constrained and unconstrained optimization problems", International Journal of Industrial Engineering Computations, 7(1), 2016, 19-34.
  3. Ravipudi Venkata Rao, "Rao algorithms: Three metaphor-less simple algorithms for solving optimization problems", International Journal of Industrial Engineering Computations, 11(2), 2020, 193-212.
  4. Ravipudi Venkata Rao, V. J. Savsani, D. P. Vakharia, "Teaching-Learning-Based Optimization: An optimization method for continuous non-linear large scale problems", Information Sciences, 183(1), 2012, 1-15.
  5. Ravipudi Venkata Rao, D. P. Rai, "Optimization of welding processes using quasi-oppositional-based Jaya algorithm", Journal of Mechanical Science and Technology, 31(5), 2017, 2513-2522.
  6. Ravipudi Venkata Rao, V. Patel, "An improved teaching-learning-based optimization algorithm for solving unconstrained optimization problems", Scientia Iranica, 20(3), 2013, 710-720.
  7. Ravipudi Venkata Rao, V. Patel, "An elitist teaching-learning-based optimization algorithm for solving complex constrained optimization problems", International Journal of Industrial Engineering Computations, 3(4), 2012, 535-560.
  8. Ravipudi Venkata Rao, V. D. Kalyankar, "Multi-objective TLBO algorithm for optimization of modern machining processes", Advances in Intelligent Systems and Computing, 236, 2014, 21-31.

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.5.0.tar.gz (20.1 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.5.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rao_algorithms-0.5.0.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for rao_algorithms-0.5.0.tar.gz
Algorithm Hash digest
SHA256 fce206fe31fd2cd0f81b221fb18ce10fd13f1f0b3375ef0272632ac59d76377e
MD5 32b083880be99484e60adafe898b8b96
BLAKE2b-256 5c4fe4734e719ff41c8792a86f0c84e8ff462a851c92ff1e4daea13af17d7a6e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rao_algorithms-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for rao_algorithms-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f152d988541e6f97e0dec126b7e615101aebf3cf710060374326d75e9f056cc
MD5 3f890a61c5ff08c57dcf921ff5ce42fa
BLAKE2b-256 be357bb06d7c1f2bc4fb7e4e5babb46e246d5b8845e1ba76e9da6a52fa5b8aa0

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