Gradient-based algorithms, such as Gradient descent, Back propagation, Conjugate gradient and Adaptive Moment Estimation (ADAM), despite the popularity present problems like the sensitivity to the choice of the initial point and step size, the ease of getting stuck in local optima, and the need of differentiable objective functions.
In last decade, the interest on metaheuristic nature inspired algorithms has been growing steadily, due to their flexibility and effectiveness. EvoMiP is a package for Python (based on EmiR, a popular R package from the same authors) which implements several methauristic algorithms for optimization problems:
- Artificial Bee Colony Algorithm
- Bat Algorithm
- Cuckoo Search
- Genetic Algorithm
- Gravitationl Search Algorithm
- Grey Wolf Optimization
- Harmony Search
- Improved Harmony Search
- Moth-flame Optimization
- Particle Swarm Optimization
- Simulated Annealing
- Whale Optimization Algorithm
Unlike other available tools, EvoMiP can be used not only for unconstrained problems, but also for problems subjected to inequality constraints and for integer or mixed-integer problems.
pip3 install git+https://github.com/dr4kan/EvoMiP.git#egg=evomip
The function is defined and evaluated in
The function has a global minimum:
from evomip.Config import Config
from evomip.Parameter import *
from evomip.SearchSpace import SearchSpace
from evomip.Population import Population
from evomip.BAT import BAT
import numpy as np
# definition of the objective function
def miele_cantrell(x: np.array):
x1 = x[0]
x2 = x[1]
x3 = x[2]
x4 = x[3]
return (np.exp(-x1) - x2)**4 + 100*(x2 - x3)**6 + (np.tan(x3 - x4))**4 + x1**8
# configuration of the optimization parameters
config = Config(nmax_iter=100)
# definition of the search space
l = createListParameters("x", 4, -2., 2.)
sspace = SearchSpace(l)
# defition of the population
population = Population(100, miele_cantrell, sspace, config)
# running the algorithm
algo = BAT(population)
algo.minimize()
# summary of the results
algo.summary()
The following objective function is minimized in the range
from evomip.Config import Config
from evomip.Parameter import *
from evomip.SearchSpace import SearchSpace
from evomip.Population import Population
from evomip.Functions import sphere
from evomip.WOA import WOA
import numpy as np
# definition of the objective function
def obFunc(x: np.array):
x1 = x[0]
x2 = x[1]
x3 = x[2]
x4 = x[3]
x5 = x[4]
x6 = x[5]
x7 = x[6]
x8 = x[7]
x9 = x[8]
x10 = x[9]
y = x1**2 + x1*x2 - x2**2 + x3*x1 - x3**2 + 8*(x4**2) - 17*(x5**2) + 6*(x6**3) + x6*x5*x4*x7 + x8**3 + x9**4 - x10**5 - x10*x5 + 18*x3*x7*x6
return -y
# configuration of the optimization parameters
config = Config(nmax_iter=500)
# definition of the search space
l = createListParameters("x", 10, 0, 99, True)
sspace = SearchSpace(l)
# defition of the population
population = Population(200, obFunc, sspace, config)
# running the algorithm
algo = WOA(population)
algo.minimize()
# summary of the results
algo.summary()
This is a well know benchmark problem:
subject to:
where:
The search space is:
Best solution from Lee and Geem, Comput. Methods Appl. Mech. Eng. 2005, 194(36–38): 7197.730
import numpy as np
from evomip.Constraint import Constraint
from evomip.Parameter import Parameter
from evomip.SearchSpace import SearchSpace
from evomip.Population import Population
from evomip.Config import Config
from evomip.WOA import WOA
def ob(x: np.array):
return 0.6224 * (x[0]*0.0625) * x[2] * x[3] + 1.7781 * (x[1]*0.0625) * x[2]**2 + 3.1611 * (x[0]*0.0625)**2 * x[3] + 19.8621 * (x[0]*0.0625)**2 * x[2]
def g1(x: np.array):
return 0.0193*x[2] - (x[0]*0.0625)
def g2(x: np.array):
return 0.00954*x[2] - (x[1]*0.0625)
def g3(x: np.array):
return 1296000 - np.pi * x[2]**2 * x[3] - 4/3 * np.pi * x[2]**3
c1 = Constraint(g1, "<=")
c2 = Constraint(g2, "<=")
c3 = Constraint(g3, "<=")
p1 = Parameter("x1*", 18, 32, True)
p2 = Parameter("x2*", 10, 32, True)
p3 = Parameter("x3", 10, 240)
p4 = Parameter("x4", 10, 240)
config = Config(nmax_iter=3000, nmax_iter_same_cost=0, seed=110, oobMethod="RBC",
constraintsMethod="BAR", min_valid_solutions = 50)
sspace = SearchSpace([p1,p2,p3,p4], [c1,c2,c3])
population = Population(500, ob, sspace, config)
algo = WOA(population)
algo.minimize()
algo.summary()