mealpy.swarm_based package
mealpy.swarm_based.ABC module
- class mealpy.swarm_based.ABC.OriginalABC(epoch: int = 10000, pop_size: int = 100, n_limits: int = 25, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Artificial Bee Colony (ABC)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
n_limits (int) – Limit of trials before abandoning a food source, default=25.
References
Karaboga, Dervis, and Bahriye Basturk. “A powerful and efficient algorithm for numerical function optimization: artificial bee colony (ABC) algorithm.” Journal of global optimization 39.3 (2007): 459-471. https://doi.org/10.1007/s10898-007-9149-x
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ABC >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = ABC.OriginalABC(epoch=1000, pop_size=50, n_limits = 50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.ACOR module
- class mealpy.swarm_based.ACOR.OriginalACOR(epoch: int = 10000, pop_size: int = 100, sample_count: int = 25, intent_factor: float = 0.5, zeta: float = 1.0, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Ant Colony Optimization Continuous (ACOR)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
n_limits (int) – Limit of trials before abandoning a food source, default=25.
sample_count (int) – Valid range [2, 10000], Number of Newly Generated Samples, default = 25.
intent_factor (float) – Good range [0.2, 1.0], Intensification Factor (Selection Pressure), (q in the paper), default = 0.5.
zeta (float) – Good range [1, 2, 3], Deviation-Distance Ratio, default = 1.0.
References
Socha, K. and Dorigo, M., 2008. Ant colony optimization for continuous domains. European journal of operational research, 185(3), pp.1155-1173. https://doi.org/10.1016/j.ejor.2006.06.046
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ACOR >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = ACOR.OriginalACOR(epoch=1000, pop_size=50, sample_count = 25, intent_factor = 0.5, zeta = 1.0) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.AGTO module
- class mealpy.swarm_based.AGTO.MGTO(epoch: int = 10000, pop_size: int = 100, pp: float = 0.03, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Modified Gorilla Troops Optimization (mGTO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
pp (float) – The probability of transition in exploration phase (p in the paper), default = 0.03
References
Mostafa, R. R., Gaheen, M. A., Abd ElAziz, M., Al-Betar, M. A., & Ewees, A. A. (2023). An improved gorilla troops optimizer for global optimization problems and feature selection. Knowledge-Based Systems, 110462. https://doi.org/10.1016/j.knosys.2023.110462
Examples
>>> import numpy as np >>> from mealpy import FloatVar, AGTO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = AGTO.MGTO(epoch=1000, pop_size=50, pp=0.03) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.AGTO.OriginalAGTO(epoch: int = 10000, pop_size: int = 100, p1: float = 0.03, p2: float = 0.8, beta: float = 3.0, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Artificial Gorilla Troops Optimization (AGTO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
p1 (float) – The probability of transition in exploration phase (p in the paper), default = 0.03.
p2 (float) – The probability of transition in exploitation phase (w in the paper), default = 0.8.
beta (float) – Coefficient in updating equation, should be in [-5.0, 5.0], default = 3.0.
References
Abdollahzadeh, B., Soleimanian Gharehchopogh, F., & Mirjalili, S. (2021). Artificial gorilla troops optimizer: a new nature‐inspired metaheuristic algorithm for global optimization problems. International Journal of Intelligent Systems, 36(10), 5887-5958. https://doi.org/10.1002/int.22535
Van Thieu, Nguyen, and La Van Quan. “Artificial Gorilla Troops Optimizer.” Encyclopedia of Engineering Optimization and Heuristics. Singapore: Springer Nature Singapore, 2026. 1-9. https://doi.org/10.1007/978-981-96-8165-5_56-1
Examples
>>> import numpy as np >>> from mealpy import FloatVar, AGTO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = AGTO.OriginalAGTO(epoch=1000, pop_size=50, p1=0.03, p2=0.8, beta=3.0) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.AHO module
- class mealpy.swarm_based.AHO.OriginalAHO(epoch: int = 10000, pop_size: int = 100, theta: float = 0.26, omega: float = 0.01, **kwargs)[source]
Bases:
OptimizerThe original version of: Archerfish Hunting Optimizer (AHO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
theta (float) – Good range [0, pi], The swapping angle between exploration and exploitation, default: pi/12.
omega (float) – Good range [0, 100.], The attractiveness rate, default: 0.01.
Danger
Empirical evaluations have exposed several critical flaws in its fundamental design:
Architectural Inefficiency: Unlike standard metaheuristic algorithms that operate with O(N) population loops, AHO explicitly employs deeply nested O(N^2) population loops during its exploration (shooting) phase. This unorthodox design causes severe computational bottlenecking and wastes resources without yielding proportional exploration benefits.
Convergence Failure & Literature Discrepancy: Independent testing reveals that AHO struggles to converge even on simple unimodal landscapes (e.g., the Sphere function), failing to reach the global optimum after 10,000+ iterations. These empirical outcomes strongly contradict the high-performance claims published in the original paper.
Production Unsuitability: Due to the extreme computational overhead and stagnation risks, this implementation is strictly provided for academic reproducibility and critical analysis. It is NOT recommended for solving practical, large-scale, or real-world optimization problems.
References
Zitouni, F., Harous, S., Belkeram, A., & Hammou, L. E. B. (2022). The archerfish hunting optimizer: A novel metaheuristic algorithm for global optimization. Arabian Journal for Science and Engineering, 47(2), 2513-2553. https://doi.org/10.1007/s13369-021-06208-z
Examples
>>> import numpy as np >>> from mealpy import FloatVar, AHO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem = { >>> "obj_func": objective_function, >>> "bounds": FloatVar(lb=[-10., ]*10, ub=[10., ]*10), >>> "minmax": "min", >>> } >>> >>> model = AHO.OriginalAHO(epoch=100, pop_size=50, theta=0.26, omega=0.01) >>> g_best = model.solve(problem) >>> print(f"Best solution: {g_best.solution}, Best fitness: {g_best.target.fitness}")
mealpy.swarm_based.ALO module
- class mealpy.swarm_based.ALO.DevALO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OriginalALOOur developed version: Ant Lion Optimizer (ALO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Note
Improved performance by removing the for loop when creating n random walks
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ALO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = ALO.DevALO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.ALO.OriginalALO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Ant Lion Optimizer (ALO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Links
References
Mirjalili, S., 2015. The ant lion optimizer. Advances in engineering software, 83, pp.80-98.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ALO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = ALO.OriginalALO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.AO module
- class mealpy.swarm_based.AO.AAO(epoch=10000, pop_size=100, sharpness=10.0, sigmoid_midpoint=0.5, **kwargs)[source]
Bases:
OptimizerThe original version of: Adaptive Aquila Optimizer (AAO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
sharpness (float) – Variable that controls the sharpness of the transition between exploration and exploitation. Default is 10.0, valid range: [0.1, 10000.0].
sigmoid_midpoint (float) – Variable that controls the midpoint of the sigmoid function as it determines when the transition should be applied, default is 0.5, valid range: [0.0, 1.0].
References
Al-Selwi, S. M., Hassan, M. F., Abdulkadir, S. J., Ragab, M. G., Alqushaibi, A., & Sumiea, E. H. (2024). Smart grid stability prediction using adaptive aquila optimizer and ensemble stacked bilstm. Results in Engineering, 24, 103261. https://doi.org/10.1016/j.rineng.2024.103261
Examples
>>> import numpy as np >>> from mealpy import FloatVar, AO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(n_vars=30, lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = AO.AAO(epoch=1000, pop_size=50, sharpness=10.0, sigmoid_midpoint=0.5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.AO.OriginalAO(epoch=10000, pop_size=100, **kwargs)[source]
Bases:
OptimizerThe original version of: Aquila Optimization (AO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Abualigah, L., Yousri, D., Abd Elaziz, M., Ewees, A.A., Al-Qaness, M.A. and Gandomi, A.H., 2021. Aquila optimizer: a novel meta-heuristic optimization algorithm. Computers & Industrial Engineering, 157, p.107250. https://doi.org/10.1016/j.cie.2021.107250
Examples
>>> import numpy as np >>> from mealpy import FloatVar, AO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = AO.OriginalAO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.ARO module
- class mealpy.swarm_based.ARO.IARO(epoch=10000, pop_size=100, **kwargs)[source]
Bases:
OptimizerOur improved version of ARO: Improved Artificial Rabbits Optimization (IARO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ARO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = ARO.IARO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.ARO.LARO(epoch=10000, pop_size=100, **kwargs)[source]
Bases:
OptimizerThe original version of: Lévy flight Artificial Rabbit Algorithm (LARO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Wang, Y., Huang, L., Zhong, J., & Hu, G. (2022). LARO: Opposition-based learning boosted artificial rabbits-inspired optimization algorithm with Lévy flight. Symmetry, 14(11), 2282. https://doi.org/10.3390/sym14112282
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ARO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = ARO.LARO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.ARO.OriginalARO(epoch=10000, pop_size=100, **kwargs)[source]
Bases:
OptimizerThe original version of: Artificial Rabbits Optimization (ARO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Wang, L., Cao, Q., Zhang, Z., Mirjalili, S., & Zhao, W. (2022). Artificial rabbits optimization: A new bio-inspired meta-heuristic algorithm for solving engineering optimization problems. Engineering Applications of Artificial Intelligence, 114, 105082. https://doi.org/10.1016/j.engappai.2022.105082
Van Thieu, Nguyen, and Ngoc Hung Nguyen. “Artificial Rabbits Optimizer.” Encyclopedia of Engineering Optimization and Heuristics. Singapore: Springer Nature Singapore, 2026. 1-9. https://doi.org/10.1007/978-981-96-8165-5_55-1
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ARO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = ARO.OriginalARO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.AVOA module
- class mealpy.swarm_based.AVOA.OriginalAVOA(epoch: int = 10000, pop_size: int = 100, p1: float = 0.6, p2: float = 0.4, p3: float = 0.6, alpha: float = 0.8, gama: float = 2.5, **kwargs: object)[source]
Bases:
OptimizerThe original version of: African Vultures Optimization Algorithm (AVOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
p1 (float) – The probability of status transition, default 0.6
p2 (float) – The probability of status transition, default 0.4
p3 (float) – The probability of status transition, default 0.6
alpha (float) – The probability of 1st best, default = 0.8.
gama (float) – The factor in the paper (not much affect to algorithm), default = 2.5
Links
References
Abdollahzadeh, B., Gharehchopogh, F. S., & Mirjalili, S. (2021). African vultures optimization algorithm: A new nature-inspired metaheuristic algorithm for global optimization problems. Computers & Industrial Engineering, 158, 107408.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, AVOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = AVOA.OriginalAVOA(epoch=1000, pop_size=50, p1=0.6, p2=0.4, p3=0.6, alpha=0.8, gama=2.5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.BA module
- class mealpy.swarm_based.BA.AdaptiveBA(epoch: int = 10000, pop_size: object = 100, loudness_min: float = 1.0, loudness_max: float = 2.0, pr_min: float = 0.15, pr_max: float = 0.85, pf_min: float = 0.0, pf_max: float = 10.0, **kwargs: object)[source]
Bases:
OptimizerOur adaptive version of BA: Adaptive Bat-inspired Algorithm (ABA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
loudness_min (float) – A_min - loudness, default=1.0. Good range [0.5, 1.5].
loudness_max (float) – The range is [1.5, 3.0], A_max - loudness, default=2.0
pr_min (float) – Pulse rate / emission rate min, default = 0.15.
pr_max (float) – Pulse rate / emission rate min, default = 0.85.
pf_min (float) – The pulse frequency min, default=0.
pf_max (float) – The pulse frequency max, default = 10.
Note
The value of A and r are changing after each iteration
Examples
>>> import numpy as np >>> from mealpy import FloatVar, BA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = BA.AdaptiveBA(epoch=1000, 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.) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.BA.DevBA(epoch=10000, pop_size=100, pulse_rate=0.95, pf_min=0.0, pf_max=10.0, **kwargs)[source]
Bases:
OptimizerOur developed version: Developed Bat-inspired Algorithm (DBA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
pulse_rate (float) – Good range [0.7, 1.0], pulse rate / emission rate, default = 0.95
pf_min (float) – The pulse frequency min, default = 0.
pf_max (float) – The pulse frequency, default = 10.
Note
A (loudness) parameter is removed.
- Flow is changed:
1st the exploration phase is proceed (using frequency)
2nd: If new position has better fitness, replace the old position
3rd: Otherwise, proceed exploitation phase (using finding around the best position so far)
Examples
>>> import numpy as np >>> from mealpy import FloatVar, BA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = BA.DevBA(epoch=1000, pop_size=50, pulse_rate = 0.95, pf_min = 0., pf_max = 10.) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.BA.OriginalBA(epoch: int = 10000, pop_size: int = 100, loudness: float = 0.8, pulse_rate: float = 0.95, pf_min: float = 0.0, pf_max: float = 10.0, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Bat-inspired Algorithm (BA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
loudness (float) – The range is (0.0, 1.0), loudness, default = 0.8.
pulse_rate (float) – Good range (0.15, 0.85), pulse rate / emission rate, default = 0.95.
pf_min (float) – The pulse frequency min, default=0.1. Range in [0, 3.0]
pf_max (float) – The pulse frequency max, default = 10. Range in [5., 20.]
Note
The value of A and r parameters are constant
References
Yang, X.S., 2010. A new metaheuristic bat-inspired algorithm. In Nature inspired cooperative strategies for optimization (NICSO 2010) (pp. 65-74). Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-12538-6_6
Examples
>>> import numpy as np >>> from mealpy import FloatVar, BA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = BA.OriginalBA(epoch=1000, pop_size=50, loudness=0.8, pulse_rate=0.95, pf_min=0.1, pf_max=10.0) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.BES module
- class mealpy.swarm_based.BES.OriginalBES(epoch: int = 10000, pop_size: int = 100, a_factor: int = 10, R_factor: float = 1.5, alpha: float = 2.0, c1: float = 2.0, c2: float = 2.0, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Bald Eagle Search (BES)
- Parameters
epoch (int) – Maximum number of iterations. Default is 10000.
pop_size (int) – Number of population size. Default is 100.
a_factor (int) – Determines the corner between point search in the central point, in range [5, 10]. Default is 10.
R_factor (float) – Determines the number of search cycles, in range [0.5, 2.0]. Default is 1.5.
alpha (float) – Parameter for controlling the changes in position, in range [1.5, 2.0]. Default is 2.0.
c1 (float) – Increases the movement intensity of bald eagles towards the best and centre points, in range [1.0, 2.0]. Default is 2.0.
c2 (float) – Increases the movement intensity of bald eagles towards the best and centre points. Default is 2.0.
References
Alsattar, H.A., Zaidan, A.A. and Zaidan, B.B., 2020. Novel meta-heuristic bald eagle search optimisation algorithm. Artificial Intelligence Review, 53(3), pp.2237-2264. https://doi.org/10.1007/s10462-019-09732-5
Examples
>>> import numpy as np >>> from mealpy import FloatVar, BES >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = BES.OriginalBES(epoch=1000, pop_size=50, a_factor = 10, R_factor = 1.5, alpha = 2.0, c1 = 2.0, c2 = 2.0) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.BFO module
- class mealpy.swarm_based.BFO.ABFO(epoch: int = 10000, pop_size: int = 100, C_s: float = 0.1, C_e: float = 0.001, Ped: float = 0.01, Ns: int = 4, N_adapt: int = 2, N_split: int = 40, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Adaptive Bacterial Foraging Optimization (ABFO)
- Parameters
epoch (int) – Maximum number of iterations. Default is 10000.
pop_size (int) – Number of population size. Default is 100.
C_s (float) – Step size start. Default is 0.1.
C_e (float) – Step size end. Default is 0.001.
Ped (float) – Probability of elimination. Default is 0.01.
Ns (int) – Swim length. Default is 4.
N_adapt (int) – Dead threshold value. Default is 2.
N_split (int) – Split threshold value. Default is 40.
References
Nguyen, T., Nguyen, B.M. and Nguyen, G., 2019, April. Building resource auto-scaler with functional-link neural network and adaptive bacterial foraging optimization. In International Conference on Theory and Applications of Models of Computation (pp. 501-517). Springer, Cham. https://doi.org/10.1007/978-3-030-14812-6_31
Examples
>>> import numpy as np >>> from mealpy import FloatVar, BFO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = BFO.ABFO(epoch=1000, pop_size=50, C_s=0.1, C_e=0.001, Ped = 0.01, Ns = 4, N_adapt = 2, N_split = 40) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- generate_agent(solution: Optional[ndarray] = None) Agent[source]
Generate new agent with full information
- Parameters
solution (np.ndarray) – The solution
- class mealpy.swarm_based.BFO.OriginalBFO(epoch: int = 10000, pop_size: int = 100, Ci: float = 0.01, Ped: float = 0.25, Nc: int = 5, Ns: int = 4, d_attract: float = 0.1, w_attract: float = 0.2, h_repels: float = 0.1, w_repels: float = 10, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Bacterial Foraging Optimization (BFO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Ci (float) – Step size, in range [0.01, 0.3]. Default is 0.01.
Ped (float) – Probability of elimination, in range [0.1, 0.5]. Default is 0.25.
Ned (int) – Number of elimination-dispersal steps. Default is 5.
Nre (int) – Number of reproduction steps. Default is 50.
Nc (int) – Number of chemotactic steps (reduced to Original Nc/2), in range [3, 10]. Default is 5.
Ns (int) – Swim length, in range [2, 10]. Default is 4.
d_attract (float) – Coefficient to calculate attract force. Default is 0.1.
w_attract (float) – Coefficient to calculate attract force. Default is 0.2.
h_repels (float) – Coefficient to calculate repel force. Default is 0.1.
w_repels (float) – Coefficient to calculate repel force. Default is 10.0.
Attention
Ned and Nre parameters are replaced by epoch (generation)
The Nc parameter will also decrease to reduce the computation time.
Cost in this version equal to Fitness value in the paper.
https://www.cleveralgorithms.com/nature-inspired/swarm/bfoa.html
References
Passino, K.M., 2002. Biomimicry of bacterial foraging for distributed optimization and control. IEEE control systems magazine, 22(3), pp.52-67. https://doi.org/10.1109/MCS.2002.1004010
Examples
>>> import numpy as np >>> from mealpy import FloatVar, BFO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = BFO.OriginalBFO(epoch=1000, 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) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
mealpy.swarm_based.BSA module
- class mealpy.swarm_based.BSA.OriginalBSA(epoch: int = 10000, pop_size: int = 100, ff: int = 10, pff: float = 0.8, c1: float = 1.5, c2: float = 1.5, a1: float = 1.0, a2: float = 1.0, fc: float = 0.5, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Bird Swarm Algorithm (BSA)
- Parameters
epoch (int) – Maximum number of iterations. Default is 10000.
pop_size (int) – Number of population size. Default is 100.
ff (int) – Flight frequency. Default is 10.
pff (float) – The probability of foraging for food. Default is 0.8.
c1 (float) – Cognitive accelerated coefficient same as PSO. Default is 1.5.
c2 (float) – Social accelerated coefficient same as PSO. Default is 1.5.
a1 (float) – The indirect effect on the birds’ vigilance behaviours. Default is 1.0.
a2 (float) – The direct effect on the birds’ vigilance behaviours. Default is 1.0.
fc (float) – The followed coefficient. Default is 0.5.
Links
References
Meng, X.B., Gao, X.Z., Lu, L., Liu, Y. and Zhang, H., 2016. A new bio-inspired optimisation algorithm: Bird Swarm Algorithm. Journal of Experimental & Theoretical Artificial Intelligence, 28(4), pp.673-687.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, BSA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = BSA.OriginalBSA(epoch=1000, pop_size=50, ff = 10, pff = 0.8, c1 = 1.5, c2 = 1.5, a1 = 1.0, a2 = 1.0, fc = 0.5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
mealpy.swarm_based.BWO module
- class mealpy.swarm_based.BWO.OriginalBWO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Beluga Whale Optimization (BWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Zhong, Changting, Gang Li, and Zeng Meng. “Beluga whale optimization: A novel nature-inspired metaheuristic algorithm.” Knowledge-based systems 251 (2022): 109215. https://doi.org/10.1016/j.knosys.2022.109215
Examples
>>> import numpy as np >>> from mealpy import FloatVar, BWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = BWO.OriginalBWO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.BeesA module
- class mealpy.swarm_based.BeesA.CleverBookBeesA(epoch: int = 10000, pop_size: int = 100, n_elites: int = 16, n_others: int = 4, patch_size: float = 5.0, patch_reduction: float = 0.985, n_sites: int = 3, n_elite_sites: int = 1, **kwargs: object)[source]
Bases:
OptimizerThe original version of BeesA in clever book: Bees Algorithm (CB-BeesA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
n_elites (int) – Number of employed bees which provided for good location.
n_others (int) – Number of employed bees which provided for other location.
patch_size (float) – Calculated as patch_variables = patch_variables * patch_reduction.
patch_reduction (float) – The reduction factor.
n_sites (int) – Number of sites for 3 bees (employed bees, onlookers and scouts).
n_elite_sites (int) – Number of elite sites (1 good partition).
Note
This version is based on ABC in the book Clever Algorithms
Improved the function search_neighborhood
References
D. T. Pham, Ghanbarzadeh A., Koc E., Otri S., Rahim S., and M.Zaidi. The bees algorithm - a novel tool for complex optimisation problems. In Proceedings of IPROMS 2006 Conference, pages 454–461, 2006.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, BeesA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = BeesA.CleverBookBeesA(epoch=1000, pop_size=50, n_elites = 16, n_others = 4, >>> patch_size = 5.0, patch_reduction = 0.985, n_sites = 3, n_elite_sites = 1) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.BeesA.OriginalBeesA(epoch: int = 10000, pop_size: int = 100, selected_site_ratio: float = 0.5, elite_site_ratio: float = 0.4, selected_site_bee_ratio: float = 0.1, elite_site_bee_ratio: float = 2.0, dance_radius: float = 0.1, dance_reduction: float = 0.99, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Bees Algorithm (BeesA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
selected_site_ratio (float) – Ratio of the selected sites. Default is 0.5.
elite_site_ratio (float) – Ratio of the elite sites. Default is 0.4.
selected_site_bee_ratio (float) – Ratio of bees assigned to the selected sites. Default is 0.1.
elite_site_bee_ratio (float) – Ratio of bees assigned to the elite sites. Default is 2.0.
dance_radius (float) – Initial radius of the bees’ dance (search space). Default is 0.1.
dance_reduction (float) – Reduction factor for the dance radius over iterations. Default is 0.99.
Links
https://www.sciencedirect.com/science/article/pii/B978008045157250081X
https://www.tandfonline.com/doi/full/10.1080/23311916.2015.1091540
References
Pham, D.T., Ghanbarzadeh, A., Koç, E., Otri, S., Rahim, S. and Zaidi, M., 2006. The bees algorithm—a novel tool for complex optimisation problems. In Intelligent production machines and systems (pp. 454-459). Elsevier Science Ltd.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, BeesA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = BeesA.OriginalBeesA(epoch=1000, 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) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.BeesA.ProbBeesA(epoch: int = 10000, pop_size: int = 100, recruited_bee_ratio: float = 0.1, dance_radius: float = 0.1, dance_reduction: float = 0.99, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Probabilistic Bees Algorithm (P-BeesA)
- Parameters
epoch (int) – Maximum number of iterations. Default is 10000.
pop_size (int) – Number of population size. Default is 100.
recruited_bee_ratio (float) – Percent of bees recruited. Default is 0.1.
dance_radius (float) – Bees dance radius. Default is 0.1.
dance_reduction (float) – Bees dance radius reduction rate. Default is 0.99.
References
Pham, D.T. and Castellani, M., 2015. A comparative study of the Bees Algorithm as a tool for function optimisation. Cogent Engineering, 2(1), p.1091540. https://doi.org/10.1080/23311916.2015.1091540
Examples
>>> import numpy as np >>> from mealpy import FloatVar, BeesA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = BeesA.ProbBeesA(epoch=1000, pop_size=50, recruited_bee_ratio = 0.1, dance_radius = 0.1, dance_reduction = 0.99) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.CCO module
- class mealpy.swarm_based.CCO.OriginalCCO(epoch=10000, pop_size=100, alpha=1.34, beta=0.3, **kwargs)[source]
Bases:
OptimizerThe original version of: Cuckoo Catfish Optimizer (CCO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
alpha (float) – Good range (0, 10.0), alpha parameter, default = 1.34 (as in Matlab code).
beta (float) – Good range (0, 10.0), beta parameter, default = 0.3 (as in Matlab code).
Danger
Excessive Complexity: This is the most complex and convoluted algorithm we have ever implemented. It is packed with nested operators that seem entirely disconnected from the actual behavior of a Cuckoo Catfish.
Arbitrary Logic: We get the distinct impression that the authors simply fabricated the equations and an excessive number of if-else conditions just to force the algorithm to perform well.
Lack of Conceptual Alignment: While the algorithm may appear mathematically sound, it lacks any real connection to its stated inspiration, the Cuckoo Catfish. We would advise researchers, especially those new to the field to avoid using such overly complex heuristics for development.
Computational Inefficiency: A major issue is that the actual computational complexity does not align with the claims made in the paper. The excessive sorting processes within the population update loops make the algorithm significantly slower than others.
Lack of Parallelizability: Furthermore, the algorithm is not inherently parallelizable, as the population updates are strictly interdependent.
Links
References
Wang, T. L., Gu, S. W., Liu, R. J., Chen, L. Q., Wang, Z., & Zeng, Z. Q. (2025). Cuckoo catfish optimizer: a new meta-heuristic optimization algorithm. Artificial Intelligence Review, 58(10), 326.
Examples
import numpy as np from mealpy import FloatVar, CCO def objective_function(solution): return np.sum(solution**2) problem_dict = { "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="x"), "minmax": "min", "obj_func": objective_function, } model = CCO.OriginalCCO(epoch=1000, pop_size=50, alpha=0.5, beta=1.0) g_best = model.solve(problem_dict) print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}")
mealpy.swarm_based.COA module
- class mealpy.swarm_based.COA.OriginalCOA(epoch: int = 10000, pop_size: int = 100, n_coyotes: int = 5, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Coyote Optimization Algorithm (COA)
Links
https://github.com/jkpir/COA/blob/master/COA.py (Old version Mealpy < 1.2.2)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
n_coyotes (int) – Good range [3, 15], number of coyotes per group, default=5
References
Pierezan, J. and Coelho, L.D.S., 2018, July. Coyote optimization algorithm: a new metaheuristic for global optimization problems. In 2018 IEEE congress on evolutionary computation (CEC) (pp. 1-8). IEEE.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, COA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = COA.OriginalCOA(epoch=1000, pop_size=50, n_coyotes = 5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
mealpy.swarm_based.CSA module
- class mealpy.swarm_based.CSA.OriginalCSA(epoch: int = 10000, pop_size: int = 100, p_a: float = 0.3, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Cuckoo Search Algorithm (CSA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
p_a (float) – Good range [0.1, 0.7], probability a, default=0.3
References
Yang, X.S. and Deb, S., 2009, December. Cuckoo search via Lévy flights. In 2009 World congress on nature & biologically inspired computing (NaBIC) (pp. 210-214). Ieee. https://doi.org/10.1109/NABIC.2009.5393690
Examples
>>> import numpy as np >>> from mealpy import FloatVar, CSA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = CSA.OriginalCSA(epoch=1000, pop_size=50, p_a = 0.3) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.CSO module
- class mealpy.swarm_based.CSO.OriginalCSO(epoch: int = 10000, pop_size: int = 100, mixture_ratio: float = 0.15, smp: int = 5, spc: bool = False, cdc: float = 0.8, srd: float = 0.15, c1: float = 0.4, w_min: float = 0.5, w_max: float = 0.9, selected_strategy: int = 1, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Cat Swarm Optimization (CSO)
- Parameters
epoch (int) – Maximum number of iterations. Default is 10000.
pop_size (int) – Number of population size. Default is 100.
mixture_ratio (float) – Ratio for joining seeking mode with tracing mode. Default is 0.15.
smp (int) – Seeking memory pool (e.g., clones). Larger is better but time-consuming. Default is 5.
spc (bool) – Self-position considering flag. Default is False.
cdc (float) – Counts of dimension to change. Larger provides more diversity but slow convergence. Default is 0.8.
srd (float) – Seeking range of the selected dimension. Smaller is better but slow convergence. Default is 0.15.
c1 (float) – Cognitive parameter, same as in PSO. Default is 0.4.
w_min (float) – Minimum inertia weight, same as in PSO. Default is 0.5.
w_max (float) – Maximum inertia weight, same as in PSO. Default is 0.9.
selected_strategy (int) – Strategy selection: 0 for best fitness, 1 for tournament, 2 for roulette wheel, otherwise random (decreases by quality). Default is 1.
Links
References
Chu, S.C., Tsai, P.W. and Pan, J.S., 2006, August. Cat swarm optimization. In Pacific Rim international conference on artificial intelligence (pp. 854-858). Springer, Berlin, Heidelberg.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, CSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = CSO.OriginalCSO(epoch=1000, 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) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
mealpy.swarm_based.ChOA module
- class mealpy.swarm_based.ChOA.OriginalChOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Chimp Optimization Algorithm (ChOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Khishe, M. and Mosavi, M.R., 2020. Chimp optimization algorithm. Expert systems with applications, 149, p.113338. https://doi.org/10.1016/j.eswa.2020.113338
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ChOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = ChOA.OriginalChOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.ChameleonSA module
- class mealpy.swarm_based.ChameleonSA.IChameleonSA(epoch=1000, pop_size=100, r_chaos: float = 0.3, k_spiral: float = 5.0, p1: float = 2.0, p2: float = 2.0, **kwargs)[source]
Bases:
OptimizerThe original version of: Improved Chameleon Swarm Algorithm (ICSA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
beta (float) – Lévy flight constant (Eq. 13), default = 1.5.
r_chaos (float) – Control parameter for logistic mapping (Eq. 10), default = 0.3
k_spiral (int) – Variation coefficient for spiral search (Eq. 11), default = 5
p1 (float) – Valid range [0, 10.] Personal best influence (From PSO), default=2.0.
p2 (float) – Valid range [0, 10.] Global best influence (From PSO), default=2.0.
Warning
Despite being claimed as an improved version, this algorithm still requires too many parameters and relies on standard PSO update operators.
Additionally, its NFE per iteration is 3x times higher than typical algorithms, so users should be mindful of the execution time.
References
Chen, Yaodan, Li Cao, and Yinggao Yue. “Hybrid Multi-Objective Chameleon Optimization Algorithm Based on Multi-Strategy Fusion and Its Applications.” Biomimetics 9.10 (2024): 583. https://doi.org/10.3390/biomimetics9100583
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ChameleonSA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = ChameleonSA.IChameleonSA(epoch=1000, pop_size=50, r_chaos=0.5, k_spiral=10., p1=5.0, p2=3.0) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}")
- class mealpy.swarm_based.ChameleonSA.OriginalChameleonSA(epoch=10000, pop_size=100, pp: float = 0.1, p1: float = 0.25, p2: float = 1.5, c1: float = 1.75, c2: float = 1.75, gama: float = 1.0, alpha: float = 3.5, rho: float = 1.0, **kwargs)[source]
Bases:
OptimizerThe original version of: Chameleon Swarm Algorithm (ChameleonSA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
pp (float) – Valid range [0, 1] Probability of the chameleon perceiving prey, default=0.1
p1 (float) – Valid range [0, 5.0] Exploration control parameter 1 (From PSO), default=0.25.
p2 (float) – Valid range [0, 5.0] Exploration control parameter 2 (From PSO), default=1.50.
c1 (float) – Valid range [0, 5.0] Personal best influence (From PSO), default=1.75.
c2 (float) – Valid range [0, 5.0] Global best influence (From PSO), default=1.75.
gama (float) – Valid range [0, 2] Constant controlling the exploration rate decay over iterations, default=1.0.
alpha (float) – Valid range [0, 10] Constant defining the steepness of the exploration decay curve, default=3.5.
rho (float) – Valid range [0, 2] Positive number, default=1.0.
Caution
This algorithm essentially relies on the update operators of the PSO algorithm. It has too many parameters, and the results are nowhere near as good as those presented in the paper.
Please note that the official MATLAB code deviates from the paper, using undocumented modifications to artificially boost performance.
This pure implementation is provided specifically so users can independently evaluate the algorithm’s true performance based solely on the published mathematical model, allowing you to verify whether the paper’s claims and results are legitimate.
Links
References
Braik, M. S. (2021). Chameleon Swarm Algorithm: A bio-inspired optimizer for solving engineering design problems. Expert Systems with Applications, 174, 114685.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ChameleonSA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = ChameleonSA.OriginalChameleonSA(epoch=1000, pop_size=50, pp=0.2, p1=0.3, p2=2.0, c1=2.0, c2=2.0, gama=1.0, alpha=5.0, rho=1.5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.CoatiOA module
- class mealpy.swarm_based.CoatiOA.OriginalCoatiOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Coati Optimization Algorithm (CoatiOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Links
https://www.sciencedirect.com/science/article/pii/S0950705122011042
https://www.mathworks.com/matlabcentral/fileexchange/116965-coa-coati-optimization-algorithm
Danger
Algorithm design is similar to Zebra Optimization Algorithm (ZOA), Osprey Optimization Algorithm (OOA), Pelican optimization algorithm (POA), Siberian Tiger Optimization (STO), Language Education Optimization (LEO), Serval Optimization Algorithm (SOA), Walrus Optimization Algorithm (WOA), Fennec Fox Optimization (FFO), Three-periods optimization algorithm (TPOA), Teamwork optimization algorithm (TOA), Northern goshawk optimization (NGO), Tasmanian devil optimization (TDO), Archery algorithm (AA), Cat and mouse based optimizer (CMBO)
It may be useful to compare the Matlab code of this algorithm with those of the similar algorithms to ensure its accuracy and completeness.
The article may share some similarities with previous work by the same authors, further investigation may be warranted to verify the benchmark results reported in the papers and ensure their reliability and accuracy.
References
Dehghani, M., Montazeri, Z., Trojovská, E., & Trojovský, P. (2023). Coati Optimization Algorithm: A new bio-inspired metaheuristic algorithm for solving optimization problems. Knowledge-Based Systems, 259, 110011.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, CoatiOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = CoatiOA.OriginalCoatiOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.CrayfishOA module
- class mealpy.swarm_based.CrayfishOA.OriginalCrayfishOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Crayfish Optimization Algorithm (COA)
epoch (int): maximum number of iterations, default = 10000
pop_size (int): number of population size, default = 100
References
Jia, H., Rao, H., Wen, C., & Mirjalili, S. (2023). Crayfish optimization algorithm. Artificial Intelligence Review, 56(Suppl 2), 1919-1979. https://doi.org/10.1007/s10462-023-10567-4
Examples
>>> import numpy as np >>> from mealpy import FloatVar, CrayfishOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = CrayfishOA.OriginalCrayfishOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}")
mealpy.swarm_based.DBO module
- class mealpy.swarm_based.DBO.OriginalDBO(epoch: int = 10000, pop_size: int = 100, kk: float = 0.1, bb: float = 0.3, ss: float = 0.5, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Dung Beetle Optimizer (DBO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
kk (float) – Deflection coefficient in rolling behavior, in range [0.0, 2.0]. Default is 0.1.
bb (float) – Attraction toward worst position, in range [0.0, 1.0]. Default is 0.3.
ss (float) – Attraction factor toward local best position, in range [0.0, 1.0]. Default is 0.3.
Links
References
Xue, J., & Shen, B. (2022). Dung beetle optimizer: A new meta-heuristic algorithm for global optimization. The Journal of Supercomputing, 79, 7305–7336.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, DBO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = DBO.OriginalDBO(epoch=1000, pop_size=50, kk=0.1, bb=0.5, ss=0.5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.DMOA module
- class mealpy.swarm_based.DMOA.DevDMOA(epoch: int = 10000, pop_size: int = 100, peep: float = 2, **kwargs: object)[source]
Bases:
OptimizerOur developed version: Dwarf Mongoose Optimization Algorithm (DMOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
peep (float) – Peep parameter, in range [1.0, 10.0]. Default is 2.0.
note:: (..) –
Removed the parameter n_baby_sitter
Changed in section # Next Mongoose position
Removed the meaningless variable tau
Examples
>>> import numpy as np >>> from mealpy import FloatVar, DMOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = DMOA.DevDMOA(epoch=1000, pop_size=50, peep = 2) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.DMOA.OriginalDMOA(epoch: int = 10000, pop_size: int = 100, n_baby_sitter: int = 3, peep: float = 2, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Dwarf Mongoose Optimization Algorithm (DMOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
n_baby_sitter (int) – Number of baby sitters, in range [2, 10]. Default is 3.
peep (float) – Peep parameter, in range [1.0, 10.0]. Default is 2.0.
Note
The Matlab code differs slightly from the original paper
There are some parameters and equations in the Matlab code that don’t seem to have any meaningful purpose.
The algorithm seems to be weak on solving several problems.
Links
References
Agushaka, J. O., Ezugwu, A. E., & Abualigah, L. (2022). Dwarf mongoose optimization algorithm. Computer methods in applied mechanics and engineering, 391, 114570.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, DMOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = DMOA.OriginalDMOA(epoch=1000, pop_size=50, n_baby_sitter = 3, peep = 2) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.DO module
- class mealpy.swarm_based.DO.OriginalDO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Dragonfly Optimization (DO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Mirjalili, S., 2016. Dragonfly algorithm: a new meta-heuristic optimization technique for solving single-objective, discrete, and multi-objective problems. Neural computing and applications, 27(4), pp.1053-1073. https://doi.org/10.1007/s00521-015-1920-1
Examples
>>> import numpy as np >>> from mealpy import FloatVar, DO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = DO.OriginalDO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.DSO module
- class mealpy.swarm_based.DSO.OriginalDSO(epoch: int = 10000, pop_size: int = 100, lamda: float = 0.9, eta: float = 0.2, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Dove Swarm Optimization (DSO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
lamda (float) – Satiety decay rate, in range [0.0, 1.0]. Default is 0.9.
eta (float) – Scaled-step for position updates, in range [-100.0, 100.0]. Default is 0.2.
Note
This algorithm is of low quality as it lacks any novel or specialized operators, making it highly prone to getting trapped in local optima.
Relying on fitness and distance within the operator is not an effective approach to improving algorithmic performance.
References
Su, M. C., Chen, J. H., Utami, A. M., Lin, S. C., & Wei, H. H. (2022). Dove swarm optimization algorithm. IEEE Access, 10, 46690-46696. https://doi.org/10.1109/ACCESS.2022.3170112
Examples
>>> import numpy as np >>> from mealpy import FloatVar, DSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = DSO.OriginalDSO(epoch=1000, pop_size=50, lamda=0.9, eta=0.2) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.DandelionO module
- class mealpy.swarm_based.DandelionO.DevDandelionO(epoch=10000, pop_size=100, **kwargs)[source]
Bases:
OptimizerThe developed version: Dandelion Optimizer (DandelionO)
epoch (int): Maximum number of iterations, default = 10000
pop_size (int): Population size, default = 100
Danger
This dev version was contributed by the user “Halil”. Several parameters—such as alpha, a, b, and k, differ from the original paper.
Furthermore, the Levy function is applied to the entire population simultaneously, whereas the paper specifies generating a Levy step for each individual. If you choose to use this version, it must be clearly stated that it is not the original implementation.
References
Zhao, S., Zhang, T., Ma, S., & Chen, M. (2022). Dandelion Optimizer: A nature-inspired metaheuristic algorithm for engineering applications. Engineering Applications of Artificial Intelligence, 114, 105075. https://doi.org/10.1016/j.engappai.2022.105075
Examples
>>> import numpy as np >>> from mealpy import FloatVar, DandelionO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = DandelionO.DevDandelionO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.DandelionO.OriginalDandelionO(epoch=10000, pop_size=100, **kwargs)[source]
Bases:
OptimizerThe original version: Dandelion Optimizer (DandelionO)
epoch (int): Maximum number of iterations, default = 10000
pop_size (int): Population size, default = 100
Warning
This version is implemented exactly as described in the paper and the author’s original MATLAB code.
However, in the MATLAB code, the author omitted the 0.01 multiplier in the Levy function, despite it being explicitly mentioned in the paper.
Links
References
Zhao, S., Zhang, T., Ma, S., & Chen, M. (2022). Dandelion Optimizer: A nature-inspired metaheuristic algorithm for engineering applications. Engineering Applications of Artificial Intelligence, 114, 105075.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, DandelionO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = DandelionO.OriginalDandelionO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.EEFO module
- class mealpy.swarm_based.EEFO.OriginalEEFO(epoch=10000, pop_size=100, **kwargs)[source]
Bases:
OptimizerThe original version of: Electric Eel Foraging Optimization (EEFO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Links
References
Zhao, W., Wang, L., Zhang, Z., Fan, H., Zhang, J., Mirjalili, S., Khodadadi, N. and Cao, Q., 2024. Electric eel foraging optimization: A new bio-inspired optimizer for engineering applications. Expert systems with applications, 238, p.122200.
Examples
>>> import numpy as np >>> from mealpy import FloatVar >>> from mealpy.swarm_based import EEFO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=[-100.] * 30, ub=[100.] * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = EEFO.OriginalEEFO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}")
- amend_solution(solution: ndarray) ndarray[source]
Amends the solution by replacing any out-of-bound dimension with a random uniform value between its lower and upper bounds.
- Parameters
solution – The position array to check and amend.
- Returns
The valid solution with out-of-bound dimensions randomized.
mealpy.swarm_based.EHO module
- class mealpy.swarm_based.EHO.OriginalEHO(epoch: int = 10000, pop_size: int = 100, alpha: float = 0.5, beta: float = 0.5, n_clans: int = 5, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Elephant Herding Optimization (EHO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
alpha (float) – A factor that determines the influence of the best in each clan, in range [0.3, 0.8]. Default is 0.5.
beta (float) – A factor that determines the influence of the x_center, in range [0.3, 0.8]. Default is 0.5.
n_clans (int) – The number of clans, in range [3, 10]. Default is 5.
References
Wang, G.G., Deb, S. and Coelho, L.D.S., 2015, December. Elephant herding optimization. In 2015 3rd international symposium on computational and business intelligence (ISCBI) (pp. 1-5). IEEE. https://doi.org/10.1109/ISCBI.2015.8
Examples
>>> import numpy as np >>> from mealpy import FloatVar, EHO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = EHO.OriginalEHO(epoch=1000, pop_size=50, alpha = 0.5, beta = 0.5, n_clans = 5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.EPC module
- class mealpy.swarm_based.EPC.DevEPC(epoch=10000, pop_size=100, heat_damping_factor: float = 0.95, mutation_factor: float = 0.5, spiral_a: float = 1.0, spiral_b: float = 0.5, **kwargs)[source]
Bases:
OptimizerOur developed version of: Emperor Penguins Colony (EPC)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
heat_damping_factor (float) – Damping factor for heat radiation, in range [0.0, 1.0]. Default is 0.95.
mutation_factor (float) – Mutation factor for random movement, in range [0.0, 1.0]. Default is 0.5.
spiral_a (float) – Constant for logarithmic spiral movement, in range [0.0, 100.0]. Default is 1.0.
spiral_b (float) – Constant for logarithmic spiral movement, in range [0.0, 100.0]. Default is 0.5.
Error
This algorithm is almost like a trash algorithm. Some comments are as follows:
The pseudocode is incorrect and incomplete. It updates coefficients either increasing or decreasing, but the paper does not clearly provide any formulas describing how these increases or decreases are calculated.
Most of the formulas are wrong and meaningless, with no clear explanation of what the symbols represent. In particular, formulas 12 to 18 are problematic. There is no connection between the position update process in the algorithm and the parameters.
This algorithm can only be applied to 2-dimensional problems and cannot be extended to problems with more than 2 dimensions. The entire experimental section of the paper is also limited to 2-dimensional functions.
In the code, I simplified the position update process for penguins and modified the algorithm to work on n-dimensional problems. The parameter update rules were also devised by me. Therefore, I named it DevEPC.
References
Harifi, S., Khalilian, M., Mohammadzadeh, J. and Ebrahimnejad, S., 2019. Emperor Penguins Colony: a new metaheuristic algorithm for optimization. Evolutionary intelligence, 12(2), pp.211-226. https://doi.org/10.1007/s12065-019-00212-x
Examples
>>> import numpy as np >>> from mealpy import FloatVar, EPC >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> 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) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- calculate_attractiveness(heat_radiation: float, distance: float) float[source]
Calculate attractiveness between two penguins based on heat radiation and distance
- heat_radiationfloat
Heat radiation of the source penguin
- distancefloat
Distance between penguins
float : Attractiveness value
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- spiral_movement(penguin_i: ndarray, penguin_j: ndarray, attractiveness: float) ndarray[source]
Calculate spiral-like movement from penguin i towards penguin j
- penguin_inp.ndarray
Position of penguin i (moving penguin)
- penguin_jnp.ndarray
Position of penguin j (target penguin)
- attractivenessfloat
Attractiveness value between penguins
np.ndarray : New position after spiral movement
mealpy.swarm_based.ESOA module
- class mealpy.swarm_based.ESOA.OriginalESOA(epoch=10000, pop_size=100, **kwargs)[source]
Bases:
OptimizerThe original version of: Egret Swarm Optimization Algorithm (ESOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Links
References
Chen, Z., Francis, A., Li, S., Liao, B., Xiao, D., Ha, T. T., … & Cao, X. (2022). Egret Swarm Optimization Algorithm: An Evolutionary Computation Approach for Model Free Optimization. Biomimetics, 7(4), 144.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ESOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = ESOA.OriginalESOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- generate_agent(solution: Optional[ndarray] = None) Agent[source]
ID_WEI = 2 ID_LOC_X = 3 ID_LOC_Y = 4 ID_G = 5 ID_M = 6 ID_V = 7
mealpy.swarm_based.FA module
- class mealpy.swarm_based.FA.OriginalFA(epoch: int = 10000, pop_size: int = 100, max_sparks: int = 100, p_a: float = 0.04, p_b: float = 0.8, max_ea: int = 40, m_sparks: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Fireworks Algorithm (FA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
max_sparks (int) – Parameter controlling the total number of sparks generated by the pop_size fireworks, in range [2, 10000]. Default is 100.
p_a (float) – Percent (const parameter), in range (0.0, 1.0). Default is 0.04.
p_b (float) – Percent (const parameter), in range (0.0, 1.0). Default is 0.8.
max_ea (int) – Maximum explosion amplitude, in range [2, 100]. Default is 40.
m_sparks (int) – Number of sparks generated in each explosion generation, in range [2, 10000]. Default is 100.
References
Tan, Y. and Zhu, Y., 2010, June. Fireworks algorithm for optimization. In International conference in swarm intelligence (pp. 355-364). Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-13495-1_44
Examples
>>> import numpy as np >>> from mealpy import FloatVar, FA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = FA.OriginalFA(epoch=1000, pop_size=50, max_sparks = 50, p_a = 0.04, p_b = 0.8, max_ea = 40, m_sparks = 50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.FDO module
- class mealpy.swarm_based.FDO.OriginalFDO(epoch: int = 10000, pop_size: int = 100, weight_factor=0.1, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Fitness Dependent Optimizer (FDO)
Warning
Inspired by the bee swarming reproductive process, this algorithm optimizes solutions based on their fitness values by relying primarily on Lévy flight techniques. Owing to random number generation following the Lévy distribution, the algorithm demonstrates strong convergence capabilities.
However, a major drawback lies in its fitness weight design, where an update is virtually impossible when the fitness weight equals 1
References
- [1] Abdullah, J. M., & Ahmed, T. (2019). Fitness dependent optimizer: inspired by the bee
swarming reproductive process. IEEe Access, 7, 43473-43486. https://doi.org/10.1109/ACCESS.2019.2907012
Examples
>>> import numpy as np >>> from mealpy import FloatVar, FDO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = FDO.OriginalFDO(epoch=1000, pop_size=50, weight_factor=0.1) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- get_fit_weight(best_fit, current_fit, weight_factor=0.1)[source]
Calculate the fitness weight based on the best and current fitness values.
- Parameters
best_fit (float) – The best fitness value found so far.
current_fit (float) – The current fitness value of the agent.
weight_factor (float) – A factor to adjust the weight calculation, default is 0.1.
- Returns
The fitness weight.
- Return type
float
mealpy.swarm_based.FFA module
- class mealpy.swarm_based.FFA.MLFA_GD(epoch=10000, pop_size=100, m_females: int = 3, beta0: float = 1.0, gama: float = 1.0, alpha: float = 0.2, k_rw: int = 10, **kwargs)[source]
Bases:
OptimizerThe original version of: Multiple Learning FA based on Gender Difference (MLFA-GD)
epoch (int): Maximum number of iterations, default = 10000
pop_size (int): Population size, default = 100
m_females (int): Number of female fireflies selected by each male firefly, default = 3
beta0 (float): Base attractiveness at r=0., default=1.0
gama (float): Light absorption coefficient, default=1.0
alpha (float): Step size factor for randomization, default=0.2
k_rw (float): Number of chaotic random walks for the global best individual, default=10.
Warning
This algorithm suffers from severe numerical instabilities:
Distance Underflow (Eq. 3 & 12): The attractiveness term exp(-gama * r^2) evaluates to exactly 0.0 in large search bounds. Without distance normalization, attraction drops to zero, and the swarm paralyzes.
Cauchy Mutation Explosion (Eq. 13): The female update utilizes an unscaled Cauchy distribution. Due to its heavy tails, it frequently generates massive values, throwing fireflies out of the search space boundaries.
Formula Inconsistency (Eq. 8): The male update omits the random perturbation noise inherently needed in FA, risking premature stagnation in local optima.
References
Zhang, Wenning, Chongyang Jiao, and Qinglei Zhou. “Firefly algorithm with multiple learning ability based on gender difference.” Scientific Reports 15.1 (2025): 28400. https://doi.org/10.1038/s41598-025-09523-9
Examples
>>> import numpy as np >>> from mealpy import FloatVar, FFA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = FFA.MLFA_GD(epoch=1000, pop_size=50, m_females=3, beta0=1.0, gama=1.0, alpha=0.2, k_rw=10) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.FFA.OriginalFFA(epoch: int = 10000, pop_size: int = 100, gamma: float = 0.001, beta_base: float = 2, alpha: float = 0.2, alpha_damp: float = 0.99, delta: float = 0.05, exponent: int = 2, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Firefly Algorithm (FFA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
gamma (float) – Light Absorption Coefficient, in range (0.0, 1.0). Default is 0.001.
beta_base (float) – Attraction Coefficient Base Value, in range (0.0, 3.0). Default is 2.0.
alpha (float) – Mutation Coefficient, in range (0.0, 1.0). Default is 0.2.
alpha_damp (float) – Mutation Coefficient Damp Rate, in range (0.0, 1.0). Default is 0.99.
delta (float) – Mutation Step Size, in range (0.0, 1.0). Default is 0.05.
exponent (int) – Exponent (m in the paper), in range [2, 4]. Default is 2.
References
Yang, Xin-She. “Firefly algorithms for multimodal optimization.” International symposium on stochastic algorithms. Berlin, Heidelberg: Springer Berlin Heidelberg, 2009. https://doi.org/10.1007/978-3-642-04944-6_14
Examples
>>> import numpy as np >>> from mealpy import FloatVar, FFA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = FFA.OriginalFFA(epoch=1000, pop_size=50, gamma = 0.001, beta_base = 2, alpha = 0.2, alpha_damp = 0.99, delta = 0.05, exponent = 2) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.FFO module
- class mealpy.swarm_based.FFO.OriginalFFO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Fennec Fox Optimization (FFO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
gamma (float) – Light Absorption Coefficient, in range (0.0, 1.0). Default is 0.001.
beta_base (float) – Attraction Coefficient Base Value, in range (0.0, 3.0). Default is 2.0.
alpha (float) – Mutation Coefficient, in range (0.0, 1.0). Default is 0.2.
alpha_damp (float) – Mutation Coefficient Damp Rate, in range (0.0, 1.0). Default is 0.99.
delta (float) – Mutation Step Size, in range (0.0, 1.0). Default is 0.05.
exponent (int) – Exponent (m in the paper), in range [2, 4]. Default is 2.
Error
This is somewhat concerning, as there appears to be a high degree of similarity between the source code for this algorithm and the Pelican Optimization Algorithm (POA).
Algorithm design is similar to Zebra Optimization Algorithm (ZOA), Osprey Optimization Algorithm (OOA), Coati Optimization Algorithm (CoatiOA), Siberian Tiger Optimization (STO), Language Education Optimization (LEO), Serval Optimization Algorithm (SOA), Walrus Optimization Algorithm (WOA), Pelican Optimization Algorithm (POA), Three-periods optimization algorithm (TPOA), Teamwork optimization algorithm (TOA), Northern goshawk optimization (NGO), Tasmanian devil optimization (TDO), Archery algorithm (AA), Cat and mouse based optimizer (CMBO)
It may be useful to compare the Matlab code of this algorithm with those of the similar algorithms to ensure its accuracy and completeness.
The article may share some similarities with previous work by the same authors, further investigation may be warranted to verify the benchmark results reported in the papers and ensure their reliability and accuracy.
References
Trojovská, E., Dehghani, M., & Trojovský, P. (2022). Fennec Fox Optimization: A New Nature-Inspired Optimization Algorithm. IEEE Access, 10, 84417-84443. https://doi.org/10.1109/ACCESS.2022.3197745
Examples
>>> import numpy as np >>> from mealpy import FloatVar, FFO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = FFO.OriginalFFO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.FHO module
- class mealpy.swarm_based.FHO.OriginalFHO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Fire Hawk Optimization (FHO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Note
There are discrepancies between the author’s MATLAB code and the paper.
This Python version strictly follows what is written in the paper.
Links
References
Azizi, M., Talatahari, S., & Gandomi, A. H. (2022). Fire Hawk Optimizer: a novel metaheuristic algorithm. Artificial Intelligence Review, 1-77.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, FHO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = FHO.OriginalFHO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}")
mealpy.swarm_based.FOA module
- class mealpy.swarm_based.FOA.DevFOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OriginalFOAOur developed version: Fruit-fly Optimization Algorithm (FOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, FOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = FOA.DevFOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.FOA.OriginalFOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Fruit-fly Optimization Algorithm (FOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Pan, W.T., 2012. A new fruit fly optimization algorithm: taking the financial distress model as an example. Knowledge-Based Systems, 26, pp.69-74. https://doi.org/10.1016/j.knosys.2011.07.001
Examples
>>> import numpy as np >>> from mealpy import FloatVar, FOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = FOA.OriginalFOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- class mealpy.swarm_based.FOA.WhaleFOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OriginalFOAThe original version of: Whale Fruit-fly Optimization Algorithm (WFOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Fan, Y., Wang, P., Heidari, A.A., Wang, M., Zhao, X., Chen, H. and Li, C., 2020. Boosted hunting-based fruit fly optimization and advances in real-world problems. Expert Systems with Applications, 159, p.113502. https://doi.org/10.1016/j.eswa.2020.113502
Examples
>>> import numpy as np >>> from mealpy import FloatVar, FOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = FOA.WhaleFOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.FOX module
- class mealpy.swarm_based.FOX.DevFOX(epoch: int = 10000, pop_size: int = 100, c1: float = 0.18, c2: float = 0.82, pp=0.5, **kwargs: object)[source]
Bases:
OptimizerOur developed version of: Fox Optimizer (FOX)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
c1 (float) – The coefficient of jumping (c1 in the paper). Default is 0.18.
c2 (float) – The coefficient of jumping (c2 in the paper). Default is 0.82.
pp (float) – The probability of choosing the exploration and exploitation phase. Default is 0.5.
Note
Set parameter pp = 0.18 if you want to same as Original version
The different between Dev and Original version is the equation: self.g_best.solution + self.generator.standard_normal(self.problem.n_dims) * (self.mint * aa)
Examples
>>> import numpy as np >>> from mealpy import FloatVar, FOX >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = FOX.DevFOX(epoch=1000, pop_size=50, c1=0.18, c2=0.82, pp=0.5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.FOX.OriginalFOX(epoch: int = 10000, pop_size: int = 100, c1: float = 0.18, c2: float = 0.82, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Fox Optimizer (FOX)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
c1 (float) – The coefficient of jumping (c1 in the paper). Default is 0.18.
c2 (float) – The coefficient of jumping (c2 in the paper). Default is 0.82.
Note
The equation used to calculate the distance_S_travel value in the Matlab code seems to be lacking in meaning.
The if-else conditions used with p > 0.18 seem to lack a clear justification. The authors seem to have simply chosen the best value based on their experiments without explaining the rationale behind it.
Links
References
Mohammed, H., & Rashid, T. (2023). FOX: a FOX-inspired optimization algorithm. Applied Intelligence, 53(1), 1030-1050.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, FOX >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = FOX.OriginalFOX(epoch=1000, pop_size=50, c1=0.18, c2=0.82) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.GJA module
- class mealpy.swarm_based.GJA.OriginalGJA(epoch: int = 10000, pop_size: int = 100, beta_start: float = 1.2, beta_end: float = 0.3, alpha_ratio: float = 0.6, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Gekko Japonicus Algorithm (GJA)
- Parameters
epoch (int) – Maximum number of iterations. Default is 10000.
pop_size (int) – Population size (number of trees). Default is 100.
beta_start (float) – Starting value for the beta parameter, in range [1.0, 1.5]. Default is 1.2.
beta_end (float) – Ending value for the beta parameter, in range [0.1, 0.5]. Default is 0.3.
alpha_ratio (float) – Ratio to calculate alpha from beta, in range [0.4, 0.8]. Default is 0.6.
Note
- The algorithm draws inspiration from the predation strategies and survival behaviors
of the Gekko japonicus (Japanese gecko). It simulates various biological behaviors including:
Hybrid locomotion patterns (Levy flight + Gaussian perturbation)
Directional olfactory guidance
Implicit group advantage tendencies
Tail autotomy mechanism for escaping local optima
Historical memory injection for maintaining diversity
Links
References
Zhang, K., Zhao, H., Li, X., Fu, C. and Jin, J., 2025. Gekko Japonicus Algorithm: A Novel Nature-inspired Algorithm for Engineering Problems and Path Planning. Journal of Bionic Engineering.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GJA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-100.,) * 30, ub=(100.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GJA.OriginalGJA(epoch=1000, pop_size=30) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.GJO module
- class mealpy.swarm_based.GJO.OriginalGJO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Golden jackal optimization (GJO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Links
https://www.sciencedirect.com/science/article/abs/pii/S095741742200358X
https://www.mathworks.com/matlabcentral/fileexchange/108889-golden-jackal-optimization-algorithm
References
Chopra, N., & Ansari, M. M. (2022). Golden jackal optimization: A novel nature-inspired optimizer for engineering applications. Expert Systems with Applications, 198, 116924.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GJO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GJO.OriginalGJO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.GOA module
- class mealpy.swarm_based.GOA.OriginalGOA(epoch: int = 10000, pop_size: int = 100, c_min: float = 4e-05, c_max: float = 2.0, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Grasshopper Optimization Algorithm (GOA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
c_min (float) – Coefficient c min, in range [0.00001, 0.2]. Default is 0.00004.
c_max (float) – Coefficient c max, in range [0.2, 5.0]. Default is 2.0.
Links
References
Saremi, S., Mirjalili, S. and Lewis, A., 2017. Grasshopper optimisation algorithm: theory and application. Advances in Engineering Software, 105, pp.30-47.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GOA.OriginalGOA(epoch=1000, pop_size=50, c_min = 0.00004, c_max = 1.0) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.GTO module
- class mealpy.swarm_based.GTO.Matlab101GTO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe conversion of Matlab code (version 1.0.1 - 29/11/2022) to Python code of: Giant Trevally Optimizer (GTO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Attention
This algorithm costs a huge amount of computational resources in each epoch. Therefore, be careful when using the maximum number of generations as a stopping condition.
Other algorithms update around K*pop_size times in each epoch, this algorithm updates around 2*pop_size^2 + pop_size times
This version is used by the authors to compared with other algorithms in their paper.
Links
References
Sadeeq, H. T., & Abdulazeez, A. M. (2022). Giant Trevally Optimizer (GTO): A Novel Metaheuristic Algorithm for Global Optimization and Challenging Engineering Problems. IEEE Access, 10, 121615-121640.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GTO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GTO.Matlab101GTO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.GTO.Matlab102GTO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe conversion of Matlab code (version 1.0.2 - 27/04/2023) to Python code of: Giant Trevally Optimizer (GTO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Attention
The author sent me an email asking to update the algorithm. In this version, they removed 2 for loops in the epoch (generations) based on my comments on their Matlab code is wrong, so the computation time will reduce to 3*pop_size from 2*pop_size^2 + pop_size. However, this will also lead to a reduction in performance results. My question: Are the results in the paper valid?
I have decided to implement the original version of the algorithm exactly as described in the paper (OriginalGTO).
Links
References
Sadeeq, H. T., & Abdulazeez, A. M. (2022). Giant Trevally Optimizer (GTO): A Novel Metaheuristic Algorithm for Global Optimization and Challenging Engineering Problems. IEEE Access, 10, 121615-121640.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GTO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GTO.Matlab102GTO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.GTO.OriginalGTO(epoch: int = 10000, pop_size: int = 100, A: float = 0.4, H: float = 2.0, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Giant Trevally Optimizer (GTO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
A (float) – A position-change-controlling parameter (recommended range from 0.3 to 0.4), in range [-10.0, 10.0]. Default is 0.4.
H (float) – Initial value for specifies the jumping slope function, in range [1.0, 10.0]. Default is 2.0.
Note
There is a minor difference between Matlab code and the paper. So, this version is implemented exactly as described in the paper.
https://www.mathworks.com/matlabcentral/fileexchange/121358-giant-trevally-optimizer-gto
References
Sadeeq, H. T., & Abdulazeez, A. M. (2022). Giant Trevally Optimizer (GTO): A Novel Metaheuristic Algorithm for Global Optimization and Challenging Engineering Problems. IEEE Access, 10, 121615-121640.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GTO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GTO.OriginalGTO(epoch=1000, pop_size=50, A=0.4, H=2.0) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.GWO module
- class mealpy.swarm_based.GWO.CG_GWO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Cauchy‑Gaussian mutation and improved search strategy GWO (CG‑GWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Caution
This algorithm can’t be parallelized because of the ‘single’ update mode.
Meaning that the updating of the pack is based on order and sequence of the wolves.
References
Li, K., Li, S., Huang, Z. et al. Grey Wolf Optimization algorithm based on Cauchy-Gaussian mutation and improved search strategy. Sci Rep 12, 18961 (2022). https://doi.org/10.1038/s41598-022-23713-9
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.CG_GWO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.GWO.ChaoticGWO(epoch: int = 10000, pop_size: int = 100, chaotic_name: str = 'chebyshev', initial_chaotic_value: float = 0.7, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Chaotic-based Grey Wolf Optimizer (Chaotic-GWO or C-GWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
chaotic_name (str) – Name of the chaotic map to use (e.g., ‘bernoulli’, ‘logistic’, ‘chebyshev’, ‘circle’, ‘cubic’, ‘icmic’, ‘piecewise’, ‘singer’, ‘sinusoidal’, ‘tent’). Default is ‘chebyshev’.
initial_chaotic_value (float) – Initial value for the chaotic map, in range [0.0, 1.0]. Default is 0.7.
References
Kohli, M., & Arora, S. (2018). Chaotic grey wolf optimization algorithm for constrained optimization problems. Journal of computational design and engineering, 5(4), 458-472. https://doi.org/10.1016/j.jcde.2017.02.005
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.ChaoticGWO(epoch=1000, pop_size=50, chaotic_name="chebyshev", initial_chaotic_value=0.7) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- CHAOTIC_MAPS = {'bernoulli': <function ChaoticMap.bernoulli_map>, 'chebyshev': <function ChaoticMap.chebyshev_map>, 'circle': <function ChaoticMap.circle_map>, 'cubic': <function ChaoticMap.cubic_map>, 'icmic': <function ChaoticMap.icmic_map>, 'logistic': <function ChaoticMap.logistic_map>, 'piecewise': <function ChaoticMap.piecewise_map>, 'singer': <function ChaoticMap.singer_map>, 'sinusoidal': <function ChaoticMap.sinusoidal_map>, 'tent': <function ChaoticMap.tent_map>}
- class mealpy.swarm_based.GWO.DS_GWO(epoch: int = 10000, pop_size: int = 100, explore_ratio: float = 0.4, n_groups: int = 5, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Diversity enhanced Strategy based Grey Wolf Optimizer (DS-GWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
explore_ratio (float) – Ratio to control exploration, in range [0.0, 1.0]. Default is 0.4.
n_groups (int) – Number of groups for group-stage competition, in range [5, 100]. Default is 5.
Note
- This implementation includes:
Group-stage competition mechanism
Exploration-exploitation balance mechanism
References
Jiang, Jianhua, Ziying Zhao, Yutong Liu, Weihua Li, and Huan Wang. “DSGWO: An improved grey wolf optimizer with diversity enhanced strategy based on group-stage competition and balance mechanisms.” Knowledge-Based Systems 250 (2022): 109100. https://doi.org/10.1016/j.knosys.2022.109100
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.DS_GWO(epoch=1000, pop_size=50, explore_ratio=0.4, n_groups=5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- get_coefficients(a: float) tuple[source]
Generate coefficients A and C for position update equations.
- Parameters
a (float) – Coefficient that decreases over epochs
- Returns
Coefficients A, C
- Return type
tuple
- class mealpy.swarm_based.GWO.ER_GWO(epoch: int = 10000, pop_size: int = 100, a_initial: float = 2.0, a_final: float = 0.0, miu_factor: float = 1.0001, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Efficient and Robust Grey Wolf Optimizer (ER-GWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
a_initial (float) – Initial value of coefficient a, in range [0.0, 10.0]. Default is 2.0.
a_final (float) – Final value of coefficient a, in range [0.0, a_initial]. Default is 0.0.
miu_factor (float) – Nonlinear coefficient for equation (8), in range [1.0001, 1.01]. Default is 1.0001.
Caution
Slow convergence speed due to the (miu_factor)^(iteration) ==> Big number
Three more parameters than original GWO, increase the complexity of the algorithm.
References
Long, W., Cai, S., Jiao, J. et al. An efficient and robust grey wolf optimizer algorithm for large-scale numerical optimization. Soft Comput 24, 997–1026 (2020). https://doi.org/10.1007/s00500-019-03939-y
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.ER_GWO(epoch=1000, pop_size=50, a_initial=2.0, a_final=0.0, miu_factor=1.0001) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.GWO.ExGWO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Expanded Grey Wolf Optimizer (Ex-GWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Note
When calling the solve() function, you need to set the mode to “swarm” to use this algorithm as original version.
They update the position of whole population before calculating the fitness of each agent.
References
Seyyedabbasi, A., & Kiani, F. (2021). I-GWO and Ex-GWO: improved algorithms of the Grey Wolf Optimizer to solve global optimization problems. Engineering with Computers, 37(1), 509-532. https://doi.org/10.1007/s00366-019-00837-7
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.ExGWO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.GWO.FuzzyGWO(epoch: int = 10000, pop_size: int = 100, fuzzy_name: str = 'increase', **kwargs: object)[source]
Bases:
OptimizerThe original version of: Fuzzy Hierarchical Operator - Grey Wolf Optimizer (FHO-GWO or FuzzyGWO or F-GWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
fuzzy_name (str) – Type of fuzzy operator to use (e.g., ‘increase’, ‘decrease’). Default is ‘increase’.
References
Rodríguez, Luis, Oscar Castillo, José Soria, Patricia Melin, Fevrier Valdez, Claudia I. Gonzalez, Gabriela E. Martinez, and Jesus Soto. “A fuzzy hierarchical operator in the grey wolf optimizer algorithm.” Applied Soft Computing 57 (2017): 315-328. https://doi.org/10.1016/j.asoc.2017.03.048
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.FuzzyGWO(epoch=1000, pop_size=50, fuzzy_name="increase") >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- FUZZY_OPERATORS = ['increase', 'decrease']
- class mealpy.swarm_based.GWO.GWO_WOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OriginalGWOThe original version of: Hybrid Grey Wolf - Whale Optimization Algorithm (GWO-WOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Obadina, O. O., Thaha, M. A., Althoefer, K., & Shaheed, M. H. (2022). Dynamic characterization of a master–slave robotic manipulator using a hybrid grey wolf–whale optimization algorithm. Journal of Vibration and Control, 28(15-16), 1992-2003. https://doi.org/10.1177/10775463211003402
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.GWO_WOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.GWO.IGWO(epoch: int = 10000, pop_size: int = 100, a_min: float = 0.02, a_max: float = 2.2, **kwargs: object)[source]
Bases:
OriginalGWOThe original version of: Improved Grey Wolf Optimization (IGWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
a_min (float) – Lower bound of a, in range (0.0, 1.6). Default is 0.02.
a_max (float) – Upper bound of a, in range [1.0, 4.0]. Default is 2.2.
References
Kaveh, A., & Zakian, P. (2018). Improved GWO algorithm for optimal design of truss structures. Engineering with Computers, 34(4), 685-707. https://doi.org/10.1007/s00366-017-0567-1
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.IGWO(epoch=1000, pop_size=50, a_min = 0.02, a_max = 2.2) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.GWO.IOBL_GWO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Improved Opposite-based Learning Grey Wolf Optimizer (IOBL-GWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Note
In the paper, they called it “Improved Grey Wolf Optimizer (IGWO)”, but there are many improved versions of GWO.
So based on their proposed equations, we called it as “Improved Opposite-based Learning Grey Wolf Optimizer (IOBL-GWO)”.
This algorithm is heavily (4x - 6X slower than original) because of multiple times of calculating the fitness of agent in each population.
References
Bansal, J. C., & Singh, S. (2021). A better exploration strategy in Grey Wolf Optimizer. Journal of Ambient Intelligence and Humanized Computing, 12(1), 1099-1118. https://doi.org/10.1007/s12652-020-02153-1
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.IOBL_GWO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.GWO.IncrementalGWO(epoch: int = 10000, pop_size: int = 100, explore_factor: float = 1.5, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Incremental model-based Grey Wolf Optimizer (IncrementalGWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
explore_factor (float) – Factor to control exploration, in range [0.0, 5.0]. Default is 1.5.
Note
When calling the solve() function, you need to set the mode to “swarm” to use this algorithm as original version.
They update the position of whole population before calculating the fitness of each agent.
References
Seyyedabbasi, A., & Kiani, F. (2021). I-GWO and Ex-GWO: improved algorithms of the Grey Wolf Optimizer to solve global optimization problems. Engineering with Computers, 37(1), 509-532. https://doi.org/10.1007/s00366-019-00837-7
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.IncrementalGWO(epoch=1000, pop_size=50, explore_factor=1.5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.GWO.OGWO(epoch: int = 10000, pop_size: int = 100, miu_factor: float = 2.0, jumping_rate: float = 0.05, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Opposition-based learning Grey Wolf Optimizer (OGWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
miu_factor (float) – Nonlinear coefficient for equation (11), in range [0.0, 10.0]. Default is 2.0.
jumping_rate (float) – Jumping rate for OBL (Opposition-Based Learning), in range [0.0, 1.0]. Default is 0.05.
References
Yu, X., Xu, W., & Li, C. (2021). Opposition-based learning grey wolf optimizer for global optimization. Knowledge-Based Systems, 226, 107139. https://doi.org/10.1016/j.knosys.2021.107139
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.OGWO(epoch=1000, pop_size=50, miu_factor=2.0, jumping_rate=0.05) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.GWO.OriginalGWO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Grey Wolf Optimizer (GWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Links
References
Mirjalili, S., Mirjalili, S.M. and Lewis, A., 2014. Grey wolf optimizer. Advances in engineering software, 69, pp.46-61.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.OriginalGWO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.GWO.RW_GWO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Random Walk Grey Wolf Optimizer (RW-GWO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Gupta, S. and Deep, K., 2019. A novel random walk grey wolf optimizer. Swarm and evolutionary computation, 44, pp.101-112. https://doi.org/10.1016/j.swevo.2018.01.001
Examples
>>> import numpy as np >>> from mealpy import FloatVar, GWO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = GWO.RW_GWO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.HBA module
- class mealpy.swarm_based.HBA.OriginalHBA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Honey Badger Algorithm (HBA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Links
References
Hashim, F. A., Houssein, E. H., Hussain, K., Mabrouk, M. S., & Al-Atabany, W. (2022). Honey Badger Algorithm: New metaheuristic algorithm for solving optimization problems. Mathematics and Computers in Simulation, 192, 84-110.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, HBA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = HBA.OriginalHBA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.HGS module
- class mealpy.swarm_based.HGS.OriginalHGS(epoch: int = 10000, pop_size: int = 100, PUP: float = 0.08, LH: float = 10000, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Hunger Games Search (HGS)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
PUP (float) – The probability of updating position (L in the paper), in range (0, 1.0). Default is 0.08.
LH (float) – Largest hunger / threshold, in range [1, 20000]. Default is 10000.
References
Yang, Y., Chen, H., Heidari, A.A. and Gandomi, A.H., 2021. Hunger games search: Visions, conception, implementation, deep analysis, perspectives, and towards performance shifts. Expert Systems with Applications, 177, p.114864. https://doi.org/10.1016/j.eswa.2021.114864
Examples
>>> import numpy as np >>> from mealpy import FloatVar, HGS >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = HGS.OriginalHGS(epoch=1000, pop_size=50, PUP = 0.08, LH = 10000) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
mealpy.swarm_based.HHO module
- class mealpy.swarm_based.HHO.OriginalHHO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Harris Hawks Optimization (HHO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Heidari, A.A., Mirjalili, S., Faris, H., Aljarah, I., Mafarja, M. and Chen, H., 2019. Harris hawks optimization: Algorithm and applications. Future generation computer systems, 97, pp.849-872. https://doi.org/10.1016/j.future.2019.02.028
Examples
>>> import numpy as np >>> from mealpy import FloatVar, HHO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = HHO.OriginalHHO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.JA module
- class mealpy.swarm_based.JA.DevJA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerOur developed version: Jaya Algorithm (JA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Rao, R., 2016. Jaya: A simple and new optimization algorithm for solving constrained and unconstrained optimization problems. International Journal of Industrial Engineering Computations, 7(1), pp.19-34.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, JA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = JA.DevJA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.JA.LevyJA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
DevJAThe original version of: Levy-flight Jaya Algorithm (LJA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Note
All third loops in this version also are removed
The beta value of Levy-flight equal to 1.8 as the best value in the paper.
References
Iacca, G., dos Santos Junior, V.C. and de Melo, V.V., 2021. An improved Jaya optimization algorithm with Lévy flight. Expert Systems with Applications, 165, p.113902. https://doi.org/10.1016/j.eswa.2020.113902
Examples
>>> import numpy as np >>> from mealpy import FloatVar, JA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = JA.LevyJA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.JA.OriginalJA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
DevJAThe original version of: Jaya Algorithm (JA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Rao, R., 2016. Jaya: A simple and new optimization algorithm for solving constrained and unconstrained optimization problems. International Journal of Industrial Engineering Computations, 7(1), pp.19-34. https://www.growingscience.com/ijiec/Vol7/IJIEC_2015_32.pdf
Examples
>>> import numpy as np >>> from mealpy import FloatVar, JA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = JA.OriginalJA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.MFO module
- class mealpy.swarm_based.MFO.OriginalMFO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version: Moth-Flame Optimization (MFO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Mirjalili, S., 2015. Moth-flame optimization algorithm: A novel nature-inspired heuristic paradigm. Knowledge-based systems, 89, pp.228-249. https://doi.org/10.1016/j.knosys.2015.07.006
Examples
>>> import numpy as np >>> from mealpy import FloatVar, MFO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = MFO.OriginalMFO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.MGO module
- class mealpy.swarm_based.MGO.OriginalMGO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Mountain Gazelle Optimizer (MGO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Links
https://www.sciencedirect.com/science/article/abs/pii/S0965997822001831
https://www.mathworks.com/matlabcentral/fileexchange/118680-mountain-gazelle-optimizer
References
Abdollahzadeh, B., Gharehchopogh, F. S., Khodadadi, N., & Mirjalili, S. (2022). Mountain gazelle optimizer: a new nature-inspired metaheuristic algorithm for global optimization problems. Advances in Engineering Software, 174, 103282.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, MGO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = MGO.OriginalMGO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.MPA module
- class mealpy.swarm_based.MPA.OriginalMPA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe developed version: Marine Predators Algorithm (MPA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Note
To use the original paper, set the training mode = “swarm”
They update the whole population at the same time before update the fitness
Two variables that they consider it as constants which are FADS = 0.2 and P = 0.5
Links
References
Faramarzi, A., Heidarinejad, M., Mirjalili, S., & Gandomi, A. H. (2020). Marine Predators Algorithm: A nature-inspired metaheuristic. Expert systems with applications, 152, 113377.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, MPA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = MPA.OriginalMPA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.MRFO module
- class mealpy.swarm_based.MRFO.OriginalMRFO(epoch: int = 10000, pop_size: int = 100, somersault_range: float = 2.0, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Manta Ray Foraging Optimization (MRFO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
somersault_range (float) – Somersault factor that decides the somersault range of manta rays, in range [1.0, 5.0]. Default is 2.0.
References
Zhao, W., Zhang, Z. and Wang, L., 2020. Manta ray foraging optimization: An effective bio-inspired optimizer for engineering applications. Engineering Applications of Artificial Intelligence, 87, p.103300. https://doi.org/10.1016/j.engappai.2019.103300
Examples
>>> import numpy as np >>> from mealpy import FloatVar, MRFO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = MRFO.OriginalMRFO(epoch=1000, pop_size=50, somersault_range = 2.0) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.MRFO.WMQIMRFO(epoch: int = 10000, pop_size: int = 100, somersault_range: float = 2.0, pm: float = 0.5, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Wavelet Mutation and Quadratic Interpolation MRFO (WMQIMRFO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
somersault_range (float) – Somersault factor that decides the somersault range of manta rays, in range [1.0, 5.0]. Default is 2.0.
pm (float) – Probability mutation, in range (0.0, 1.0). Default is 0.5.
References
G. Hu, M. Li, X. Wang et al., An enhanced manta ray foraging optimization algorithm for shape optimization of complex CCG-Ball curves, Knowledge-Based Systems (2022). https://doi.org/10.1016/j.knosys.2021.108071.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, MRFO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = MRFO.WMQIMRFO(epoch=1000, pop_size=50, somersault_range = 2.0, pm=0.5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.MSA module
- class mealpy.swarm_based.MSA.OriginalMSA(epoch: int = 10000, pop_size: int = 100, n_best: int = 5, partition: float = 0.5, max_step_size: float = 1.0, **kwargs: object)[source]
Bases:
OptimizerThe original version: Moth Search Algorithm (MSA)
- Parameters
epoch (int) – Maximum number of iterations. Default is 10000.
pop_size (int) – Population size. Default is 100.
n_best (int) – How many of the best moths to keep from one generation to the next, in range [3, 10]. Default is 5.
partition (float) – The proportional of first partition, in range [0.3, 0.8]. Default is 0.5.
max_step_size (float) – Max step size used in Levy-flight technique, in range [0.5, 2.0]. Default is 1.0.
Links
References
Wang, G.G., 2018. Moth search algorithm: a bio-inspired metaheuristic algorithm for global optimization problems. Memetic Computing, 10(2), pp.151-164.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, MSA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = MSA.OriginalMSA(epoch=1000, pop_size=50, n_best = 5, partition = 0.5, max_step_size = 1.0) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.MShOA module
- class mealpy.swarm_based.MShOA.DevMShOA(epoch: int = 10000, pop_size: int = 100, k_value: float = 0.3, **kwargs: object)[source]
Bases:
OptimizerOur developed version of: Mantis Shrimp Optimization Algorithm (MShOA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
k_value (float) – Upper bound for k parameter in defense/shelter phase (Strategy 3, Equation 15). k is sampled from U(0, k_value), in range (0.0, 10000.0). Default is 0.3.
Note
This version is implemented by “Gunbaz” with the help of AI-generated code.
- This implementation uses PTI-based strategy selection exactly as described in Algorithm 1 and Algorithm 2. All equations match the paper exactly:
Algorithm 1: PTI update mechanism (Eq. 5, 6, 7)
Strategy 1: Foraging equation (Eq. 12)
Strategy 2: Attack/Strike equation (Eq. 14)
Strategy 3: Defense/Burrow equation (Eq. 15)
- Each agent has a PTI (Polarization Type Indicator) value ∈ {1, 2, 3} that determines strategy:
PTI = 1: Foraging/Navigation (vertical linear polarized light detection) → Strategy 1
PTI = 2: Attack/Strike (horizontal linear polarized light detection) → Strategy 2
PTI = 3: Defense/Burrow (circular polarized light detection) → Strategy 3
Links
References
Sánchez Cortez, J.A., Peraza Vázquez, H., Peña Delgado, A.F., 2025. Mantis Shrimp Optimization Algorithm (MShOA): A Novel Bio-Inspired Optimization Algorithm Based on Mantis Shrimp Survival Tactics. Mathematics, 13(9), 1500.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, MShOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = MShOA.DevMShOA(epoch=1000, pop_size=50, k_value=0.3) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- before_main_loop()[source]
Initialize PTI vector randomly (Algorithm 1, initialization step) PTI ∈ {1, 2, 3} for each agent using PTI_i = round(1 + 2 * rand_i) This produces distribution: ~25% for 1, ~50% for 2, ~25% for 3
- evolve(epoch: int) None[source]
The main operations (equations) of algorithm. Inherit from Optimizer class Implements Algorithm 2 from the paper with PTI-based strategy selection.
Execution order (critical for correct LPA calculation): 1. Save X_i(t) (current positions before strategy application) 2. Apply strategies based on PTI to generate X’_i(t) (new positions) 3. Calculate LPA from X_i(t) and X’_i(t) (intra-iteration change) 4. Calculate RPA, LPT, RPT, LAD, RAD 5. Update PTI according to Algorithm 1
- Parameters
epoch (int) – The current iteration
- class mealpy.swarm_based.MShOA.OriginalMShOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Mantis Shrimp Optimization Algorithm (MShOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Warning
Mathematical formulas and notations in the paper are ambiguous, making direct implementation is hard.
This Python code was translated directly from the author’s MATLAB implementation.
Use this algorithm with caution due to the questionable quality of the paper.
The main point of this algorithm is changing the position of global best solution instead of current position.
Links
References
Sánchez Cortez, J.A., Peraza Vázquez, H., Peña Delgado, A.F., 2025. Mantis Shrimp Optimization Algorithm (MShOA): A Novel Bio-Inspired Optimization Algorithm Based on Mantis Shrimp Survival Tactics. Mathematics, 13(9), 1500.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, MShOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = MShOA.OriginalMShOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- amend_solution(solution: ndarray) ndarray[source]
This function is based on optimizer’s strategy. In each optimizer, this function can be overridden
- Parameters
solution – The position
- Returns
The valid solution based on optimizer’s strategy
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
mealpy.swarm_based.NGO module
- class mealpy.swarm_based.NGO.OriginalNGO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Northern Goshawk Optimization (NGO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Danger
This is somewhat concerning, as there appears to be a high degree of similarity between the source code for this algorithm and the Pelican Optimization Algorithm (POA).
Algorithm design is highly similar to Zebra Optimization Algorithm (ZOA), Osprey Optimization Algorithm (OOA), Coati Optimization Algorithm (CoatiOA), Siberian Tiger Optimization (STO), Language Education Optimization (LEO), Serval Optimization Algorithm (SOA), Walrus Optimization Algorithm (WOA), Fennec Fox Optimization (FFO), Three-periods optimization algorithm (TPOA), Teamwork optimization algorithm (TOA), Pelican Optimization Algorithm (POA), Tasmanian devil optimization (TDO), Archery algorithm (AA), Cat and mouse based optimizer (CMBO)
It may be useful to compare the Matlab code of this algorithm with those of the similar algorithms to ensure its accuracy and completeness.
The article may share some similarities with previous work by the same authors, further investigation may be warranted to verify the benchmark results reported in the papers and ensure their reliability and accuracy.
Links
References
Dehghani, M., Hubálovský, Š., & Trojovský, P. (2021). Northern goshawk optimization: a new swarm-based algorithm for solving optimization problems. IEEE Access, 9, 162059-162080.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, NGO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = NGO.OriginalNGO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.NMRA module
- class mealpy.swarm_based.NMRA.ImprovedNMRA(epoch=10000, pop_size=100, pb=0.75, pm=0.01, **kwargs)[source]
Bases:
OptimizerOur improved version of: Improved Naked Mole-Rat Algorithm (I-NMRA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
pb (float) – Breeding probability, in range (0.0, 1.0). Default is 0.75.
pm (float) – Probability of mutation, in range (0.0, 1.0). Default is 0.01.
Note
Use mutation probability idea
Use crossover operator
Use Levy-flight technique
Examples
>>> import numpy as np >>> from mealpy import FloatVar, NMRA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = NMRA.ImprovedNMRA(epoch=1000, pop_size=50, pb = 0.75, pm = 0.01) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.NMRA.OriginalNMRA(epoch: int = 10000, pop_size: int = 100, pb: float = 0.75, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Naked Mole-Rat Algorithm (NMRA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
pb (float) – Probability of breeding, in range (0.0, 1.0). Default is 0.75.
References
Salgotra, R. and Singh, U., 2019. The naked mole-rat algorithm. Neural Computing and Applications, 31(12), pp.8837-8857. https://www.doi.org10.1007/s00521-019-04464-7
Examples
>>> import numpy as np >>> from mealpy import FloatVar, NMRA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = NMRA.OriginalNMRA(epoch=1000, pop_size=50, pb = 0.75) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.NWOA module
Provides context and a disclaimer regarding the ‘Narwhal Optimization Algorithm’.
Danger
There are two distinct papers proposing algorithms under the same name. Both have been published in journals with low academic impact; therefore, the mathematical soundness and experimental results are highly questionable. Users are strongly advised to exercise extreme caution and perform rigorous validation before applying these to critical optimization tasks.
The two identified versions are:
- ‘Narwhal Optimizer: A Novel Nature-Inspired Metaheuristic Algorithm’ (May 2024)
Acronym: NO
Note: Lacks significant or novel update operators.
- ‘Narwhal Optimizer: A Nature-Inspired Optimization Algorithm for Solving Complex Optimization Problems’ (September 2025)
Acronym: NWOA
Note: Performance results reported in the paper may not be replicable or statistically valid.
Danger
Neither implementation offers a robust contribution to the metaheuristic field. It is recommended to utilize established, peer-reviewed optimization frameworks instead.
- class mealpy.swarm_based.NWOA.OriginalNO(epoch: int = 10000, pop_size: int = 100, alpha=2.0, sigma0=2.0, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Narwhal Optimization (NO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
alpha (float) – Signal intensity control factor, in range [-100.0, 100.0]. Default is 2.0.
sigma0 (float) – Initial standard deviation for signal propagation, in range [-100.0, 100.0]. Default is 2.0.
References
Medjahed, Seyyid Ahmed, and Fatima Boukhatem. “Narwhal Optimizer: A Novel Nature-Inspired Metaheuristic Algorithm”. Int. Arab J. Inf. Technol. 21.3 (2024): 418-426. https://doi.org/10.34028/iajit/21/3/6
Examples
>>> import numpy as np >>> from mealpy import FloatVar, NWOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = NWOA.OriginalNO(epoch=1000, pop_size=50, alpha=2.0, sigma0=2.0) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.NWOA.OriginalNWOA(epoch: int = 10000, pop_size: int = 100, amplitude: float = 1.0, delta_decay: float = 0.01, lamda_decay: float = 0.001, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Narwhal Optimization Algorithm (NWOA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
amplitude (float) – Wave amplitude, in range [-100.0, 100.0]. Default is 1.0.
delta_decay (float) – Decay constant, in range (0.0, 1.0). Default is 0.01.
lamda_decay (float) – Energy decay rate, in range (0.0, 1.0). Default is 0.001.
References
Masadeh, R., Almomani, O., Zaqebah, A., Masadeh, S., Alshqurat, K., Sharieh, A., & Alsharman, N. (2025). Narwhal Optimizer: A Nature-Inspired Optimization Algorithm for Solving Complex Optimization Problems. Computers, Materials & Continua, 85(2). https://doi.org/10.32604/cmc.2025.066797
Examples
>>> import numpy as np >>> from mealpy import FloatVar, NWOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = NWOA.OriginalNWOA(epoch=1000, pop_size=50, amplitude=2.0, delta_decay=0.01, lamda_decay=0.001) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- static cosine_similarity(agent_pos: ndarray, best_pos: ndarray) float[source]
Calculate cosine similarity distance (Eq. 3 from paper)
- Parameters
agent_pos – Current agent position
best_pos – Best solution position
- Returns
Cosine similarity distance
- Return type
float
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
mealpy.swarm_based.OOA module
- class mealpy.swarm_based.OOA.OriginalOOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Osprey Optimization Algorithm (OOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Caution
Algorithm design is similar to Zebra Optimization Algorithm (ZOA), Osprey Optimization Algorithm (OOA), Pelican optimization algorithm (POA), Siberian Tiger Optimization (STO), Language Education Optimization (LEO), Serval Optimization Algorithm (SOA), Walrus Optimization Algorithm (WOA), Fennec Fox Optimization (FFO), Three-periods optimization algorithm (TPOA), Teamwork optimization algorithm (TOA), Northern goshawk optimization (NGO), Tasmanian devil optimization (TDO), Archery algorithm (AA), Cat and mouse based optimizer (CMBO)
It may be useful to compare the Matlab code of this algorithm with those of the similar algorithms to ensure its accuracy and completeness.
The article may share some similarities with previous work by the same authors, further investigation may be warranted to verify the benchmark results reported in the papers and ensure their reliability and accuracy.
Links
https://www.frontiersin.org/articles/10.3389/fmech.2022.1126450/full
https://www.mathworks.com/matlabcentral/fileexchange/124555-osprey-optimization-algorithm
References
Trojovský, P., & Dehghani, M. Osprey Optimization Algorithm: A new bio-inspired metaheuristic algorithm for solving engineering optimization problems. Frontiers in Mechanical Engineering, 8, 136.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, OOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = OOA.OriginalOOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.ORCA module
- class mealpy.swarm_based.ORCA.OriginalOrcaOA(epoch: int = 10000, pop_size: int = 100, p_percent: float = 0.1, R0: float = 2.0, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Orca Optimization Algorithm (OrcaOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
p_percent (float) – The percentage of worst orcas to remove and regenerate per iteration, default = 0.1.
R0 (float) – The initial radius of the ice floe, default=2.0.
References
Golilarz, N. A., Gao, H., Addeh, A., & Pirasteh, S. (2020, December). ORCA optimization algorithm: A new meta-heuristic tool for complex optimization problems. In 2020 17th International Computer Conference on Wavelet Active Media Technology and Information Processing (ICCWAMTIP) (pp. 198-204). IEEE. https://doi.org/10.1109/ICCWAMTIP51612.2020.9317473
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ORCA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = ORCA.OriginalOrcaOA(epoch=1000, pop_size=50, p_percent=0.15, R0=5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}")
- class mealpy.swarm_based.ORCA.OriginalOrcaPA(epoch: int = 10000, pop_size: int = 100, p1: float = 0.5, p2: float = 0.1, q: float = 0.9, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Orca Predation Algorithm (OrcaPA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
p1 (float) – Probability to select driving vs encircling, in range [0.0, 1.0]. Default is 0.5.
p2 (float) – Probability for position adjustment, in range [0.0, 1.0]. Default is 0.1.
q (float) – Probability parameter for driving methods, in range [0.0, 1.0]. Default is 0.9.
Caution
1. This algorithm uses approximately 2x more Number of Function Evaluations (NFEs) than other algorithms. That is, it calls the fitness function 2.x times per epoch, where x depends on the probability parameter “p_2”. Therefore, users should be cautious when applying it to large-scale problems, as it will be very slow.
2. This algorithm borrows ideas from the Whale Optimization Algorithm (WOA) and Grey Wolf Optimization (GWO), with slight modifications to the equations. Conceptually, however, the underlying ideas remain the same.
3. This algorithm uses the same animal motif as the original Orca Optimization Algorithm, despite differences in the equations.
References
Jiang, Y., Wu, Q., Zhu, S., & Zhang, L. (2022). Orca predation algorithm: A novel bio-inspired algorithm for global optimization problems. Expert Systems with Applications, 188, 116026. https://doi.org/10.1016/j.eswa.2021.116026
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ORCA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = ORCA.OriginalOrcaPA(epoch=1000, pop_size=50, p1=0.5, p2=0.3, q=0.9) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}")
mealpy.swarm_based.OSA module
- class mealpy.swarm_based.OSA.OriginalOSA(epoch: int = 10000, pop_size: int = 100, alpha_max: float = 0.5, beta_max: float = 1.9, **kwargs: object)[source]
Bases:
OptimizerThe original version: Owl Search Algorithm (OSA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 100000]. Default is 100.
alpha_max (float) – Maximum value of alpha, in range (0.0, 10.0). Default is 0.5.
beta_max (float) – Maximum value of beta, in range (0.0, 10.0). Default is 1.9.
Warning
There are two MATLAB versions of this algorithm available. However, neither is from the original authors, and their implementations do not accurately reflect the original paper. This algorithm was published in a low-tier journal, lacks any unique update operators, and does not provide pseudocode, which explains why it hasn’t gained traction since its publication in 2018.
Links
https://www.mathworks.com/matlabcentral/fileexchange/181126-owl-search-algorithm-osa
https://www.mathworks.com/matlabcentral/fileexchange/162356-owl-search-algorithm-osa
References
Jain, M., Maurya, S., Rani, A., & Singh, V. (2018). Owl search algorithm: a novel nature-inspired heuristic paradigm for global optimization. Journal of Intelligent & Fuzzy Systems, 34(3), 1573-1582. https://doi.org/10.3233/JIFS-169452
Examples
>>> import numpy as np >>> from mealpy import FloatVar, OSA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = OSA.OriginalOSA(epoch=1000, pop_size=50, alpha_max = 0.5, beta_max = 1.9) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.PFA module
- class mealpy.swarm_based.PFA.OriginalPFA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Pathfinder Algorithm (PFA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Yapici, H. and Cetinkaya, N., 2019. A new meta-heuristic optimizer: Pathfinder algorithm. Applied soft computing, 78, pp.545-568. https://doi.org/10.1016/j.asoc.2019.03.012
Examples
>>> import numpy as np >>> from mealpy import FloatVar, PFA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = PFA.OriginalPFA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.POA module
- class mealpy.swarm_based.POA.OriginalPOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Pelican Optimization Algorithm (POA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Caution
This is somewhat concerning, as there appears to be a high degree of similarity between the source code for this algorithm and the Northern Goshawk Optimization (NGO)
Algorithm design is similar to Zebra Optimization Algorithm (ZOA), Osprey Optimization Algorithm (OOA), Coati Optimization Algorithm (CoatiOA), Siberian Tiger Optimization (STO), Language Education Optimization (LEO), Serval Optimization Algorithm (SOA), Walrus Optimization Algorithm (WOA), Fennec Fox Optimization (FFO), Three-periods optimization algorithm (TPOA), Teamwork optimization algorithm (TOA), Northern goshawk optimization (NGO), Tasmanian devil optimization (TDO), Archery algorithm (AA), Cat and mouse based optimizer (CMBO)
It may be useful to compare the Matlab code of this algorithm with those of the similar algorithms to ensure its accuracy and completeness.
The article may share some similarities with previous work by the same authors, further investigation may be warranted to verify the benchmark results reported in the papers and ensure their reliability and accuracy.
Links
References
Trojovský, P., & Dehghani, M. (2022). Pelican optimization algorithm: A novel nature-inspired algorithm for engineering applications. Sensors, 22(3), 855.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, POA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = POA.OriginalPOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.PSO module
- class mealpy.swarm_based.PSO.AIW_PSO(epoch: int = 10000, pop_size: int = 100, c1: float = 2.05, c2: float = 2.05, alpha: float = 0.4, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Adaptive Inertia Weight Particle Swarm Optimization (AIW-PSO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
c1 (float) – Local coefficient, in range (0.0, 5.0). Default is 2.05.
c2 (float) – Global coefficient, in range (0.0, 5.0). Default is 2.05.
alpha (float) – The positive constant, in range [0.0, 1.0]. Default is 0.4.
References
Qin, Z., Yu, F., Shi, Z., Wang, Y. (2006). Adaptive Inertia Weight Particle Swarm Optimization. In: Rutkowski, L., Tadeusiewicz, R., Zadeh, L.A., Żurada, J.M. (eds) Artificial Intelligence and Soft Computing – ICAISC 2006. ICAISC 2006. Lecture Notes in Computer Science(), vol 4029. S pringer, Berlin, Heidelberg. https://doi.org/10.1007/11785231_48
Examples
>>> import numpy as np >>> from mealpy import FloatVar, PSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = PSO.AIW_PSO(epoch=1000, pop_size=50, c1=2.05, c2=20.5, alpha=0.4) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- amend_solution(solution: ndarray) ndarray[source]
This function is based on optimizer’s strategy. In each optimizer, this function can be overridden
- Parameters
solution – The position
- Returns
The valid solution based on optimizer’s strategy
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- generate_agent(solution: Optional[ndarray] = None) Agent[source]
Generate new agent with full information
- Parameters
solution (np.ndarray) – The solution
- class mealpy.swarm_based.PSO.CL_PSO(epoch: int = 10000, pop_size: int = 100, c_local: float = 1.2, w_min: float = 0.4, w_max: float = 0.9, max_flag: int = 7, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Comprehensive Learning Particle Swarm Optimization (CL-PSO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
c_local (float) – Local coefficient, in range (0.0, 5.0). Default is 1.2.
w_min (float) – Weight min of bird, in range (0.0, 0.5). Default is 0.4.
w_max (float) – Weight max of bird, in range [0.5, 2.0]. Default is 0.9.
max_flag (int) – Number of times, in range [2, 100]. Default is 7.
References
Liang, J.J., Qin, A.K., Suganthan, P.N. and Baskar, S., 2006. Comprehensive learning particle swarm optimizer for global optimization of multimodal functions. IEEE transactions on evolutionary computation, 10(3), pp.281-295. https://doi.org/10.1109/TEVC.2005.857610
Examples
>>> import numpy as np >>> from mealpy import FloatVar, PSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = PSO.CL_PSO(epoch=1000, pop_size=50, c_local = 1.2, w_min=0.4, w_max=0.9, max_flag = 7) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- generate_agent(solution: Optional[ndarray] = None) Agent[source]
Generate new agent with full information
- Parameters
solution (np.ndarray) – The solution
- class mealpy.swarm_based.PSO.C_PSO(epoch: int = 10000, pop_size: int = 100, c1: float = 2.05, c2: float = 2.05, w_min: float = 0.4, w_max: float = 0.9, **kwargs: object)[source]
Bases:
P_PSOThe original version of: Chaos Particle Swarm Optimization (C-PSO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
c1 (float) – Local coefficient, in range (0.0, 5.0). Default is 2.05.
c2 (float) – Global coefficient, in range (0.0, 5.0). Default is 2.05.
w_min (float) – Weight min of bird, in range (0.0, 0.5). Default is 0.4.
w_max (float) – Weight max of bird, in range [0.5, 2.0]. Default is 0.9.
References
Liu, B., Wang, L., Jin, Y.H., Tang, F. and Huang, D.X., 2005. Improved particle swarm optimization combined with chaos. Chaos, Solitons & Fractals, 25(5), pp.1261-1271. https://doi.org/10.1016/j.chaos.2004.11.095
Examples
>>> import numpy as np >>> from mealpy import FloatVar, PSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = PSO.C_PSO(epoch=1000, pop_size=50, c1=2.05, c2=2.05, w_min=0.4, w_max=0.9) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.PSO.HPSO_TVAC(epoch=10000, pop_size=100, ci=0.5, cf=0.1, **kwargs)[source]
Bases:
P_PSOThe original version of: Hierarchical PSO Time-Varying Acceleration (HPSO-TVAC)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
ci (float) – c initial, in range [0.3, 1.0]. Default is 0.5.
cf (float) – c final, in range [0.0, 0.3]. Default is 0.1.
References
Ghasemi, M., Aghaei, J. and Hadipour, M., 2017. New self-organising hierarchical PSO with jumping time-varying acceleration coefficients. Electronics Letters, 53(20), pp.1360-1362. https://doi.org/10.1049/el.2017.2112
Examples
>>> import numpy as np >>> from mealpy import FloatVar, PSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = PSO.HPSO_TVAC(epoch=1000, pop_size=50, ci=0.5, cf=0.1) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.PSO.LDW_PSO(epoch: int = 10000, pop_size: int = 100, c1: float = 2.05, c2: float = 2.05, w_min: float = 0.4, w_max: float = 0.9, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Linearly Decreasing inertia Weight Particle Swarm Optimization (LDW-PSO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
c1 (float) – Local coefficient, in range (0.0, 5.0). Default is 2.05.
c2 (float) – Global coefficient, in range (0.0, 5.0). Default is 2.05.
w_min (float) – Weight min of bird, in range (0.0, 0.5). Default is 0.4.
w_max (float) – Weight max of bird, in range [0.5, 2.0]. Default is 0.9.
References
Shi, Yuhui, and Russell Eberhart. “A modified particle swarm optimizer.” In 1998 IEEE international conference on evolutionary computation proceedings. IEEE world congress on computational intelligence (Cat. No. 98TH8360), pp. 69-73. IEEE, 1998. https://doi.org/10.1109/ICEC.1998.699146
Examples
>>> import numpy as np >>> from mealpy import FloatVar, PSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = PSO.LDW_PSO(epoch=1000, pop_size=50, c1=2.05, c2=20.5, w_min=0.4, w_max=0.9) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- amend_solution(solution: ndarray) ndarray[source]
This function is based on optimizer’s strategy. In each optimizer, this function can be overridden
- Parameters
solution – The position
- Returns
The valid solution based on optimizer’s strategy
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- generate_agent(solution: Optional[ndarray] = None) Agent[source]
Generate new agent with full information
- Parameters
solution (np.ndarray) – The solution
- class mealpy.swarm_based.PSO.OriginalPSO(epoch: int = 10000, pop_size: int = 100, c1: float = 2.05, c2: float = 2.05, w: float = 0.4, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Particle Swarm Optimization (PSO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
c1 (float) – Local coefficient, in range (0.0, 5.0). Default is 2.05.
c2 (float) – Global coefficient, in range (0.0, 5.0). Default is 2.05.
w (float) – Weight min of bird, in range (0.0, 1.0). Default is 0.4.
References
Kennedy, J. and Eberhart, R., 1995, November. Particle swarm optimization. In Proceedings of ICNN’95-international conference on neural networks (Vol. 4, pp. 1942-1948). IEEE. https://doi.org/10.1109/ICNN.1995.488968
Examples
>>> import numpy as np >>> from mealpy import FloatVar, PSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = PSO.OriginalPSO(epoch=1000, pop_size=50, c1=2.05, c2=20.5, w=0.4) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- amend_solution(solution: ndarray) ndarray[source]
This function is based on optimizer’s strategy. In each optimizer, this function can be overridden
- Parameters
solution – The position
- Returns
The valid solution based on optimizer’s strategy
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- generate_agent(solution: Optional[ndarray] = None) Agent[source]
Generate new agent with full information
- Parameters
solution (np.ndarray) – The solution
- class mealpy.swarm_based.PSO.P_PSO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Phasor Particle Swarm Optimization (P-PSO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
References
Ghasemi, M., Akbari, E., Rahimnejad, A., Razavi, S.E., Ghavidel, S. and Li, L., 2019. Phasor particle swarm optimization: a simple and efficient variant of PSO. Soft Computing, 23(19), pp.9701-9718. https://doi.org/10.1007/s00500-018-3536-8
Examples
>>> import numpy as np >>> from mealpy import FloatVar, PSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = PSO.P_PSO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- generate_agent(solution: Optional[ndarray] = None) Agent[source]
Generate new agent with full information
- Parameters
solution (np.ndarray) – The solution
mealpy.swarm_based.RFO module
- class mealpy.swarm_based.RFO.OriginalRFO(epoch=10000, pop_size: int = 100, phi_0: float = 0.785, theta: float = 0.5, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Red Fox Optimization (RFO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
phi_0 (float) – Fox observation angle set at the beginning. Default is 0.785 (pi/4).
theta (float) – Weather conditions parameter. Default is 0.5.
References
Połap, Dawid, and Marcin Woźniak. “Red fox optimization algorithm.” Expert Systems with Applications 166 (2021): 114107. https://doi.org/10.1016/j.eswa.2020.114107
Examples
>>> import numpy as np >>> from mealpy import FloatVar, RFO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = RFO.OriginalRFO(epoch=1000, pop_size=50, phi_0=0.785, theta=0.6) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.RSA module
- class mealpy.swarm_based.RSA.OriginalRSA(epoch=10000, pop_size=100, alpha=0.1, beta=0.1, **kwargs)[source]
Bases:
OptimizerThe original version of: Reptile Search Algorithm (RSA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
alpha (float) – Current range from (0.0, 100.0).
beta (float) – Current range from (0.0, 100.0).
References
- Abualigah, L., Abd Elaziz, M., Sumari, P., Geem, Z. W., & Gandomi, A. H. (2022).
Reptile Search Algorithm (RSA): A nature-inspired meta-heuristic optimizer. Expert Systems with Applications, 191, 116158. https://doi.org/10.1016/j.eswa.2021.116158
Examples
>>> import numpy as np >>> from mealpy import FloatVar, RSA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = RSA.OriginalRSA(epoch=1000, pop_size=50, alpha=0.1, beta=0.1) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.SCSO module
- class mealpy.swarm_based.SCSO.OriginalSCSO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Sand Cat Swarm Optimization (SCSO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Links
https://link.springer.com/article/10.1007/s00366-022-01604-x
https://www.mathworks.com/matlabcentral/fileexchange/110185-sand-cat-swarm-optimization
References
Seyyedabbasi, A., & Kiani, F. (2022). Sand Cat swarm optimization: a nature-inspired algorithm to solve global optimization problems. Engineering with Computers, 1-25.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SCSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SCSO.OriginalSCSO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.SFO module
- class mealpy.swarm_based.SFO.ImprovedSFO(epoch: int = 10000, pop_size: int = 100, pp: float = 0.1, **kwargs: object)[source]
Bases:
OptimizerThe original version: Improved Sailfish Optimizer (I-SFO)
Notes
Energy equation is reformed
AP (A) and epsilon parameters are removed
Opposition-based learning technique is used
- Hyper-parameters should fine-tune in approximate range to get faster convergence toward the global optimum:
pp (float): the rate between SailFish and Sardines (N_sf = N_s * pp) = 0.25, 0.2, 0.1
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SFO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SFO.ImprovedSFO(epoch=1000, pop_size=50, pp = 0.1) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.SFO.OriginalSFO(epoch: int = 10000, pop_size: int = 100, pp: float = 0.1, AP: float = 4.0, epsilon: float = 0.0001, **kwargs: object)[source]
Bases:
OptimizerThe original version of: SailFish Optimizer (SFO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, SailFish pop size, in range [5, 10000]. Default is 100.
pp (float) – The rate between SailFish and Sardines (N_sf = N_s * pp) = 0.25, 0.2, 0.1, in range (0.0, 1.0). Default is 0.1.
AP (float) – Coefficient for decreasing the value of Power Attack linearly from AP to 0, in range (0.0, 100.0). Default is 4.0.
epsilon (float) – Should be 0.0001, 0.001, in range (0.0, 0.1). Default is 0.0001.
References
Shadravan, S., Naji, H.R. and Bardsiri, V.K., 2019. The Sailfish Optimizer: A novel nature-inspired metaheuristic algorithm for solving constrained engineering optimization problems. Engineering Applications of Artificial Intelligence, 80, pp.20-34. https://doi.org/10.1016/j.engappai.2019.01.001
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SFO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SFO.OriginalSFO(epoch=1000, pop_size=50, pp = 0.1, AP = 4.0, epsilon = 0.0001) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.SHO module
- class mealpy.swarm_based.SHO.OriginalSHO(epoch: int = 10000, pop_size: int = 100, h_factor: float = 5.0, n_trials: int = 10, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Spotted Hyena Optimizer (SHO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
h_factor (float) – Coefficient linearly decreased from 5.0 to 0, in range (0.5, 10.0). Default is 5.0.
n_trials (int) – In range [1, 1000000]. Default is 10.
References
Dhiman, G. and Kumar, V., 2017. Spotted hyena optimizer: a novel bio-inspired based metaheuristic technique for engineering applications. Advances in Engineering Software, 114, pp.48-70. https://doi.org/10.1016/j.advengsoft.2017.05.014
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SHO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SHO.OriginalSHO(epoch=1000, pop_size=50, h_factor = 5.0, n_trials = 10) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.SLO module
- class mealpy.swarm_based.SLO.ImprovedSLO(epoch: int = 10000, pop_size: int = 100, c1: float = 1.2, c2: float = 1.2, **kwargs: object)[source]
Bases:
ModifiedSLOThe original version: Improved Sea Lion Optimization (ImprovedSLO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
c1 (float) – Local coefficient same as PSO, in range (0.0, 5.0). Default is 1.2.
c2 (float) – Global coefficient same as PSO, in range (0.0, 5.0). Default is 1.2.
References
Nguyen, Binh Minh, Trung Tran, Thieu Nguyen, and Giang Nguyen. “An improved sea lion optimization for workload elasticity prediction with neural networks.” International Journal of Computational Intelligence Systems 15, no. 1 (2022): 90. https://doi.org/10.1007/s44196-022-00156-8
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SLO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SLO.ImprovedSLO(epoch=1000, pop_size=50, c1=1.2, c2=1.5) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.SLO.ModifiedSLO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerOur modified version: Modified Sea Lion Optimization (M-SLO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Note
Local best idea in PSO is inspired
Levy-flight technique is used
Shrink encircling idea is used
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SLO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SLO.ModifiedSLO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- class mealpy.swarm_based.SLO.OriginalSLO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Sea Lion Optimization Algorithm (SLO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Caution
There are some unclear equations and parameters in the original paper https://doi.org/10.14569/IJACSA.2019.0100548
References
Masadeh, R., Mahafzah, B.A. and Sharieh, A., 2019. Sea lion optimization algorithm. Sea, 10(5), p.388.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SLO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SLO.OriginalSLO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.SMO module
- class mealpy.swarm_based.SMO.DevSMO(epoch=10000, pop_size=100, max_groups: int = 5, perturbation_rate: float = 0.7, **kwargs)[source]
Bases:
OptimizerOur developed version of: Spider Monkey Optimization (SMO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
max_groups (int) – Maximum number of groups for spider monkeys, in range [2, 100]. Default is 5.
perturbation_rate (float) – Perturbation rate for spider monkeys, in range [0.0, 1.0]. Default is 0.7.
Danger
The original paper is truly difficult to read and unclear. The operators are somewhat more understandable, but the pseudocode they provide is inaccurate. In addition, the design of the two parameters - local_leader_limit and global_leader_limit, is essentially meaningless. After each iteration, the population can be split and separated continuously, making it very unlikely for the if conditions involving these two values to ever be triggered. As a result, the operators in the two phases local_leader_decision and global_leader_decision will rarely be applied.
In summary, this algorithm has many issues, and the original MATLAB source code is also unavailable. I cannot guarantee its correctness, so I will refer to it as DevSMO.
References
- [1] Bansal, J. C., Sharma, H., Jadon, S. S., & Clerc, M. (2014).
Spider monkey optimization algorithm for numerical optimization. Memetic computing, 6(1), 31-47. https://doi.org/10.1007/s12293-013-0128-0
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SMO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "obj_func": objective_function, >>> "minmax": "min", >>> } >>> >>> model = SMO.DevSMO(epoch=1000, pop_size=50, max_groups = 5, perturbation_rate = 0.7) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
mealpy.swarm_based.SRSR module
- class mealpy.swarm_based.SRSR.OriginalSRSR(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Swarm Robotics Search And Rescue (SRSR)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Bakhshipour, M., Ghadi, M.J. and Namdari, F., 2017. Swarm robotics search & rescue: A novel artificial intelligence-inspired optimization approach. Applied Soft Computing, 57, pp.708-726. https://doi.org/10.1016/j.asoc.2017.02.028
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SRSR >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SRSR.OriginalSRSR(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- generate_agent(solution: Optional[ndarray] = None) Agent[source]
Generate new agent with full information
- Parameters
solution (np.ndarray) – The solution
mealpy.swarm_based.SSA module
- class mealpy.swarm_based.SSA.DevSSA(epoch: int = 10000, pop_size: int = 100, ST: float = 0.8, PD: float = 0.2, SD: float = 0.1, **kwargs: object)[source]
Bases:
OptimizerThe developed version: Sparrow Search Algorithm (SSA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
ST (float) – ST in [0.5, 1.0], safety threshold value, in range (0.0, 1.0). Default is 0.8.
PD (float) – Number of producers (percentage), in range (0.0, 1.0). Default is 0.2.
SD (float) – Number of sparrows who perceive the danger, in range (0.0, 1.0). Default is 0.1.
Note
First, the population is sorted to find g-best and g-worst
In Eq. 4, the self.generator.normal() gaussian distribution is used instead of A+ and L
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SSA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SSA.DevSSA(epoch=1000, pop_size=50, ST = 0.8, PD = 0.2, SD = 0.1) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.SSA.OriginalSSA(epoch: int = 10000, pop_size: int = 100, ST: float = 0.8, PD: float = 0.2, SD: float = 0.1, **kwargs: object)[source]
Bases:
DevSSAThe original version of: Sparrow Search Algorithm (SSA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
ST (float) – Safety threshold value, in range [0.5, 1.0]. Default is 0.8.
PD (float) – Number of producers (percentage). Default is 0.2.
SD (float) – Number of sparrows who perceive the danger. Default is 0.1.
Note
The paper contains some unclear equations and symbol https://doi.org/10.1080/21642583.2019.1708830
References
Xue, J. and Shen, B., 2020. A novel swarm intelligence optimization approach: sparrow search algorithm. Systems Science & Control Engineering, 8(1), pp.22-34.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SSA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SSA.OriginalSSA(epoch=1000, pop_size=50, ST = 0.8, PD = 0.2, SD = 0.1) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.SSO module
- class mealpy.swarm_based.SSO.OriginalSSO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Salp Swarm Optimization (SSO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
References
Mirjalili, S., Gandomi, A.H., Mirjalili, S.Z., Saremi, S., Faris, H. and Mirjalili, S.M., 2017. Salp Swarm Algorithm: A bio-inspired optimizer for engineering design problems. Advances in Engineering Software, 114, pp.163-191. https://doi.org/10.1016/j.advengsoft.2017.07.002
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SSO.OriginalSSO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.SSpiderA module
- class mealpy.swarm_based.SSpiderA.DevSSpiderA(epoch: int = 10000, pop_size: int = 100, r_a: float = 1.0, p_c: float = 0.7, p_m: float = 0.1, **kwargs: object)[source]
Bases:
OptimizerOur developed version of: Social Spider Algorithm (DevSSpiderA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
r_a (float) – The rate of vibration attenuation when propagating over the spider web, in range (0.0, 5.0). Default is 1.0.
p_c (float) – Controls the probability of the spiders changing their dimension mask in the random walk step, in range (0.0, 1.0). Default is 0.7.
p_m (float) – The probability of each value in a dimension mask to be one, in range (0.0, 1.0). Default is 0.1.
Note
The version of the algorithm available on the GitHub repository has a slow convergence rate. Changes the idea of intensity, which one has better intensity, others will move toward to it https://github.com/James-Yu/SocialSpiderAlgorithm (Modified this version)
References
James, J.Q. and Li, V.O., 2015. A social spider algorithm for global optimization. Applied soft computing, 30, pp.614-627. https://doi.org/10.1016/j.asoc.2015.02.014
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SSpiderA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SSpiderA.DevSSpiderA(epoch=1000, pop_size=50, r_a = 1.0, p_c = 0.7, p_m = 0.1) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
- generate_agent(solution: Optional[ndarray] = None) Agent[source]
Generate new agent with full information
- Parameters
solution (np.ndarray) – The solution
- generate_empty_agent(solution: Optional[ndarray] = None) Agent[source]
- Overriding method in Optimizer class
x: The position of s on the web.
train: The fitness of the current position of s
target_vibration: The target vibration of s in the previous iteration.
intensity_vibration: intensity of vibration
movement_vector: The movement that s performed in the previous iteration
dimension_mask: The dimension mask 1 that s employed to guide movement in the previous iteration
The dimension mask is a 0-1 binary vector of length problem size
n_changed: The number of iterations since s has last changed its target vibration. (No need)
mealpy.swarm_based.SSpiderO module
- class mealpy.swarm_based.SSpiderO.OriginalSSpiderO(epoch: int = 10000, pop_size: int = 100, fp_min: float = 0.65, fp_max: float = 0.9, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Social Spider Optimization (SSpiderO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
fp_min (float) – Female Percent min, in range (0.0, 1.0). Default is 0.65.
fp_max (float) – Female Percent max, in range (0.0, 1.0). Default is 0.9.
References
Luque-Chang, A., Cuevas, E., Fausto, F., Zaldivar, D. and Pérez, M., 2018. Social spider optimization algorithm: modifications, applications, and perspectives. Mathematical Problems in Engineering, 2018. https://doi.org/10.1155/2018/6843923
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SSpiderO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SSpiderO.OriginalSSpiderO(epoch=1000, pop_size=50, fp_min = 0.65, fp_max = 0.9) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- amend_solution(solution: ndarray) ndarray[source]
This function is based on optimizer’s strategy. In each optimizer, this function can be overridden
- Parameters
solution – The position
- Returns
The valid solution based on optimizer’s strategy
- evolve(epoch)[source]
The main operations (equations) of algorithm. Inherit from Optimizer class
- Parameters
epoch (int) – The current iteration
mealpy.swarm_based.STO module
- class mealpy.swarm_based.STO.OriginalSTO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Siberian Tiger Optimization (STO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Attention
This is somewhat concerning, as there appears to be a high degree of similarity between the source code for this algorithm and the Osprey Optimization Algorithm (OOA)
Algorithm design is similar to Zebra Optimization Algorithm (ZOA), Osprey Optimization Algorithm (OOA), Coati Optimization Algorithm (CoatiOA), Northern Goshawk Optimization (NGO), Language Education Optimization (LEO), Serval Optimization Algorithm (SOA), Walrus Optimization Algorithm (WOA), Fennec Fox Optimization (FFO), Three-periods optimization algorithm (TPOA), Teamwork optimization algorithm (TOA), Pelican Optimization Algorithm (POA), Tasmanian devil optimization (TDO), Archery algorithm (AA), Cat and mouse based optimizer (CMBO)
It may be useful to compare the Matlab code of this algorithm with those of the similar algorithms to ensure its accuracy and completeness.
The article may share some similarities with previous work by the same authors, further investigation may be warranted to verify the benchmark results reported in the papers and ensure their reliability and accuracy.
References
Trojovský, P., Dehghani, M., & Hanuš, P. (2022). Siberian Tiger Optimization: A New Bio-Inspired Metaheuristic Algorithm for Solving Engineering Optimization Problems. IEEE Access, 10, 132396-132431. https://doi.org/10.1109/ACCESS.2022.3229964
Examples
>>> import numpy as np >>> from mealpy import FloatVar, STO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = STO.OriginalSTO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.SeaHO module
- class mealpy.swarm_based.SeaHO.OriginalSeaHO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Sea-Horse Optimization (SeaHO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Links
https://link.springer.com/article/10.1007/s10489-022-03994-3
https://www.mathworks.com/matlabcentral/fileexchange/115945-sea-horse-optimizer
References
Zhao, S., Zhang, T., Ma, S., & Wang, M. (2022). Sea-horse optimizer: a novel nature-inspired meta-heuristic for global optimization problems. Applied Intelligence, 1-28.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SeaHO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = SeaHO.OriginalSeaHO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.ServalOA module
- class mealpy.swarm_based.ServalOA.OriginalServalOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Serval Optimization Algorithm (ServalOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Danger
It’s concerning that the author seems to be reusing the same algorithms with minor variations.
Algorithm design is similar to Zebra Optimization Algorithm (ZOA), Osprey Optimization Algorithm (OOA), Coati Optimization Algorithm (CoatiOA), Siberian Tiger Optimization (STO), Language Education Optimization (LEO), Pelican Optimization Algorithm (POA), Walrus Optimization Algorithm (WOA), Fennec Fox Optimization (FFO), Three-periods optimization algorithm (TPOA), Teamwork optimization algorithm (TOA), Northern goshawk optimization (NGO), Tasmanian devil optimization (TDO), Archery algorithm (AA), Cat and mouse based optimizer (CMBO)
It may be useful to compare the Matlab code of this algorithm with those of the similar algorithms to ensure its accuracy and completeness.
The article may share some similarities with previous work by the same authors, further investigation may be warranted to verify the benchmark results reported in the papers and ensure their reliability and accuracy.
References
Dehghani, M., & Trojovský, P. (2022). Serval Optimization Algorithm: A New Bio-Inspired Approach for Solving Optimization Problems. Biomimetics, 7(4), 204. https://www.mdpi.com/2313-7673/7/4/204
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ServalOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = ServalOA.OriginalServalOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.SquirrelSA module
- class mealpy.swarm_based.SquirrelSA.OriginalSquirrelSA(epoch: int = 10000, pop_size: int = 100, n_food_sources=4, predator_prob=0.1, gliding_constant=1.9, scaling_factor=18, beta=1.5, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Squirrel Search Algorithm (SquirrelSA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
n_food_sources (int) – Number of food sources (1 hickory + 3 acorn trees), in range [1, 10]. Default is 4.
predator_prob (float) – Predator presence probability (P_dp), in range [0.0, 1.0]. Default is 0.1.
gliding_constant (float) – Gliding constant (G_c) for exploration/exploitation balance, in range [0.0, 10.0]. Default is 1.9.
scaling_factor (float) – Scaling factor for gliding distance, in range [1, 100]. Default is 18.
beta (float) – Beta parameter for Levy flight, in range [0.0, 10.0]. Default is 1.5.
References
Jain, M., Singh, V., & Rani, A. (2019). A novel nature-inspired algorithm for optimization: Squirrel search algorithm. Swarm and evolutionary computation, 44, 148-175. https://doi.org/10.1016/j.swevo.2018.02.013
Examples
>>> import numpy as np >>> from mealpy import FloatVar, SquirrelSA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> 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) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.TDO module
- class mealpy.swarm_based.TDO.OriginalTDO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Tasmanian Devil Optimization (TDO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Attention
This is somewhat concerning, as there appears to be a high degree of similarity between the source code for this algorithm and the Osprey Optimization Algorithm (OOA)
Algorithm design is similar to Zebra Optimization Algorithm (ZOA), Osprey Optimization Algorithm (OOA), Pelican optimization algorithm (POA), Siberian Tiger Optimization (STO), Language Education Optimization (LEO), Serval Optimization Algorithm (SOA), Walrus Optimization Algorithm (WOA), Fennec Fox Optimization (FFO), Three-periods optimization algorithm (TPOA), Teamwork optimization algorithm (TOA), Northern goshawk optimization (NGO), Osprey Optimization Algorithm (OOA), Archery algorithm (AA), Cat and mouse based optimizer (CMBO)
It may be useful to compare the Matlab code of this algorithm with those of the similar algorithms to ensure its accuracy and completeness.
The article may share some similarities with previous work by the same authors, further investigation may be warranted to verify the benchmark results reported in the papers and ensure their reliability and accuracy.
References
Dehghani, M., Hubálovský, Š., & Trojovský, P. (2022). Tasmanian devil optimization: a new bio-inspired optimization algorithm for solving optimization algorithm. IEEE Access, 10, 19599-19620. https://ieeexplore.ieee.org/abstract/document/9714388
Examples
>>> import numpy as np >>> from mealpy import FloatVar, TDO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = TDO.OriginalTDO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.TSO module
- class mealpy.swarm_based.TSO.OriginalTSO(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Tuna Swarm Optimization (TSO)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Note
Two variables that authors consider it as a constants (aa = 0.7 and zz = 0.05)
https://www.mathworks.com/matlabcentral/fileexchange/101734-tuna-swarm-optimization
References
Xie, L., Han, T., Zhou, H., Zhang, Z. R., Han, B., & Tang, A. (2021). Tuna swarm optimization: a novel swarm-based metaheuristic algorithm for global optimization. Computational intelligence and Neuroscience, 2021.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, TSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = TSO.OriginalTSO(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.WOA module
- class mealpy.swarm_based.WOA.DevWOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerOur developed version of: Whale Optimization Algorithm (WOA)
Note
Hanlding simple vector instead of loop through whole dimensions
Using greedy to update position
Examples
>>> import numpy as np >>> from mealpy import FloatVar, WOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = WOA.DevWOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.WOA.DevWOAmM(epoch: int = 10000, pop_size: int = 100, mut_rand: bool = False, patience: int = 0, restart_rate: float = 0.2, bound: str = 'clip', **kwargs)[source]
Bases:
OriginalWOAmMOur developed version of: Whale Optimization Algorithm with Modified Mutualism (WOAmM)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Population size, in range [5, 10000]. Default is 100.
mut_rand (bool) – Whether mutualism random coefficients are generated per dimension. Default is False.
patience (int) – Number of stagnant epochs before restarting worst agents. Set 0 to disable, in range [0, 100000]. Default is 0.
restart_rate (float) – Ratio of worst agents to restart when stagnation occurs, in range [0.0, 1.0]. Default is 0.2.
bound (str) – Boundary handling method. Supported: “clip”, “reflect”, “random”. Default is “clip”.
Note
This version replaces the population after the WOA phase (no greedy selection).
References
Chakraborty, S., Saha, A. K., Sharma, S., Mirjalili, S., & Chakraborty, R. (2021). A novel enhanced whale optimization algorithm for global optimization. Computers & Industrial Engineering, 153, 107086. https://doi.org/10.1016/j.cie.2020.107086
- class mealpy.swarm_based.WOA.HI_WOA(epoch: int = 10000, pop_size: int = 100, feedback_max: int = 10, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Hybrid Improved Whale Optimization Algorithm (HI-WOA)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Number of population size, in range [5, 10000]. Default is 100.
feedback_max (int) – Maximum iterations of each feedback, in range [2, 2 + int(epoch/2)]. Default is 10.
References
Tang, C., Sun, W., Wu, W. and Xue, M., 2019, July. A hybrid improved whale optimization algorithm. In 2019 IEEE 15th International Conference on Control and Automation (ICCA) (pp. 362-367). IEEE. https://doi.org/10.1109/ICCA.2019.8900003
Examples
>>> import numpy as np >>> from mealpy import FloatVar, WOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = WOA.HI_WOA(epoch=1000, pop_size=50, feedback_max = 10) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.WOA.OriginalWOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Whale Optimization Algorithm (WOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Links
References
Mirjalili, S. and Lewis, A., 2016. The whale optimization algorithm. Advances in engineering software, 95, pp.51-67.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, WOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = WOA.OriginalWOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.swarm_based.WOA.OriginalWOAmM(epoch: int = 10000, pop_size: int = 100, mut_rand: bool = False, patience: int = 0, restart_rate: float = 0.2, bound: str = 'clip', **kwargs)[source]
Bases:
OptimizerThe original version of: Whale Optimization Algorithm with Modified Mutualism (WOAmM)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Population size, in range [5, 10000]. Default is 100.
mut_rand (bool) – Whether mutualism random coefficients are generated per dimension. Default is False.
patience (int) – Number of stagnant epochs before restarting worst agents. Set 0 to disable, in range [0, 100000]. Default is 0.
restart_rate (float) – Ratio of worst agents to restart when stagnation occurs, in range [0.0, 1.0]. Default is 0.2.
bound (str) – Boundary handling method. Supported: “clip”, “reflect”, “random”. Default is “clip”.
References
Chakraborty, S., Saha, A. K., Sharma, S., Mirjalili, S., & Chakraborty, R. (2021). A novel enhanced whale optimization algorithm for global optimization. Computers & Industrial Engineering, 153, 107086. https://doi.org/10.1016/j.cie.2020.107086
Examples
>>> import numpy as np >>> from mealpy import FloatVar, WOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = WOA.OriginalWOAmM(epoch=1000, pop_size=50, mut_rand=True, patience=2, restart_rate=0.3, bound="clip") >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- amend_solution(solution: ndarray) ndarray[source]
This function is based on optimizer’s strategy. In each optimizer, this function can be overridden
- Parameters
solution – The position
- Returns
The valid solution based on optimizer’s strategy
mealpy.swarm_based.WSO module
- class mealpy.swarm_based.WSO.OriginalWSO(epoch=10000, pop_size=100, tau: float = 4.125, p_min: float = 0.5, p_max: float = 1.5, f_min: float = 0.07, f_max: float = 0.75, a0: float = 6.25, a1: float = 100.0, a2: float = 0.0005, **kwargs)[source]
Bases:
OptimizerThe original version: White Shark Optimizer (WSO)
- Parameters
epoch (int) – Maximum number of iterations, in range [1, 100000]. Default is 10000.
pop_size (int) – Population size, in range [5, 100000]. Default is 100.
tau (float) – Acceleration coefficient used to derive the constriction factor mu, in range [0.0, 100.0]. Default is 4.125.
p_min (float) – Initial velocities to control the effect of global and local best positions, in range [0.0, 10.0]. Default is 0.5.
p_max (float) – Subordinate velocities to control the effect of global and local best positions, in range [0.0, 100.0]. Default is 1.5.
f_min (float) – Minimum frequencies of the undulating motion, in range (0.0, 10.0). Default is 0.07.
f_max (float) – Maximum frequencies of the undulating motion, in range (0.0, 10.0). Default is 0.75.
a0 (float) – Constant managing exploration vs. exploitation via the movement force parameter mv (hearing/smell strength), in range (0.0, 1000.0). Default is 6.25.
a1 (float) – Constant managing exploration vs. exploitation via the movement force parameter mv (hearing/smell strength), in range (0.0, 1000.0). Default is 100.0.
a2 (float) – Constant controlling the sight/smell strength when following the best shark in the school (s_s), in range (0.0, 1000.0). Default is 0.0005.
Warning
Discrepancies have been spotted between the MATLAB code and the pseudocode presented in the algorithm’s paper. Users should exercise caution when using this algorithm.
This version accurately implements the equations from the paper, allowing users to validate both the algorithm’s performance and the published results.
A drawback of this algorithm is the introduction of too many meaningless parameters. Replacing them with simpler operators could potentially improve performance while eliminating the need for parameter tuning
Many parameters are fixed in the paper, but this heavily depends on your specific problem. Therefore, users are advised to read the paper carefully to understand the functional meaning of these hyperparameters.
Links
References
Braik, M., Hammouri, A., Atwan, J., Al-Betar, M. A., & Awadallah, M. A. (2022). White Shark Optimizer: A novel bio-inspired meta-heuristic algorithm for global optimization problems. Knowledge-Based Systems, 243, 108457.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, WSO >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = WSO.OriginalWSO(epoch=1000, pop_size=50, tau=4.2, p_min=0.5, p_max=2.0, f_min=0.1, f_max=0.8, a0=6, a1=100, a2=0.001) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.WaOA module
- class mealpy.swarm_based.WaOA.OriginalWaOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Walrus Optimization Algorithm (WaOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Attention
This is somewhat concerning, as there appears to be a high degree of similarity between the source code for this algorithm and the Northern Goshawk Optimization (NGO)
Algorithm design is similar to Zebra Optimization Algorithm (ZOA), Osprey Optimization Algorithm (OOA), Coati Optimization Algorithm (CoatiOA), Siberian Tiger Optimization (STO), Language Education Optimization (LEO), Serval Optimization Algorithm (SOA), Northern Goshawk Optimization (NGO), Fennec Fox Optimization (FFO), Three-periods optimization algorithm (TPOA), Teamwork optimization algorithm (TOA), Pelican Optimization Algorithm (POA), Tasmanian devil optimization (TDO), Archery algorithm (AA), Cat and mouse based optimizer (CMBO)
It may be useful to compare the Matlab code of this algorithm with those of the similar algorithms to ensure its accuracy and completeness.
The article may share some similarities with previous work by the same authors, further investigation may be warranted to verify the benchmark results reported in the papers and ensure their reliability and accuracy.
References
Trojovský, P., & Dehghani, M. (2022). Walrus Optimization Algorithm: A New Bio-Inspired Metaheuristic Algorithm. https://doi.org/10.1016/j.eswa.2023.122413
Examples
>>> import numpy as np >>> from mealpy import FloatVar, WaOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = WaOA.OriginalWaOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
mealpy.swarm_based.ZOA module
- class mealpy.swarm_based.ZOA.OriginalZOA(epoch: int = 10000, pop_size: int = 100, **kwargs: object)[source]
Bases:
OptimizerThe original version of: Zebra Optimization Algorithm (ZOA)
- Parameters
epoch (int) – Maximum number of iterations, default = 10000.
pop_size (int) – Number of population size, default = 100.
Caution
It’s concerning that the author seems to be reusing the same algorithms with minor variations.
Algorithm design is similar to Zebra Optimization Algorithm (ZOA), Osprey Optimization Algorithm (OOA), Pelican optimization algorithm (POA), Siberian Tiger Optimization (STO), Language Education Optimization (LEO), Serval Optimization Algorithm (SOA), Walrus Optimization Algorithm (WOA), Fennec Fox Optimization (FFO), Three-periods optimization algorithm (TPOA), Teamwork optimization algorithm (TOA), Northern goshawk optimization (NGO), Tasmanian devil optimization (TDO), Archery algorithm (AA), Cat and mouse based optimizer (CMBO).
It may be useful to compare the Matlab code of this algorithm with those of the similar algorithms to ensure its accuracy and completeness.
The article may share some similarities with previous work by the same authors, further investigation may be warranted to verify the benchmark results reported in the papers and ensure their reliability and accuracy.
Links
References
Trojovská, E., Dehghani, M., & Trojovský, P. (2022). Zebra optimization algorithm: A new bio-inspired optimization algorithm for solving optimization algorithm. IEEE Access, 10, 49445-49473.
Examples
>>> import numpy as np >>> from mealpy import FloatVar, ZOA >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = ZOA.OriginalZOA(epoch=1000, pop_size=50) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")