Artificial Bee Colony
Example:
from bejoor.swarm_based import ArtificialBeeColony
import math
def ackley_function(sol):
n = len(sol)
term1 = -20 * math.exp(-0.2 * math.sqrt(sum(x**2 for x in sol) / n))
term2 = -math.exp(sum(math.cos(2 * math.pi * x) for x in sol) / n)
return term1 + term2 + 20 + math.e
solution_vector = [{"type": "float", "lower_bound": -32.768, "upper_bound": 32.768}] * 7
abc = ArtificialBeeColony(objective_function=ackley_function, solution_vector_size=7,
solution_vector=solution_vector, optimization_side="min",
onlooker_bees=10, employed_bees=10, limit=100, population_size=300, epochs=50)
abc.run()
print(f'Best Global Objective Value: {abc.global_best_objective_value}')
print(f'Best Global Solution: {abc.global_best_solution}')
Parameters:
-
objective_function
: Objective function needs to be optimized.
-
solution_vector_size
: Vector size of the candidate solutions.
-
solution_vector
: A vector which determines the types of each variable in solution vectors.
-
optimization_side
: Determines maximize or minimize the objective function.
-
target_objective_value
: Target Objective value.
-
target_objective_lower_bound
: Target Objective lower bound.
-
target_objective_upper_bound
: Target Objective upper bound.
-
population_size
: Number of individuals in the population.
-
epochs
: Number of generations to run the algorithm.
-
onlooker_bees
: Number of onlooker bees.
-
employed_bees
: Number of employed bees.
-
limit
: Limit for abandonment of a solution.