The Marine Predators Algorithm (MPA) is a nature-inspired metaheuristic optimization algorithm based on the foraging behavior of marine predators and their interactions with prey. It was introduced by Faramarzi et al. (2020) and has shown excellent performance on various optimization benchmarks.
Marine predators use different movement strategies depending on the prey distribution:
The algorithm models these behaviors along with:
MPA operates in three distinct phases based on the iteration count:
In this phase, the prey moves faster than the predator. The algorithm emphasizes exploration using Brownian motion. This helps discover promising regions in the search space.
Prey(t+1) = Prey(t) + P * R * stepsize
where stepsize = RB * (Elite - RB * Prey) and
RB is Brownian random movement.
Predator and prey move at similar speeds. The population is split:
This phase balances exploration and exploitation.
The predator moves faster than the prey. All agents use Levy flight focused around the best solution, emphasizing exploitation to refine the solution.
Prey(t+1) = Elite + P * CF * stepsize
where stepsize = RL * (RL * Elite - Prey) and
RL is Levy random movement.
library(marinepredator)
# Minimize the Sphere function (F01)
result <- mpa(
SearchAgents_no = 30, # Number of search agents
Max_iter = 100, # Maximum iterations
lb = -100, # Lower bound
ub = 100, # Upper bound
dim = 10, # Number of dimensions
fobj = F01 # Objective function
)
print(result)
#> Marine Predators Algorithm Results:
#> -----------------------------------
#> Best fitness: 0.0003795230
#> Best position: 0.0002517377 0.0005075457 0.0119851571 -0.0019771084 0.0113553694 -0.0031794298 0.0018634312 -0.0052026562 -0.006074163 -0.0050160146
#> Convergence curve length: 100The package includes 23 standard benchmark functions:
# Get function details programmatically
details <- get_function_details("F09") # Rastrigin function
# View the details
str(details)
#> List of 4
#> $ lb : num -5.12
#> $ ub : num 5.12
#> $ dim : num 50
#> $ fobj:function (x)# Optimize the Rastrigin function
result_rastrigin <- mpa(
SearchAgents_no = 30,
Max_iter = 200,
lb = details$lb,
ub = details$ub,
dim = 10,
fobj = details$fobj
)
print(result_rastrigin)
#> Marine Predators Algorithm Results:
#> -----------------------------------
#> Best fitness: 2.0504223273
#> Best position: 0.0004571076 -0.0093363826 -0.001081452 -0.0106586072 -0.0038450992 0.0005452777 0.9950854517 -0.0084815633 0.9949250302 -0.0039836964
#> Convergence curve length: 200You can use MPA with any objective function:
# Define a custom function
# Minimum at (1, 2, 3)
custom_fun <- function(x) {
sum((x - c(1, 2, 3))^2)
}
result_custom <- mpa(
SearchAgents_no = 20,
Max_iter = 100,
lb = c(-10, -10, -10),
ub = c(10, 10, 10),
dim = 3,
fobj = custom_fun
)
cat("Best position found:", round(result_custom$Top_predator_pos, 4), "\n")
#> Best position found: 1 2 3
cat("Best fitness:", result_custom$Top_predator_fit, "\n")
#> Best fitness: 3.16712e-10MPA is a minimization algorithm. To maximize a function, negate its output:
# Function to maximize: f(x) = -sum(x^2)
# Maximum is at (0, 0, ..., 0) with value 0
result_max <- mpa(
SearchAgents_no = 20,
Max_iter = 100,
lb = -10, ub = 10,
dim = 5,
fobj = function(x) sum(x^2) # Minimize sum(x^2) = maximize -sum(x^2)
)
cat("Best position:", round(result_max$Top_predator_pos, 6), "\n")
#> Best position: -0.000436 0.000281 0.000283 -0.000306 -0.000759
cat("Maximum value:", -result_max$Top_predator_fit, "\n")
#> Maximum value: -1.018885e-06| Parameter | Description | Typical Values |
|---|---|---|
SearchAgents_no |
Number of search agents | 20-50 |
Max_iter |
Maximum iterations | 100-500 |
dim |
Problem dimensionality | Problem-dependent |
lb, ub |
Search space bounds | Problem-dependent |
# Compare MPA performance on different functions
set.seed(42) # For reproducibility
functions <- c("F01", "F05", "F09", "F10")
results <- list()
for (func_name in functions) {
details <- get_function_details(func_name)
result <- mpa(
SearchAgents_no = 30,
Max_iter = 100,
lb = details$lb,
ub = details$ub,
dim = min(details$dim, 20), # Limit dimensions for speed
fobj = details$fobj
)
results[[func_name]] <- result$Top_predator_fit
}
# Display results
data.frame(
Function = names(results),
Best_Fitness = unlist(results)
)
#> Function Best_Fitness
#> F01 F01 0.1110520
#> F05 F05 22.1944567
#> F09 F09 21.6414587
#> F10 F10 0.2116683You can enable logging to track optimization progress:
Faramarzi, A., Heidarinejad, M., Mirjalili, S., & Gandomi, A. H. (2020). Marine Predators Algorithm: A Nature-inspired Metaheuristic. Expert Systems with Applications, 152, 113377. https://doi.org/10.1016/j.eswa.2020.113377
?mpa - Main function documentation?test-functions - Overview of benchmark functions?levy - Levy flight implementation details