mealpy.physics_based package

mealpy.physics_based.ASO

class mealpy.physics_based.ASO.BaseASO(problem, epoch=10000, pop_size=100, alpha=50, beta=0.2, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Atom Search Optimization (ASO)

Links:
  1. https://doi.org/10.1016/j.knosys.2018.08.030

  2. https://www.mathworks.com/matlabcentral/fileexchange/67011-atom-search-optimization-aso-algorithm

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • alpha (int): Depth weight, default = 50

  • beta (float): Multiplier weight, default = 0.2

Examples

>>> import numpy as np
>>> from mealpy.physics_based.ASO import BaseASO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> alpha = 50
>>> beta = 0.2
>>> model = BaseASO(problem_dict1, epoch, pop_size, alpha, beta)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Zhao, W., Wang, L. and Zhang, Z., 2019. Atom search optimization and its application to solve a hydrogeologic parameter estimation problem. Knowledge-Based Systems, 163, pp.283-304.

ID_MAS = 3
ID_POS = 0
ID_TAR = 1
ID_VEL = 2
amend_position(position=None)[source]

If solution out of bound at dimension x, then it will re-arrange to random location in the range of domain

Parameters

position – vector position (location) of the solution.

Returns

Amended position

create_solution()[source]
To get the position, fitness wrapper, target and obj list
  • A[self.ID_POS] –> Return: position

  • A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]

  • A[self.ID_TAR][self.ID_FIT] –> Return: target

  • A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]

Returns

wrapper of solution with format [position, [target, [obj1, obj2, …]], velocity, mass]

Return type

list

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

mealpy.physics_based.ArchOA

class mealpy.physics_based.ArchOA.OriginalArchOA(problem, epoch=10000, pop_size=100, c1=2, c2=6, c3=2, c4=0.5, acc_max=0.9, acc_min=0.1, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Archimedes Optimization Algorithm (ArchOA)

Links:
  1. https://doi.org/10.1007/s10489-020-01893-z

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • c1 (int): factor, default belongs to [1, 2]

  • c2 (int): factor, Default belongs to [2, 4, 6]

  • c3 (int): factor, Default belongs to [1, 2]

  • c4 (float): factor, Default belongs to [0.5, 1]

  • acc_max (float): acceleration max, Default 0.9

  • acc_min (float): acceleration min, Default 0.1

Examples

>>> import numpy as np
>>> from mealpy.physics_based.ArchOA import OriginalArchOA
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> c1 = 2
>>> c2 = 5
>>> c3 = 2
>>> c4 = 0.5
>>> acc_max = 0.9
>>> acc_min = 0.1
>>> model = OriginalArchOA(problem_dict1, epoch, pop_size, c1, c2, c3, c4, acc_max, acc_min)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Hashim, F.A., Hussain, K., Houssein, E.H., Mabrouk, M.S. and Al-Atabany, W., 2021. Archimedes optimization algorithm: a new metaheuristic algorithm for solving optimization problems. Applied Intelligence, 51(3), pp.1531-1551.

ID_ACC = 4
ID_DEN = 2
ID_POS = 0
ID_TAR = 1
ID_VOL = 3
create_solution()[source]
To get the position, fitness wrapper, target and obj list
  • A[self.ID_POS] –> Return: position

  • A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]

  • A[self.ID_TAR][self.ID_FIT] –> Return: target

  • A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]

Returns

wrapper of solution with format [position, [target, [obj1, obj2, …]], density, volume, acceleration]

Return type

list

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

mealpy.physics_based.EFO

