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, ...)

Arguments

SearchAgents_no

Number of search agents (predators). At least 2. Typical values range from 20 to 50.

Max_iter

Maximum number of iterations. At least 3. Typical values range from 100 to 500 depending on problem complexity.

lb

Lower bounds for each dimension. Can be a single value (applied to all dimensions) or a vector of length dim.

ub

Upper bounds for each dimension. Can be a single value (applied to all dimensions) or a vector of length dim.

dim

Number of dimensions (decision variables) in the optimization problem.

fobj

Objective function to minimize. Must accept a numeric vector of length dim and return a single numeric value.

logFile

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.

Value

An object of class mpa_result, which is a list containing:

Top_predator_fit

Best fitness value found (numeric scalar)

Top_predator_pos

Best position found (numeric vector of length dim)

Convergence_curve

Convergence curve over iterations (numeric vector of length Max_iter)

Details

This is a minimization algorithm. To maximize a function, negate its output (e.g., use function(x) -f(x) instead of f).

Algorithm Phases

The MPA algorithm operates in three distinct phases based on the iteration count:

Phase 1 (iterations 0 to Max_iter/3)

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.

Phase 2 (iterations Max_iter/3 to 2*Max_iter/3)

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.

Phase 3 (iterations 2*Max_iter/3 to Max_iter)

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.

Internal Parameters

The algorithm uses two internal parameters that are not exposed:

FADs

Fish Aggregating Devices effect parameter, set to 0.2. Controls the probability of applying the FADs effect which helps escape local optima.

P

Prey movement probability, set to 0.5. Controls the step size scaling factor during position updates.

Memory Mechanism

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.

Additional Arguments

The ... parameter currently accepts:

prefix

A character string to prefix log messages. Defaults to empty string if not provided.

References

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

See also

[get_function_details()] for benchmark functions, [levy()] for Levy flight implementation, [initialize_population()] for population initialization.

Examples

# 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