Implementation of the Marine Predators Algorithm (MPA) in R. MPA is a nature-inspired optimization algorithm that follows the rules governing optimal foraging strategy and encounter rate policy between predator and prey in marine ecosystems.
mpa(SearchAgents_no, Max_iter, lb, ub, dim, fobj, logFile = NULL, ...)Number of search agents (predators). At least 2. Typical values range from 20 to 50.
Maximum number of iterations. At least 3. Typical values range from 100 to 500 depending on problem complexity.
Lower bounds for each dimension. Can be a single value (applied to
all dimensions) or a vector of length dim.
Upper bounds for each dimension. Can be a single value (applied to
all dimensions) or a vector of length dim.
Number of dimensions (decision variables) in the optimization problem.
Objective function to minimize. Must accept a numeric vector of
length dim and return a single numeric value.
A path for logging (text file). Defaulted to NULL. If
NULL, no logging is performed.
Additional arguments. Currently supports prefix for log
message prefixing. See Details.
An object of class mpa_result, which is a list containing:
Best fitness value found (numeric scalar)
Best position found (numeric vector of length dim)
Convergence curve over iterations (numeric vector
of length Max_iter)
This is a minimization algorithm. To maximize a function, negate its
output (e.g., use function(x) -f(x) instead of f).
The MPA algorithm operates in three distinct phases based on the iteration count:
High velocity ratio - The prey moves faster than the predator. Exploration is emphasized using Brownian motion. This phase promotes global search across the solution space.
Unit velocity ratio - Predator and prey move at similar speeds. The population is split: half uses Brownian motion (exploitation), half uses Levy flight (exploration). This balances exploration and exploitation.
Low velocity ratio - The predator moves faster than the prey. Levy flight is used for all agents, focusing on exploitation around the best solution found.
The algorithm uses two internal parameters that are not exposed:
Fish Aggregating Devices effect parameter, set to 0.2. Controls the probability of applying the FADs effect which helps escape local optima.
Prey movement probability, set to 0.5. Controls the step size scaling factor during position updates.
MPA implements a memory mechanism (Marine Memory) that preserves the best positions found by each agent. If a new position has worse fitness than the previous one, the agent reverts to its previous position.
The ... parameter currently accepts:
A character string to prefix log messages. Defaults to empty string if not provided.
Faramarzi, A., Heidarinejad, M., Mirjalili, S., & Gandomi, A. H. (2020). Marine Predators Algorithm: A Nature-inspired Metaheuristic. Expert Systems with Applications, 152, 113377. doi:10.1016/j.eswa.2020.113377
[get_function_details()] for benchmark functions, [levy()] for Levy flight implementation, [initialize_population()] for population initialization.
# 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)
#> Marine Predators Algorithm Results:
#> -----------------------------------
#> Best fitness: 0.2301869890
#> Best position: -0.0160375455 0.1606419132 0.1434972645 0.0910379504 -0.0423537585 -0.0844940033 0.0370982321 -0.0259333066 -0.1194991444 0.0110509361 -0.0211918708 0.0193022294 0.022896384 -0.0409937494 -0.0867890479 -0.1051691656 0.2047037507 -0.0974069031 -0.0188751024 -0.0655885235 0.0347074416 0.0531497413 0.0349469068 0.0255863961 0.0377379579 -0.0858375501 0.0519965178 -0.2068023853 0.0814466144 -0.0734116615
#> Convergence curve length: 100
# 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