mpa is an R implementation of the Marine Predators Algorithm (MPA), a nature-inspired metaheuristic optimization algorithm. This package provides a complete implementation of the MPA algorithm as described in the original paper by Faramarzi et al. (2020).
Documentation: https://urbs-dev.github.io/marinepredator/
You can install the development version of mpa from GitHub:
# Install remotes if not already installed
if (!require("remotes")) {
install.packages("remotes")
}
# Install marinepredator
remotes::install_github(repo = "urbs-dev/marinepredator")The Marine Predators Algorithm (MPA) is inspired by the foraging behavior of marine predators and their interactions with prey. The algorithm follows these key principles:
-
Lévy and Brownian Movement: Marine predators use Lévy strategy for environments with low prey concentration and Brownian movement for areas with abundant prey.
-
Velocity Ratios: The algorithm considers different velocity ratios between predators and prey:
- High velocity ratio (prey moves faster)
- Unit velocity ratio (similar speeds)
- Low velocity ratio (predator moves faster)
-
Memory: Predators remember successful foraging locations and their associates.
-
Environmental Effects: The algorithm models natural phenomena like eddy formation and FADs (Fish Aggregating Devices).
library(marinepredator)
# Optimize the Sphere function (F01)
result <- mpa(
SearchAgents_no = 25, # Number of search agents
Max_iter = 100, # Maximum iterations
lb = -100, # Lower bound
ub = 100, # Upper bound
dim = 30, # Number of dimensions
fobj = F01 # Objective function
)
# Print results
print(result)The package includes 23 standard benchmark functions:
# Get function details
details <- get_function_details("F01") # Sphere function
# Run optimization
result <- mpa(
SearchAgents_no = 25,
Max_iter = 100,
lb = details$lb,
ub = details$ub,
dim = details$dim,
fobj = details$fobj
)You can use MPA with your own objective functions:
# Define a custom function
custom_function <- function(x) {
return(sum((x - c(1, 2, 3))^2)) # Minimum at (1, 2, 3)
}
# Run optimization
result <- mpa(
SearchAgents_no = 20,
Max_iter = 50,
lb = c(-10, -10, -10),
ub = c(10, 10, 10),
dim = 3,
fobj = custom_function
)mpa(): Main Marine Predators Algorithm implementationprint.mpa_result(): Print method for MPA results
initialize_population(): Initialize the search agent populationlevy(): Generate Lévy flight random stepsget_function_details(): Get details for benchmark functions
F01(): Sphere functionF02(): Sum of absolute values and productsF03(): Sum of squared termsF04(): Maximum absolute valueF05(): Rosenbrock functionF06(): Shifted sphere functionF07(): Quartic function with noiseF08(): Schwefel functionF09(): Rastrigin functionF10(): Ackley functionF11(): Griewank functionF12(): Penalized function 1F13(): Penalized function 2F14(): Shekel's FoxholesF15(): Kowalik functionF16(): Six-Hump Camel BackF17(): Branin functionF18(): Goldstein-Price functionF19(): Hartman 3D functionF20(): Hartman 6D functionF21(): Shekel 5 functionF22(): Shekel 7 functionF23(): Shekel 10 function
See the demo/ directory for complete usage examples:
mpaBenchmark.R: Comprehensive examples of using MPA with benchmark functions
The MPA algorithm has several key parameters:
SearchAgents_no: Number of search agents (predators) in the populationMax_iter: Maximum number of iterationsFADs: Fish Aggregating Devices parameter (default: 0.2)P: Prey movement probability (default: 0.5)
The algorithm's performance can be evaluated using the convergence curve:
# Plot convergence curve
plot(result$Convergence_curve, type = "l", col = "blue", lwd = 2,
main = "MPA Convergence Curve",
xlab = "Iteration", ylab = "Best Fitness")
grid()Faramarzi, A., Heidarinejad, M., Mirjalili, S., & Gandomi, A. H. (2020). Marine Predators Algorithm: A Nature-inspired Metaheuristic. Expert Systems with Applications, 113377. DOI: 10.1016/j.eswa.2020.113377
This package is licensed under the MIT License.
Original MATLAB implementation by Afshin Faramarzi and Seyedali Mirjalili
Note that I have use generative AI to produce the initial translation of the MATLAB code into R. For this, I have used Vibe from Mistral AI (Devstral). In a second phase, I have checked the code manually and produced unit tests. In a third phase, I have use Claude code AI to reinforce documentation, especially for a general presentation of test functions.
For issues, questions, or contributions, please open an issue on the GitHub repository.
If you use this package in your research, please cite the original paper:
@article{faramarzi2020marine,
title={Marine Predators Algorithm: A Nature-inspired Metaheuristic},
author={Faramarzi, Afshin and Heidarinejad, Mohammad and Mirjalili, Seyedali and Gandomi, Amir H},
journal={Expert Systems with Applications},
volume={113377},
year={2020},
publisher={Elsevier}
}