class mealpy.physics_based.EFO.BaseEFO(problem, epoch=10000, pop_size=100, r_rate=0.3, ps_rate=0.85, p_field=0.1, n_field=0.45, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

My changed version of: Electromagnetic Field Optimization (EFO)

Notes

  • Changed the flow of original algorithm and using global best solution in equation.

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • r_rate (float): [0.1, 0.6], default = 0.3, like mutation parameter in GA but for one variable

  • ps_rate (float): [0.5, 0.95], default = 0.85, like crossover parameter in GA

  • p_field (float): [0.05, 0.3], default = 0.1, portion of population, positive field

  • n_field (float): [0.3, 0.7], default = 0.45, portion of population, negative field

Examples

>>> import numpy as np
>>> from mealpy.physics_based.EFO import BaseEFO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> r_rate = 0.3
>>> ps_rate = 0.85
>>> p_field = 0.1
>>> n_field = 0.45
>>> model = BaseEFO(problem_dict1, epoch, pop_size, r_rate, ps_rate, p_field, n_field)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

class mealpy.physics_based.EFO.OriginalEFO(problem, epoch=10000, pop_size=100, r_rate=0.3, ps_rate=0.85, p_field=0.1, n_field=0.45, **kwargs)[source]

Bases: mealpy.physics_based.EFO.BaseEFO

The original version of: Electromagnetic Field Optimization (EFO)

Links:
  1. https://www.mathworks.com/matlabcentral/fileexchange/52744-electromagnetic-field-optimization-a-physics-inspired-metaheuristic-optimization-algorithm

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • r_rate (float): [0.1, 0.6], default = 0.3, like mutation parameter in GA but for one variable

  • ps_rate (float): [0.5, 0.95], default = 0.85, like crossover parameter in GA

  • p_field (float): [0.05, 0.3], default = 0.1, portion of population, positive field

  • n_field (float): [0.3, 0.7], default = 0.45, portion of population, negative field

Examples

>>> import numpy as np
>>> from mealpy.physics_based.EFO import OriginalEFO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> r_rate = 0.3
>>> ps_rate = 0.85
>>> p_field = 0.1
>>> n_field = 0.45
>>> model = OriginalEFO(problem_dict1, epoch, pop_size, r_rate, ps_rate, p_field, n_field)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Abedinpourshotorban, H., Shamsuddin, S.M., Beheshti, Z. and Jawawi, D.N., 2016. Electromagnetic field optimization: a physics-inspired metaheuristic optimization algorithm. Swarm and Evolutionary Computation, 26, pp.8-22.

amend_position(position=None)[source]

If solution out of bound at dimension x, then it will re-arrange to random location in the range of domain

Parameters

position – vector position (location) of the solution.

Returns

Amended position

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

initialization()[source]

mealpy.physics_based.EO

class mealpy.physics_based.EO.AdaptiveEO(problem, epoch=10000, pop_size=100, **kwargs)[source]

Bases: mealpy.physics_based.EO.BaseEO

The original version of: Adaptive Equilibrium Optimization (AEO)

Links:
  1. https://doi.org/10.1016/j.engappai.2020.103836

Examples

>>> import numpy as np
>>> from mealpy.physics_based.EO import AdaptiveEO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> model = AdaptiveEO(problem_dict1, epoch, pop_size)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Wunnava, A., Naik, M.K., Panda, R., Jena, B. and Abraham, A., 2020. A novel interdependence based multilevel thresholding technique using adaptive equilibrium optimizer. Engineering Applications of Artificial Intelligence, 94, p.103836.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

class mealpy.physics_based.EO.BaseEO(problem, epoch=10000, pop_size=100, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Equilibrium Optimizer (EO)

Links:
  1. https://doi.org/10.1016/j.knosys.2019.105190

  2. https://www.mathworks.com/matlabcentral/fileexchange/73352-equilibrium-optimizer-eo

Examples

>>> import numpy as np
>>> from mealpy.physics_based.EO import BaseEO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> model = BaseEO(problem_dict1, epoch, pop_size)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Faramarzi, A., Heidarinejad, M., Stephens, B. and Mirjalili, S., 2020. Equilibrium optimizer: A novel optimization algorithm. Knowledge-Based Systems, 191, p.105190.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

make_equilibrium_pool(list_equilibrium=None)[source]
class mealpy.physics_based.EO.ModifiedEO(problem, epoch=10000, pop_size=100, **kwargs)[source]

Bases: mealpy.physics_based.EO.BaseEO

The original version of: Modified Equilibrium Optimizer (MEO)

Links:
  1. https://doi.org/10.1016/j.asoc.2020.106542

Examples

>>> import numpy as np
>>> from mealpy.physics_based.EO import ModifiedEO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> model = ModifiedEO(problem_dict1, epoch, pop_size)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Gupta, S., Deep, K. and Mirjalili, S., 2020. An efficient equilibrium optimizer with mutation strategy for numerical optimization. Applied Soft Computing, 96, p.106542.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

mealpy.physics_based.HGSO

class mealpy.physics_based.HGSO.BaseHGSO(problem, epoch=10000, pop_size=100, n_clusters=2, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Henry Gas Solubility Optimization (HGSO)

Links:
  1. https://www.sciencedirect.com/science/article/abs/pii/S0167739X19306557

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • n_clusters (int): [2, 10], number of clusters, default = 2

Examples

>>> import numpy as np
>>> from mealpy.physics_based.HGSO import BaseHGSO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> n_clusters = 3
>>> model = BaseHGSO(problem_dict1, epoch, pop_size, n_clusters)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Hashim, F.A., Houssein, E.H., Mabrouk, M.S., Al-Atabany, W. and Mirjalili, S., 2019. Henry gas solubility optimization: A novel physics-based algorithm. Future Generation Computer Systems, 101, pp.646-667.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

initialization()[source]

mealpy.physics_based.MVO

class mealpy.physics_based.MVO.BaseMVO(problem, epoch=10000, pop_size=100, wep_min=0.2, wep_max=1.0, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

My changed version of: Multi-Verse Optimizer (MVO)

Notes

  • Use my routtele wheel selection which can handle negative values

  • No need condition when np.random.normalize fitness. So the chance to choose while whole higher –> better

  • Change equation 3.3 to match the name of parameter wep_minmax

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • wep_min (float): [0.05, 0.3], Wormhole Existence Probability (min in Eq.(3.3) paper, default = 0.2

  • wep_max (float: [0.75, 1.0], Wormhole Existence Probability (max in Eq.(3.3) paper, default = 1.0

Examples

>>> import numpy as np
>>> from mealpy.physics_based.MVO import BaseMVO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> wep_min = 0.2
>>> wep_max = 1.0
>>> model = BaseMVO(problem_dict1, epoch, pop_size, wep_min, wep_max)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

class mealpy.physics_based.MVO.OriginalMVO(problem, epoch=10000, pop_size=100, wep_min=0.2, wep_max=1.0, **kwargs)[source]

Bases: mealpy.physics_based.MVO.BaseMVO

The original version of: Multi-Verse Optimizer (MVO)

Links:
  1. http://dx.doi.org/10.1007/s00521-015-1870-7

  2. https://www.mathworks.com/matlabcentral/fileexchange/50112-multi-verse-optimizer-mvo

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • wep_min (float): [0.05, 0.3], Wormhole Existence Probability (min in Eq.(3.3) paper, default = 0.2

  • wep_max (float: [0.75, 1.0], Wormhole Existence Probability (max in Eq.(3.3) paper, default = 1.0

Examples

>>> import numpy as np
>>> from mealpy.physics_based.MVO import OriginalMVO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> wep_min = 0.2
>>> wep_max = 1.0
>>> model = OriginalMVO(problem_dict1, epoch, pop_size, wep_min, wep_max)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Mirjalili, S., Mirjalili, S.M. and Hatamlou, A., 2016. Multi-verse optimizer: a nature-inspired algorithm for global optimization. Neural Computing and Applications, 27(2), pp.495-513.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

mealpy.physics_based.NRO

class mealpy.physics_based.NRO.BaseNRO(problem, epoch=10000, pop_size=100, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Nuclear Reaction Optimization (NRO)

Links:
  1. https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=8720256

Examples

>>> import numpy as np
>>> from mealpy.physics_based.NRO import BaseNRO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> model = BaseNRO(problem_dict1, epoch, pop_size)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Wei, Z., Huang, C., Wang, X., Han, T. and Li, Y., 2019. Nuclear reaction optimization: A novel and powerful physics-based algorithm for global optimization. IEEE Access, 7, pp.66084-66109. [2] Wei, Z.L., Zhang, Z.R., Huang, C.Q., Han, B., Tang, S.Q. and Wang, L., 2019, June. An Approach Inspired from Nuclear Reaction Processes for Numerical Optimization. In Journal of Physics: Conference Series (Vol. 1213, No. 3, p. 032009). IOP Publishing.

amend_position(position=None)[source]

If solution out of bound at dimension x, then it will re-arrange to random location in the range of domain

Parameters

position – vector position (location) of the solution.

Returns

Amended position

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

mealpy.physics_based.SA

class mealpy.physics_based.SA.BaseSA(problem, epoch=10000, pop_size=100, max_sub_iter=5, t0=1000, t1=1, move_count=5, mutation_rate=0.1, mutation_step_size=0.1, mutation_step_size_damp=0.99, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Simulated Annealing (SA)

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • max_sub_iter (int): [5, 10, 15], Maximum Number of Sub-Iteration (within fixed temperature), default=5

  • t0 (int): Fixed parameter, Initial Temperature, default=1000

  • t1 (int): Fixed parameter, Final Temperature, default=1

  • move_count (int): [5, 20], Move Count per Individual Solution, default=5

  • mutation_rate (float): [0.01, 0.2], Mutation Rate, default=0.1

  • mutation_step_size (float): [0.05, 0.1, 0.15], Mutation Step Size, default=0.1

  • mutation_step_size_damp (float): [0.8, 0.99], Mutation Step Size Damp, default=0.99

Examples

>>> import numpy as np
>>> from mealpy.physics_based.SA import BaseSA
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> max_sub_iter = 5
>>> t0 = 1000
>>> t1 = 1
>>> move_count = 5
>>> mutation_rate = 0.1
>>> mutation_step_size = 0.1
>>> mutation_step_size_damp = 0.99
>>> model = BaseSA(problem_dict1, epoch, pop_size, max_sub_iter, t0, t1, move_count, mutation_rate, mutation_step_size, mutation_step_size_damp)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Van Laarhoven, P.J. and Aarts, E.H., 1987. Simulated annealing. In Simulated annealing: Theory and applications (pp. 7-15). Springer, Dordrecht.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

initialization()[source]

mealpy.physics_based.TWO

class mealpy.physics_based.TWO.BaseTWO(problem, epoch=10000, pop_size=100, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Tug of War Optimization (TWO)

Links:
  1. https://www.researchgate.net/publication/332088054_Tug_of_War_Optimization_Algorithm

Examples

>>> import numpy as np
>>> from mealpy.physics_based.TWO import BaseTWO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> model = BaseTWO(problem_dict1, epoch, pop_size)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Kaveh, A., 2017. Tug of war optimization. In Advances in metaheuristic algorithms for optimal design of structures (pp. 451-487). Springer, Cham.

ID_POS = 0
ID_TAR = 1
ID_WEIGHT = 2
create_solution(minmax=0)[source]
To get the position, fitness wrapper, target and obj list
  • A[self.ID_POS] –> Return: position

  • A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]

  • A[self.ID_TAR][self.ID_FIT] –> Return: target

  • A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]

Returns

wrapper of solution with format [position, [target, [obj1, obj2, …]], weight]

Return type

list

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

initialization()[source]
class mealpy.physics_based.TWO.EnhancedTWO(problem, epoch=10000, pop_size=100, **kwargs)[source]

Bases: mealpy.physics_based.TWO.OppoTWO, mealpy.physics_based.TWO.LevyTWO

The original version of: Enhenced Tug of War Optimization (ETWO)

Links:
  1. https://doi.org/10.1016/j.procs.2020.03.063

Examples

>>> import numpy as np
>>> from mealpy.physics_based.TWO import EnhancedTWO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> r_rate = 0.3
>>> ps_rate = 0.85
>>> p_field = 0.1
>>> n_field = 0.45
>>> model = EnhancedTWO(problem_dict1, epoch, pop_size, r_rate, ps_rate, p_field, n_field)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Nguyen, T., Hoang, B., Nguyen, G. and Nguyen, B.M., 2020. A new workload prediction model using extreme learning machine and enhanced tug of war optimization. Procedia Computer Science, 170, pp.362-369.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

initialization()[source]
class mealpy.physics_based.TWO.LevyTWO(problem, epoch=10000, pop_size=100, **kwargs)[source]

Bases: mealpy.physics_based.TWO.BaseTWO

The Levy-flight version of: Tug of War Optimization (LTWO)

Notes

  • Applied the idea of Levy-flight technique

Examples

>>> import numpy as np
>>> from mealpy.physics_based.TWO import LevyTWO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> model = LevyTWO(problem_dict1, epoch, pop_size)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

class mealpy.physics_based.TWO.OppoTWO(problem, epoch=10000, pop_size=100, **kwargs)[source]

Bases: mealpy.physics_based.TWO.BaseTWO

The opossition-based learning version of: Tug of War Optimization (OTWO)

Notes

  • Applied the idea of Opposition-based learning technique

Examples

>>> import numpy as np
>>> from mealpy.physics_based.TWO import OppoTWO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> model = OppoTWO(problem_dict1, epoch, pop_size)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

initialization()[source]

mealpy.physics_based.WDO

class mealpy.physics_based.WDO.BaseWDO(problem, epoch=10000, pop_size=100, RT=3, g_c=0.2, alp=0.4, c_e=0.4, max_v=0.3, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Wind Driven Optimization (WDO)

Links:
  1. https://ieeexplore.ieee.org/abstract/document/6407788

Notes

  • pop is the set of “air parcel” - “position”

  • air parcel: is the set of gas atoms. Each atom represents a dimension in position and has its own velocity

  • pressure represented by fitness value

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • RT (int): [2, 3, 4], RT coefficient, default = 3

  • g_c (float): [0.1, 0.5], gravitational constant, default = 0.2

  • alp (float): [0.3, 0.8], constants in the update equation, default=0.4

  • c_e (float): [0.1, 0.9], coriolis effect, default=0.4

  • max_v (float): [0.1, 0.9], maximum allowed speed, default=0.3

Examples

>>> import numpy as np
>>> from mealpy.physics_based.WDO import BaseWDO
>>>
>>> def fitness_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": fitness_function,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": True,
>>> }
>>>
>>> epoch = 1000
>>> pop_size = 50
>>> RT = 3
>>> g_c = 0.2
>>> alp = 0.4
>>> c_e = 0.4
>>> max_v = 0.3
>>> model = BaseWDO(problem_dict1, epoch, pop_size, RT, g_c, alp, c_e, max_v)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Bayraktar, Z., Komurcu, M., Bossard, J.A. and Werner, D.H., 2013. The wind driven optimization technique and its application in electromagnetics. IEEE transactions on antennas and propagation, 61(5), pp.2745-2757.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration