MEALPY is a Python library for applying population-based, nature-inspired metaheuristic optimization algorithms, including artificial bee colony (ABC). Install it with pip install mealpy. section 10.5
A MEALPY optimization uses a problem dictionary containing the objective function, lower and upper bounds, and minimization or maximization direction. Configure the model, then call solve() to obtain the best position and fitness. section 10.5
Minimizing the Rosenbrock function with ABC
Import OriginalABC from mealpy.swarm_based.ABC, define rosenbrock_function with bounds [-5, -5] and [5, 5], choose 200 epochs, population size 50, and n_limits 15, then call model.solve(problem_dict). One run returns a position near [1, 1] with cost 0.0009197449137428784. section 10.5
from mealpy.swarm_based.ABC import OriginalABC #1
problem_dict = {
"fit_func": rosenbrock_function,
"lb": [-5, -5],
"ub": [5, 5],
"minmax": "min",
} #2
epoch = 200 #3
pop_size = 50 #4
n_limits = 15 #5
model = OriginalABC(epoch, pop_size, n_limits) #6
best_position_mealpy, best_fitness_mealpy = model.solve(problem_dict) #7
print(f"Best solution: {best_position_mealpy}") #8
print(f"Best fitness: {best_fitness_mealpy}") #8
Browse the complete MEALPY ABC setup, including the import, problem definition, parameters, model construction, and solve call. section 10.5
