# Basic usage with the Sphere function (F01)
result <- mpa(
SearchAgents_no = 25, Max_iter = 100, lb = -100, ub = 100,
dim = 30, fobj = F01
)
print(result)
# Using different bounds per dimension
result2 <- mpa(
SearchAgents_no = 20, Max_iter = 50,
lb = c(-5, 0), ub = c(10, 15),
dim = 2, fobj = F17
)
# Maximization example (negate the objective function)
maximize_f <- function(x) -sum(x^2)
result3 <- mpa(
SearchAgents_no = 20, Max_iter = 50,
lb = -10, ub = 10, dim = 5,
fobj = function(x) -maximize_f(x)
)
# The actual maximum value is -result3$Top_predator_fit
Run the code above in your browser using DataLab