!PyPI - Python Version
!GitHub Release Date
MEALPY is the world's largest Python library, offering a comprehensive collection of cutting-edge meta-heuristic algorithms. These include nature-inspired algorithms, bio-inspired algorithms, black-box optimization, global search optimizers, iterative learning algorithms, continuous optimization, derivative-free optimization, gradient-free optimization, zeroth-order optimization, stochastic search optimization, and random search optimization. All these methods fall under the category of population-based metaheuristics (PBMs), which are among the most popular algorithms in the field of approximate optimization. For detailed updates in each new version, please refer to the ChangeLog file.
- Free software: MIT license
- Total algorithms: 233 (206 official (original, hybrid, variants), 27 developed)
- Documentation: https://mealpy.readthedocs.io/en/latest/
- Python versions: >=3.8x
- Dependencies: numpy, scipy, pandas, matplotlib, tqdm
📌 Goals
Our goals are to implement all classical as well as the state-of-the-art nature-inspired algorithms, create a simple interface that helps researchers access optimization algorithms as quickly as possible, and share knowledge of the optimization field with everyone without a fee. What you can do with mealpy:
- Analyse parameters of meta-heuristic algorithms.
- Perform Qualitative and Quantitative Analysis of algorithms.
- Analyse rate of convergence of algorithms.
- Test and Analyse the scalability and the robustness of algorithms.
- Save results in various formats (csv, json, pickle, png, pdf, jpeg)
- Export and import models can also be done with Mealpy.
- Solve any optimization problem
📄 Citation Request
Please include these citations if you plan to use this library:
``bibtex
@article{van2023mealpy,
title={MEALPY: An open-source library for latest meta-heuristic algorithms in Python},
author={Van Thieu, Nguyen and Mirjalili, Seyedali},
journal={Journal of Systems Architecture},
year={2023},
publisher={Elsevier},
doi={10.1016/j.sysarc.2023.102871}
}
@article{van2023groundwater, title={Groundwater level modeling using Augmented Artificial Ecosystem Optimization}, author={Van Thieu, Nguyen and Barma, Surajit Deb and Van Lam, To and Kisi, Ozgur and Mahesha, Amai}, journal={Journal of Hydrology}, volume={617}, pages={129034}, year={2023}, publisher={Elsevier}, doi={https://doi.org/10.1016/j.jhydrol.2022.129034} }
@article{ahmed2021comprehensive, title={A comprehensive comparison of recent developed meta-heuristic algorithms for streamflow time series forecasting problem}, author={Ahmed, Ali Najah and Van Lam, To and Hung, Nguyen Duy and Van Thieu, Nguyen and Kisi, Ozgur and El-Shafie, Ahmed}, journal={Applied Soft Computing}, volume={105}, pages={107282}, year={2021}, publisher={Elsevier}, doi={10.1016/j.asoc.2021.107282} }
# ⚙️ Usage
<details><summary><h2>🛠️ Installation</h2></summary>
- Install the stable (latest) version from PyPI release:
bash$ pip install mealpy --upgrade
* Install the alpha/beta version from PyPibash
$ pip install mealpy==2.5.4a6
* Install the pre-release version directly from the source code:bash
$ git clone https://github.com/thieu1995/mealpy.git
$ cd mealpy
$ python setup.py install
* In case, you want to install the development version from Github:bash
$ pip install git+https://github.com/thieu1995/mealpy
After installation, check the version to ensure successful installation:bash
$ python
>> import mealpy
>> mealpy.__version__
>> print(mealpy.get_all_optimizers())
>> model = mealpy.get_optimizer_by_name("OriginalWOA")(epoch=100, pop_size=50)
python</details>FloatVar(lb=(-10., )7, ub=(10., )7, name="delta")💬 Decision Variables
Before we dive into some examples, let's briefly consider the type of problem you're aiming to solve with MEALPY. Understanding your specific problem and its desired solution can help you select the most appropriate approach.
To assist you in choosing the right tools, refer to the table below. It outlines different types of decision variables available in MEALPY, along with their syntax and common problem applications. This will guide you in defining your search space effectively.
<div align="center">
| Class | Syntax | Problem Types | |-------------------|-----------------------------------------------------------------------------------------------------------------|-----------------------------| | FloatVar |
| Continuous Problem | | IntegerVar |IntegerVar(lb=(-10., )7, ub=(10., )7, name="delta")| LP, IP, NLP, QP, MIP | | StringVar |StringVar(valid_sets=(("auto", "backward", "forward"), ("leaf", "branch", "root")), name="delta")| ML, AI-optimize | | BinaryVar |BinaryVar(n_vars=11, name="delta")| Networks | | BoolVar |BoolVar(n_vars=11, name="delta")| ML, AI-optimize | | PermutationVar |PermutationVar(valid_set=(-10, -4, 10, 6, -2), name="delta")| Combinatorial Optimization | | CategoricalVar |CategoricalVar(valid_sets=(("auto", 2, 3, "backward", True), (0, "tournament", "round-robin")), name="delta")| MIP, MILP | | SequenceVar |SequenceVar(valid_sets=((1, ), {2, 3}, [3, 5, 1]), return_type=list, name='delta')| Hyper-parameter tuning | | TransferBoolVar |TransferBoolVar(n_vars=11, name="delta", tf_func="sstf_02")| ML, AI-optimize, Feature | | TransferBinaryVar |TransferBinaryVar(n_vars=11, name="delta", tf_func="vstf_04")| Networks, Feature Selection |</div>
📚 Optimizer Classification
To explore the complete, up-to-date registry of supported optimizers and their categorical breakdown, please check out our Official Classification Table or consult the foundational research paper.
❌ Warning: Algorithms Suspected of Plagiarism
During our implementation and classification of metaheuristic optimization algorithms, we identified a set of methods that raise serious concerns regarding scientific integrity and originality. These algorithms are typically published under different names, but they appear to share:
For these reasons, we strongly advise the exclusion of the following algorithms from scientific benchmarking, comparative studies, or any applications unless their originality is transparently validated.
- The same core mathematical models, equations, and update rules.
- Only superficial changes in naming, metaphors, or biological analogies.
- Publications authored by the same or overlapping research groups.
- Heavy criticism on public academic forums such as PubPeer, where many of these papers are flagged for self-plagiarism, redundant publication, or lack of novelty.
- Some of these papers may be withdrawn or retracted in the future, as investigations unfold.
**I have personally implemented these algorithms, which is why I can confidently say that they are nearly identical and likely cases of plagiarism. For this reason, I will no longer spend time coding such algorithms in the future. This warning is intended to help others avoid using or relying on these methods in their work.**
| Group | Name | Module | Class | Year | Paras | | --- | --- | --- | --- | --- |-------| | Swarm | Coati Optimization Algorithm | CoatiOA | OriginalCoatiOA | 2023 | 2 | | Swarm | Fennec For Optimization | FFO | OriginalFFO | 2022 | 2 | | Swarm | Northern Goshawk Optimization | NGO | OriginalNGO | 2021 | 2 | | Swarm | Osprey Optimization Algorithm | OOA | OriginalOOA | 2023 | 2 | | Swarm | Pelican Optimization Algorithm | POA | OriginalPOA | 2023 | 2 | | Swarm | Serval Optimization Algorithm | ServalOA | OriginalServalOA | 2022 | 2 | | Swarm | Siberian Tiger Optimization | STO | OriginalSTO | 2022 | 2 | | Swarm | Tasmanian Devil Optimization | TDO | OriginalTDO | 2022 | 2 | | Swarm | Walrus Optimization Algorithm | WaOA | OriginalWaOA | 2022 | 2 | | Swarm | Zebra Optimization Algorithm | ZOA | OriginalZOA | 2022 | 2 | | Human | Teamwork Optimization Algorithm | TOA | OriginalTOA | 2021 | 2 |
⚠️ Ethical Reminder
Researchers and students are urged to exercise caution when referencing or applying the algorithms listed above. Using unoriginal or unethical work can compromise the scientific credibility of any downstream research and introduce misleading experimental results.
> 🔗 Check PubPeer1 and PubPeer2 to > find ongoing discussions and critiques from the academic community.
<details><summary><h3>💻 Define All Optimizers</h3></summary>
from mealpy import (StringVar, FloatVar, BoolVar, PermutationVar, CategoricalVar, IntegerVar, BinaryVar, TransferBinaryVar, TransferBoolVar) from mealpy import Tuner, Multitask, Problem, Optimizer, Termination, ParameterGrid from mealpy import get_all_optimizers, get_optimizer_by_name
from mealpy import BBO, PSO, GA, ALO, AO, ARO, AVOA, BA, BBOA, BMO, EOA, IWO from mealpy import GJO, FOX, FOA, FFO, FFA, FA, ESOA, EHO, DO, DMOA, CSO, CSA, CoatiOA, COA, BSA from mealpy import HCO, ICA, LCO, WarSO, TOA, TLO, SSDO, SPBO, SARO, QSA, ArchOA, ASO, CDO, EFO, EO, EVO, FLA from mealpy import HGSO, MVO, NRO, RIME, SA, WDO, TWO, ABC, ACOR, AGTO, BeesA, BES, BFO, ZOA, WOA, WaOA, TSO from mealpy import PFA, OOA, NGO, NMRA, MSA, MRFO, MPA, MGO, MFO, JA, HHO, HGS, HBA, GWO, GTO, GOA from mealpy import SBO, SMA, SOA, SOS, TPO, TSA, VCS, WHO, AOA, CEM, CGO, CircleSA, GBO, HC, INFO, PSS, RUN, SCA from mealpy import SHIO, TS, HS, AEO, GCO, WCA, CRO, DE, EP, ES, FPA, MA, SHADE, BRO, BSO, CA, CHIO, FBIO, GSKA, HBO from mealpy import TDO, STO, SSpiderO, SSpiderA, SSO, SSA, SRSR, SLO, SHO, SFO, ServalOA, SeaHO, SCSO, POA
Newly added module in version 3.0.3
from mealpy import ESO, EPC, SMO, AFT, CDDO, SquirrelSA, FDO, LSHADEcnEpSin, IMODEif __name__ == "__main__": model = BBO.OriginalBBO(epoch=10, pop_size=30, p_m=0.01, n_elites=2) model = PSO.OriginalPSO(epoch=100, pop_size=50, c1=2.05, c2=20.5, w=0.4) model = PSO.LDW_PSO(epoch=100, pop_size=50, c1=2.05, c2=20.5, w_min=0.4, w_max=0.9) model = PSO.AIW_PSO(epoch=100, pop_size=50, c1=2.05, c2=20.5, alpha=0.4) model = PSO.P_PSO(epoch=100, pop_size=50) model = PSO.HPSO_TVAC(epoch=100, pop_size=50, ci=0.5, cf=0.1) model = PSO.C_PSO(epoch=100, pop_size=50, c1=2.05, c2=2.05, w_min=0.4, w_max=0.9) model = PSO.CL_PSO(epoch=100, pop_size=50, c_local=1.2, w_min=0.4, w_max=0.9, max_flag=7) model = GA.BaseGA(epoch=100, pop_size=50, pc=0.9, pm=0.05, selection="tournament", k_way=0.4, crossover="multi_points", mutation="swap") model = GA.SingleGA(epoch=100, pop_size=50, pc=0.9, pm=0.8, selection="tournament", k_way=0.4, crossover="multi_points", mutation="swap") model = GA.MultiGA(epoch=100, pop_size=50, pc=0.9, pm=0.8, selection="tournament", k_way=0.4, crossover="multi_points", mutation="swap") model = GA.EliteSingleGA(epoch=100, pop_size=50, pc=0.95, pm=0.8, selection="roulette", crossover="uniform", mutation="swap", k_way=0.2, elite_best=0.1, elite_worst=0.3, strategy=0) model = GA.EliteMultiGA(epoch=100, pop_size=50, pc=0.95, pm=0.8, selection="roulette", crossover="uniform", mutation="swap", k_way=0.2, elite_best=0.1, elite_worst=0.3, strategy=0) model = ABC.OriginalABC(epoch=1000, pop_size=50, n_limits=50) model = ACOR.OriginalACOR(epoch=1000, pop_size=50, sample_count=25, intent_factor=0.5, zeta=1.0) model = AGTO.OriginalAGTO(epoch=1000, pop_size=50, p1=0.03, p2=0.8, beta=3.0) model = AGTO.MGTO(epoch=1000, pop_size=50, pp=0.03) model = ALO.OriginalALO(epoch=100, pop_size=50) model = ALO.DevALO(epoch=100, pop_size=50) model = AO.OriginalAO(epoch=100, pop_size=50) model = ARO.OriginalARO(epoch=100, pop_size=50) model = ARO.LARO(epoch=100, pop_size=50) model = ARO.IARO(epoch=100, pop_size=50) model = AVOA.OriginalAVOA(epoch=100, pop_size=50, p1=0.6, p2=0.4, p3=0.6, alpha=0.8, gama=2.5) model = BA.OriginalBA(epoch=100, pop_size=50, loudness=0.8, pulse_rate=0.95, pf_min=0.1, pf_max=10.0) model = BA.AdaptiveBA(epoch=100, pop_size=50, loudness_min=1.0, loudness_max=2.0, pr_min=-2.5, pr_max=0.85, pf_min=0.1, pf_max=10.) model = BA.DevBA(epoch=100, pop_size=50, pulse_rate=0.95, pf_min=0., pf_max=10.) model = BBOA.OriginalBBOA(epoch=100, pop_size=50) model = BMO.OriginalBMO(epoch=100, pop_size=50, pl=4) model = EOA.OriginalEOA(epoch=100, pop_size=50, p_c=0.9, p_m=0.01, n_best=2, alpha=0.98, beta=0.9, gama=0.9) model = IWO.OriginalIWO(epoch=100, pop_size=50, seed_min=3, seed_max=9, exponent=3, sigma_start=0.6, sigma_end=0.01) model = SBO.DevSBO(epoch=100, pop_size=50, alpha=0.9, p_m=0.05, psw=0.02) model = SBO.OriginalSBO(epoch=100, pop_size=50, alpha=0.9, p_m=0.05, psw=0.02) model = SMA.OriginalSMA(epoch=100, pop_size=50, p_t=0.03) model = SMA.DevSMA(epoch=100, pop_size=50, p_t=0.03) model = SOA.OriginalSOA(epoch=100, pop_size=50, fc=2) model = SOA.DevSOA(epoch=100, pop_size=50, fc=2) model = SOS.OriginalSOS(epoch=100, pop_size=50) model = TPO.DevTPO(epoch=100, pop_size=50, alpha=0.3, beta=50., theta=0.9) model = TSA.OriginalTSA(epoch=100, pop_size=50) model = VCS.OriginalVCS(epoch=100, pop_size=50, lamda=0.5, sigma=0.3) model = VCS.DevVCS(epoch=100, pop_size=50, lamda=0.5, sigma=0.3) model = WHO.OriginalWHO(epoch=100, pop_size=50, n_explore_step=3, n_exploit_step=3, eta=0.15, p_hi=0.9, local_alpha=0.9, local_beta=0.3, global_alpha=0.2, global_beta=0.8, delta_w=2.0, delta_c=2.0) model = AOA.OriginalAOA(epoch=100, pop_size=50, alpha=5, miu=0.5, moa_min=0.2, moa_max=0.9) model = CEM.OriginalCEM(epoch=100, pop_size=50, n_best=20, alpha=0.7) model = CGO.OriginalCGO(epoch=100, pop_size=50) model = CircleSA.OriginalCircleSA(epoch=100, pop_size=50, c_factor=0.8) model = GBO.OriginalGBO(epoch=100, pop_size=50, pr=0.5, beta_min=0.2, beta_max=1.2) model = HC.OriginalHC(epoch=100, pop_size=50, neighbour_size=50) model = HC.SwarmHC(epoch=100, pop_size=50, neighbour_size=10) model = INFO.OriginalINFO(epoch=100, pop_size=50) model = PSS.OriginalPSS(epoch=100, pop_size=50, acceptance_rate=0.8, sampling_method="LHS") model = RUN.OriginalRUN(epoch=100, pop_size=50) model = SCA.OriginalSCA(epoch=100, pop_size=50) model = SCA.DevSCA(epoch=100, pop_size=50) model = SCA.QleSCA(epoch=100, pop_size=50, alpha=0.1, gama=0.9) model = SHIO.OriginalSHIO(epoch=100, pop_size=50) model = TS.OriginalTS(epoch=100, pop_size=50, tabu_size=5, neighbour_size=20, perturbation_scale=0.05) model = HS.OriginalHS(epoch=100, pop_size=50, c_r=0.95, pa_r=0.05) model = HS.DevHS(epoch=100, pop_size=50, c_r=0.95, pa_r=0.05) model = AEO.OriginalAEO(epoch=100, pop_size=50) model = AEO.EnhancedAEO(epoch=100, pop_size=50) model = AEO.ModifiedAEO(epoch=100, pop_size=50) model = AEO.ImprovedAEO(epoch=100, pop_size=50) model = AEO.AugmentedAEO(epoch=100, pop_size=50) model = GCO.OriginalGCO(epoch=100, pop_size=50, cr=0.7, wf=1.25) model = GCO.DevGCO(epoch=100, pop_size=50, cr=0.7, wf=1.25) model = WCA.OriginalWCA(epoch=100, pop_size=50, nsr=4, wc=2.0, dmax=1e-6) model = CRO.OriginalCRO(epoch=100, pop_size=50, po=0.4, Fb=0.9, Fa=0.1, Fd=0.1, Pd=0.5, GCR=0.1, gamma_min=0.02, gamma_max=0.2, n_trials=5) model = CRO.OCRO(epoch=100, pop_size=50, po=0.4, Fb=0.9, Fa=0.1, Fd=0.1, Pd=0.5, GCR=0.1, gamma_min=0.02, gamma_max=0.2, n_trials=5, restart_count=50) model = DE.OriginalDE(epoch=100, pop_size=50, wf=0.7, cr=0.9, strategy=0) model = DE.JADE(epoch=100, pop_size=50, miu_f=0.5, miu_cr=0.5, pt=0.1, ap=0.1) model = DE.SADE(epoch=100, pop_size=50) model = DE.SAP_DE(epoch=100, pop_size=50, branch="ABS") model = EP.OriginalEP(epoch=100, pop_size=50, bout_size=0.05) model = EP.LevyEP(epoch=100, pop_size=50, bout_size=0.05) model = ES.OriginalES(epoch=100, pop_size=50, lamda=0.75) model = ES.LevyES(epoch=100, pop_size=50, lamda=0.75) model = ES.CMA_ES(epoch=100, pop_size=50) model = ES.Simple_CMA_ES(epoch=100, pop_size=50) model = FPA.OriginalFPA(epoch=100, pop_size=50, p_s=0.8, levy_multiplier=0.2) model = MA.OriginalMA(epoch=100, pop_size=50, pc=0.85, pm=0.15, p_local=0.5, max_local_gens=10, bits_per_param=4) model = SHADE.OriginalSHADE(epoch=100, pop_size=50, miu_f=0.5, miu_cr=0.5) model = SHADE.L_SHADE(epoch=100, pop_size=50, miu_f=0.5, miu_cr=0.5) model = BRO.OriginalBRO(epoch=100, pop_size=50, threshold=3) model = BRO.DevBRO(epoch=100, pop_size=50, threshold=3) model = BSO.OriginalBSO(epoch=100, pop_size=50, m_clusters=5, p1=0.2, p2=0.8, p3=0.4, p4=0.5, slope=20) model = BSO.ImprovedBSO(epoch=100, pop_size=50, m_clusters=5, p1=0.25, p2=0.5, p3=0.75, p4=0.6) model = CA.OriginalCA(epoch=100, pop_size=50, accepted_rate=0.15) model = CHIO.OriginalCHIO(epoch=100, pop_size=50, brr=0.15, max_age=10) model = CHIO.DevCHIO(epoch=100, pop_size=50, brr=0.15, max_age=10) model = FBIO.OriginalFBIO(epoch=100, pop_size=50) model = FBIO.DevFBIO(epoch=100, pop_size=50) model = GSKA.OriginalGSKA(epoch=100, pop_size=50, pb=0.1, kf=0.5, kr=0.9, kg=5) model = GSKA.DevGSKA(epoch=100, pop_size=50, pb=0.1, kr=0.9) model = HBO.OriginalHBO(epoch=100, pop_size=50, degree=3) model = HCO.OriginalHCO(epoch=100, pop_size=50, wfp=0.65, wfv=0.05, c1=1.4, c2=1.4) model = ICA.OriginalICA(epoch=100, pop_size=50, empire_count=5, assimilation_coeff=1.5, revolution_prob=0.05, revolution_rate=0.1, revolution_step_size=0.1, zeta=0.1) model = LCO.OriginalLCO(epoch=100, pop_size=50, r1=2.35) model = LCO.ImprovedLCO(epoch=100, pop_size=50) model = LCO.DevLCO(epoch=100, pop_size=50, r1=2.35) model = WarSO.OriginalWarSO(epoch=100, pop_size=50, rr=0.1) model = TOA.OriginalTOA(epoch=100, pop_size=50) model = TLO.OriginalTLO(epoch=100, pop_size=50) model = TLO.ImprovedTLO(epoch=100, pop_size=50, n_teachers=5) model = TLO.ETLBO(epoch=100, pop_size=50, elite_size=4) model = SSDO.OriginalSSDO(epoch=100, pop_size=50) model = SPBO.OriginalSPBO(epoch=100, pop_size=50) model = SPBO.DevSPBO(epoch=100, pop_size=50) model = SARO.OriginalSARO(epoch=100, pop_size=50, se=0.5, mu=50) model = SARO.DevSARO(epoch=100, pop_size=50, se=0.5, mu=50) model = QSA.OriginalQSA(epoch=100, pop_size=50) model = QSA.DevQSA(epoch=100, pop_size=50) model = QSA.OppoQSA(epoch=100, pop_size=50) model = QSA.LevyQSA(epoch=100, pop_size=50) model = QSA.ImprovedQSA(epoch=100, pop_size=50) model = ArchOA.OriginalArchOA(epoch=100, pop_size=50, c1=2, c2=5, c3=2, c4=0.5, acc_max=0.9, acc_min=0.1) model = ASO.OriginalASO(epoch=100, pop_size=50, alpha=50, beta=0.2) model = CDO.OriginalCDO(epoch=100, pop_size=50) model = EFO.OriginalEFO(epoch=100, pop_size=50, r_rate=0.3, ps_rate=0.85, p_field=0.1, n_field=0.45) model = EFO.DevEFO(epoch=100, pop_size=50, r_rate=0.3, ps_rate=0.85, p_field=0.1, n_field=0.45) model = EO.OriginalEO(epoch=100, pop_size=50) model = EO.AdaptiveEO(epoch=100, pop_size=50) model = EO.ModifiedEO(epoch=100, pop_size=50) model = EVO.OriginalEVO(epoch=100, pop_size=50) model = FLA.OriginalFLA(epoch=100, pop_size=50, C1=0.5, C2=2.0, C3=0.1, C4=0.2, C5=2.0, DD=0.01) model = HGSO.OriginalHGSO(epoch=100, pop_size=50, n_clusters=3) model = MVO.OriginalMVO(epoch=100, pop_size=50, wep_min=0.2, wep_max=1.0) model = MVO.DevMVO(epoch=100, pop_size=50, wep_min=0.2, wep_max=1.0) model = NRO.OriginalNRO(epoch=100, pop_size=50) model = RIME.OriginalRIME(epoch=100, pop_size=50, sr=5.0) model = SA.OriginalSA(epoch=100, pop_size=50, temp_init=100, step_size=0.1) model = SA.GaussianSA(epoch=100, pop_size=50, temp_init=100, cooling_rate=0.99, scale=0.1) model = SA.SwarmSA(epoch=100, pop_size=50, max_sub_iter=5, t0=1000, t1=1, move_count=5, mutation_rate=0.1, mutation_step_size=0.1, mutation_step_size_damp=0.99) model = WDO.OriginalWDO(epoch=100, pop_size=50, RT=3, g_c=0.2, alp=0.4, c_e=0.4, max_v=0.3) model = TWO.OriginalTWO(epoch=100, pop_size=50) model = TWO.EnhancedTWO(epoch=100, pop_size=50) model = TWO.OppoTWO(epoch=100, pop_size=50) model = TWO.LevyTWO(epoch=100, pop_size=50) model = ABC.OriginalABC(epoch=100, pop_size=50, n_limits=50) model = ACOR.OriginalACOR(epoch=100, pop_size=50, sample_count=25, intent_factor=0.5, zeta=1.0) model = AGTO.OriginalAGTO(epoch=100, pop_size=50, p1=0.03, p2=0.8, beta=3.0) model = AGTO.MGTO(epoch=100, pop_size=50, pp=0.03) model = BeesA.OriginalBeesA(epoch=100, pop_size=50, selected_site_ratio=0.5, elite_site_ratio=0.4, selected_site_bee_ratio=0.1, elite_site_bee_ratio=2.0, dance_radius=0.1, dance_reduction=0.99) model = BeesA.CleverBookBeesA(epoch=100, pop_size=50, n_elites=16, n_others=4, patch_size=5.0, patch_reduction=0.985, n_sites=3, n_elite_sites=1) model = BeesA.ProbBeesA(epoch=100, pop_size=50, recruited_bee_ratio=0.1, dance_radius=0.1, dance_reduction=0.99) model = BES.OriginalBES(epoch=100, pop_size=50, a_factor=10, R_factor=1.5, alpha=2.0, c1=2.0, c2=2.0) model = BFO.OriginalBFO(epoch=100, pop_size=50, Ci=0.01, Ped=0.25, Nc=5, Ns=4, d_attract=0.1, w_attract=0.2, h_repels=0.1, w_repels=10) model = BFO.ABFO(epoch=100, pop_size=50, C_s=0.1, C_e=0.001, Ped=0.01, Ns=4, N_adapt=2, N_split=40) model = ZOA.OriginalZOA(epoch=100, pop_size=50) model = WOA.OriginalWOA(epoch=100, pop_size=50) model = WOA.HI_WOA(epoch=100, pop_size=50, feedback_max=10) model = WaOA.OriginalWaOA(epoch=100, pop_size=50) model = TSO.OriginalTSO(epoch=100, pop_size=50) model = TDO.OriginalTDO(epoch=100, pop_size=50) model = STO.OriginalSTO(epoch=100, pop_size=50) model = SSpiderO.OriginalSSpiderO(epoch=100, pop_size=50, fp_min=0.65, fp_max=0.9) model = SSpiderA.DevSSpiderA(epoch=100, pop_size=50, r_a=1.0, p_c=0.7, p_m=0.1) model = SSO.OriginalSSO(epoch=100, pop_size=50) model = SSA.OriginalSSA(epoch=100, pop_size=50, ST=0.8, PD=0.2, SD=0.1) model = SSA.DevSSA(epoch=100, pop_size=50, ST=0.8, PD=0.2, SD=0.1) model = SRSR.OriginalSRSR(epoch=100, pop_size=50) model = SLO.OriginalSLO(epoch=100, pop_size=50) model = SLO.ModifiedSLO(epoch=100, pop_size=50) model = SLO.ImprovedSLO(epoch=100, pop_size=50, c1=1.2, c2=1.5) model = SHO.OriginalSHO(epoch=100, pop_size=50, h_factor=5.0, n_trials=10) model = SFO.OriginalSFO(epoch=100, pop_size=50, pp=0.1, AP=4.0, epsilon=0.0001) model = SFO.ImprovedSFO(epoch=100, pop_size=50, pp=0.1) model = ServalOA.OriginalServalOA(epoch=100, pop_size=50) model = SeaHO.OriginalSeaHO(epoch=100, pop_size=50) model = SCSO.OriginalSCSO(epoch=100, pop_size=50) model = POA.OriginalPOA(epoch=100, pop_size=50) model = PFA.OriginalPFA(epoch=100, pop_size=50) model = OOA.OriginalOOA(epoch=100, pop_size=50) model = NGO.OriginalNGO(epoch=100, pop_size=50) model = NMRA.OriginalNMRA(epoch=100, pop_size=50, pb=0.75) model = NMRA.ImprovedNMRA(epoch=100, pop_size=50, pb=0.75, pm=0.01) model = MSA.OriginalMSA(epoch=100, pop_size=50, n_best=5, partition=0.5, max_step_size=1.0) model = MRFO.OriginalMRFO(epoch=100, pop_size=50, somersault_range=2.0) model = MRFO.WMQIMRFO(epoch=100, pop_size=50, somersault_range=2.0, pm=0.5) model = MPA.OriginalMPA(epoch=100, pop_size=50) model = MGO.OriginalMGO(epoch=100, pop_size=50) model = MFO.OriginalMFO(epoch=100, pop_size=50) model = JA.OriginalJA(epoch=100, pop_size=50) model = JA.LevyJA(epoch=100, pop_size=50) model = JA.DevJA(epoch=100, pop_size=50) model = HHO.OriginalHHO(epoch=100, pop_size=50) model = HGS.OriginalHGS(epoch=100, pop_size=50, PUP=0.08, LH=10000) model = HBA.OriginalHBA(epoch=100, pop_size=50) model = GWO.OriginalGWO(epoch=100, pop_size=50) model = GWO.RW_GWO(epoch=100, pop_size=50) model = GTO.OriginalGTO(epoch=100, pop_size=50, A=0.4, H=2.0) model = GTO.Matlab101GTO(epoch=100, pop_size=50) model = GTO.Matlab102GTO(epoch=100, pop_size=50) model = GOA.OriginalGOA(epoch=100, pop_size=50, c_min=0.00004, c_max=1.0) model = GJO.OriginalGJO(epoch=100, pop_size=50) model = FOX.OriginalFOX(epoch=100, pop_size=50, c1=0.18, c2=0.82) model = FOA.OriginalFOA(epoch=100, pop_size=50) model = FOA.WhaleFOA(epoch=100, pop_size=50) model = FOA.DevFOA(epoch=100, pop_size=50) model = FFO.OriginalFFO(epoch=100, pop_size=50) model = FFA.OriginalFFA(epoch=100, pop_size=50, gamma=0.001, beta_base=2, alpha=0.2, alpha_damp=0.99, delta=0.05, exponent=2) model = FA.OriginalFA(epoch=100, pop_size=50, max_sparks=50, p_a=0.04, p_b=0.8, max_ea=40, m_sparks=50) model = ESOA.OriginalESOA(epoch=100, pop_size=50) model = EHO.OriginalEHO(epoch=100, pop_size=50, alpha=0.5, beta=0.5, n_clans=5) model = DO.OriginalDO(epoch=100, pop_size=50) model = DMOA.OriginalDMOA(epoch=100, pop_size=50, n_baby_sitter=3, peep=2) model = DMOA.DevDMOA(epoch=100, pop_size=50, peep=2) model = CSO.OriginalCSO(epoch=100, pop_size=50, mixture_ratio=0.15, smp=5, spc=False, cdc=0.8, srd=0.15, c1=0.4, w_min=0.4, w_max=0.9) model = CSA.OriginalCSA(epoch=100, pop_size=50, p_a=0.3) model = CoatiOA.OriginalCoatiOA(epoch=100, pop_size=50) model = COA.OriginalCOA(epoch=100, pop_size=50, n_coyotes=5) model = BSA.OriginalBSA(epoch=100, pop_size=50, ff=10, pff=0.8, c1=1.5, c2=1.5, a1=1.0, a2=1.0, fc=0.5)
## Newly added algorithms in version 3.0.3 model = GWO.GWO_WOA(epoch=100, pop_size=50) model = GWO.IGWO(epoch=1000, pop_size=50, a_min = 0.02, a_max = 2.2) model = GWO.ChaoticGWO(epoch=1000, pop_size=50, chaotic_name="chebyshev", initial_chaotic_value=0.7) model = GWO.FuzzyGWO(epoch=1000, pop_size=50, fuzzy_name="increase") model = GWO.IncrementalGWO(epoch=1000, pop_size=50, explore_factor=1.5) model = GWO.ExGWO(epoch=1000, pop_size=50) model = GWO.DS_GWO(epoch=1000, pop_size=50, explore_ratio=0.4, n_groups=5) model = GWO.IOBL_GWO(epoch=1000, pop_size=50) model = GWO.OGWO(epoch=1000, pop_size=50, miu_factor=2.0, jumping_rate=0.05) model = GWO.ER_GWO(epoch=1000, pop_size=50, a_initial=2.0, a_final=0.0, miu_factor=1.0001) model = GWO.CG_GWO(epoch=1000, pop_size=50) model = ESO.OriginalESO(epoch=1000, pop_size=50) model = AO.AAO(epoch=1000, pop_size=50, sharpness=10.0, sigmoid_midpoint=0.5) model = EPC.DevEPC(epoch=1000, pop_size=50, heat_damping_factor=0.95, mutation_factor=0.1, spiral_a=1.0, spiral_b=0.5) model = SMO.DevSMO(epoch=1000, pop_size=50, max_groups = 5, perturbation_rate = 0.7) model = SquirrelSA.OriginalSquirrelSA(epoch=1000, pop_size=50, n_food_sources=4, predator_prob=0.1, gliding_constant=1.9, scaling_factor=18, beta=1.5) model = AFT.OriginalAFT(epoch=1000, pop_size=50) model = CDDO.OriginalCDDO(epoch=1000, pop_size=50, pattern_size=10, creativity_rate=0.1) model = FDO.OriginalFDO(epoch=1000, pop_size=50, weight_factor=0.1) model = LSHADEcnEpSin.OriginalLSHADEcnEpSin(epoch=1000, pop_size=50, miu_f = 0.5, miu_cr = 0.5, freq = 0.5, memory_size = 5, ps = 0.5, pc = 0.4, pop_size_min = 10) model = IMODE.OriginalIMODE(epoch=1000, pop_size=50, memory_size=5, archive_size=20)
</details>
✅ Examples
Simple Benchmark Function
MEALPY allows you to define your optimization problem in a couple of ways.
1. Define Problem as a Dictionary
You can quickly define your problem using a Python dictionary. However, this approach is only valid for problems with float decision variables.
python
from mealpy import FloatVar, SMA
import numpy as np
def objective_function(solution): return np.sum(solution**2)
problem = { "obj_func": objective_function, "bounds": FloatVar(lb=(-100., )30, ub=(100., )30), "minmax": "min", "log_to": "console", }
Run the algorithm
model = SMA.OriginalSMA(epoch=100, pop_size=50, pr=0.03) g_best = model.solve(problem) print(f"Best solution: {g_best.solution}, Best fitness: {g_best.target.fitness}")python from mealpy import Problem, FloatVar, BBO import numpy as np#### 2. Define a Custom Problem ClassFloatVarFor more complex scenarios, especially when your decision variables are not exclusively
, we recommend defining a custom class that inherits from the Problem class. Let's demonstrate this with a simple "Squared" class.__init__In the
method of your custom Problem class (e.g., Squared class), you must set the bounds and minmax attributes of the problem.bounds+
: Defines the search space and the type of decision variables (e.g.,FloatVar,IntegerVar).minmax+
: A string indicating whether the problem is a minimization ("min") or maximization ("max") problem.obj_func()After defining the initialization, you must override the abstract method
. This method is the core of your problem definition:data+ It takes a single parameter: solution (the encoded solution vector generated by the optimizer).
+ It must return the objective function value (or fitness) for the given solution.
The resulting code structure for a custom problem class would look similar to the snippet below. You can include any additional parameters you need in your custom class (like '
' or 'name' in this example).
Our custom problem class
class Squared(Problem): def __init__(self, bounds=None, minmax="min", data=None, **kwargs): super().__init__(bounds, minmax, **kwargs) self.data = data # This is additional variable use for passing data to objective functiondef obj_func(self, solution): return np.sum(solution ** 2)
Now, we define an algorithm, and pass an instance of our Squared class as the problem argument.
bound = FloatVar(lb=(-10., )20, ub=(10., )20, name="my_var") # The name of variable is important when decoding.
problem = Squared(bounds=bound, minmax="min", name="Squared", data="Amazing")
model = BBO.OriginalBBO(epoch=100, pop_size=20)
g_best = model.solve(problem)
Show some attributes
print(g_best.solution)
print(g_best.target.fitness)
print(g_best.target.objectives)
print(g_best)
print(model.get_parameters())
print(model.get_name())
print(model.get_attributes()["g_best"])
print(model.problem.get_name())
print(model.problem.n_dims)
print(model.problem.bounds)
print(model.problem.lb)
print(model.problem.ub)
``
We provide many examples for complicated applications that can use Mealpy to solve.
🚀 Mealpy Applications
MEALPY is a versatile library capable of solving a wide array of complex optimization problems across various domains. Below are examples showcasing its diverse applications.
1. General Optimization Problems
These examples demonstrate MEALPY's use in common optimization scenarios.
- Large-Scale Optimization example
- Distributed Optimization / Parallelization Optimization example
- Constrained Benchmark Function example
- Multi-objective Benchmark Function example
2. Machine Learning & AI Optimization
MEALPY can be effectively used to optimize various aspects of Machine Learning and AI models.
- Optimize Machine Learning Model (SVM) Hyperparameters example
- Optimize Linear Regression Model with Pytorch: example
3. Combinatorial Optimization Problems
MEALPY excels at solving complex combinatorial problems, which involve finding an optimal object from a finite set of objects.
- Traveling Salesman Problem (TSP) example
- Job Shop Scheduling Problem example
- Shortest Path Problem example
- Location Optimization example
- Supply Chain Optimization example
- Healthcare Workflow Optimization Problem example
- Production Optimization Problem example
- Employee Rostering Problem example
- Maintenance Scheduling example
- Cloud task scheduling example
4. Advanced Integration Examples
MEALPY's flexibility allows for integration into more specialized systems and workflows.
MEALPY + Neural Networks (Replacing Gradient Descent)
- Time-series Problem:
- Classification Problem:
MEALPY + Neural Network (Optimize Neural Network Hyper-parameter)
Code: Link
5. Dedicated Utility Classes
MEALPY includes specialized classes to streamline common optimization tasks.
- Tuner class (GridSearchCV/ParameterSearch, Hyper-parameter tuning) example
- Multitask class (Multitask solver) example
- Visualization Tutorials
6. External Projects & More Examples
Explore additional advanced examples and dedicated projects showcasing MEALPY's capabilities.
For more usage examples please look at examples folder. More advanced examples can also be found in the Mealpy-examples repository.7. Tutorial Videos & Resources
All tutorial videos: Link
All code examples: Link
All visualization examples: Link
📚 Documents
📎 Official channels
- 🔗 Official source code repository
- 📘 Official document
- 📦 Download releases
- 🐞 Issue tracker
- 📝 Notable changes log
- 📝 Examples with different meapy version
- 💬 Official discussion group
🌟 MEALPY ecosystem
- Mealpy + Multi-Layer Perceptron
- Mealpy + Extreme Learning Machine
- Mealpy + Random Vector Functional Link Neural Network
- Mealpy + KMeans clustering
- Mealpy + Cascade-Forward Neural Network
- Mealpy + Higher Order Functional Link Neural Network
- Mealpy + Radial Basis Function
- Mealpy + Adaptive Neuro Fuzzy Inference System
- Mealpy + Wavelet Neural Network
- Mealpy + Kolmogorov–Arnold Network
- Mealpy + Feature Selection
- Mealpy + Scikit-Learn
- Mealpy + Immune Algorithm-Inspired Neural Network
References
A
- ABC - Artificial Bee Colony
- ACOR - Ant Colony Optimization.
- ALO - Ant Lion Optimizer
- AEO - Artificial Ecosystem-based Optimization
- ASO - Atom Search Optimization
- ArchOA - Archimedes Optimization Algorithm
- AOA - Arithmetic Optimization Algorithm
- AO - Aquila Optimizer
- AVOA - African Vultures Optimization Algorithm
- AGTO - Artificial Gorilla Troops Optimization
- ARO - Artificial Rabbits Optimization:
- AFT - Ali baba and the Forty Thieves:
B
- BFO - Bacterial Foraging Optimization
- BeesA - Bees Algorithm
- BBO - Biogeography-Based Optimization
- BA - Bat Algorithm
- BSO - Brain Storm Optimization
- BSA - Bird Swarm Algorithm
- BMO - Barnacles Mating Optimizer:
- BES - Bald Eagle Search
- BRO - Battle Royale Optimization
C
- CA - Culture Algorithm
- CEM - Cross Entropy Method
- CSO - Cat Swarm Optimization
- CSA - Cuckoo Search Algorithm
- CRO - Coral Reefs Optimization
- COA - Coyote Optimization Algorithm
- CHIO - Coronavirus Herd Immunity Optimization
- CGO - Chaos Game Optimization
- CSA - Circle Search Algorithm
- CDDO - Child Drawing Development Optimization
D
- DE - Differential Evolution
... (README truncated for length)