A main funtion to compute the optimal solution using a selected algorithm.

```
metaOpt(FUN, optimType = "MIN", algorithm = "PSO", numVar, rangeVar,
control = list(), seed = NULL)
```

FUN

an objective function or cost function,

optimType

a string value that represents the type of optimization.
There are two options for this arguments: `"MIN"`

and `"MAX"`

.
The default value is `"MIN"`

, referring the minimization problem.
Otherwise, you can use `"MAX"`

for maximization problem.

algorithm

a vector or single string value that represent the algorithm used to do optimization. There are currently twenty one implemented algorithm:

`"PSO"`

: Particle Swarm Optimization. See`PSO`

;`"ALO"`

: Ant Lion Optimizer. See`ALO`

;`"GWO"`

: Grey Wolf Optimizer. See`GWO`

`"DA"`

: Dragonfly Algorithm. See`DA`

`"FFA"`

: Firefly Algorithm. See`FFA`

`"GA"`

: Genetic Algorithm. See`GA`

`"GOA"`

: Grasshopper Optimisation Algorithm. See`GOA`

`"HS"`

: Harmony Search Algorithm. See`HS`

`"MFO"`

: Moth Flame Optimizer. See`MFO`

`"SCA"`

: Sine Cosine Algorithm. See`SCA`

`"WOA"`

: Whale Optimization Algorithm. See`WOA`

`"CLONALG"`

: Clonal Selection Algorithm. See`CLONALG`

`"DE"`

: Differential Evolution Algorithm. See`DE`

`"SFL"`

: Shuffled Frog Leaping Algorithm. See`SFL`

`"CSO"`

: Cat Swarm Optimization Algorithm. See`CSO`

`"ABC"`

: Artificial Bee Colony Algorithm. See`ABC`

`"KH"`

: Krill-Herd Algorithm. See`KH`

`"CS"`

: Cuckoo Search Algorithm. See`CS`

`"BA"`

: Bat Algorithm. See`BA`

`"GBS"`

: Gravitation Based Search Algorithm. See`GBS`

`"BHO"`

: Black Hole Based Optimization Algorithm. See`BHO`

numVar

a positive integer to determine the number variables.

rangeVar

a matrix (\(2 \times n\)) containing the range of variables,
where \(n\) is the number of variables, and first and second rows
are the lower bound (minimum) and upper bound (maximum) values, respectively.
If all variable have equal upper bound, you can define `rangeVar`

as
matrix (\(2 \times 1\)).

control

a list containing all arguments, depending on the algorithm to use. The following list are parameters required for each algorithm.

`PSO`

:`list(numPopulation, maxIter, Vmax, ci, cg, w)`

`ALO`

:`list(numPopulation, maxIter)`

`GWO`

:`list(numPopulation, maxIter)`

`DA`

:`list(numPopulation, maxIter)`

`FFA`

:`list(numPopulation, maxIter, B0, gamma, alphaFFA)`

`GA`

:`list(numPopulation, maxIter, Pm, Pc)`

`GOA`

:`list(numPopulation, maxIter)`

`HS`

:`list(numPopulation, maxIter, PAR, HMCR, bandwith)`

`MFO`

:`list(numPopulation, maxIter)`

`SCA`

:`list(numPopulation, maxIter)`

`WOA`

:`list(numPopulation, maxIter)`

`CLONALG`

:`list(numPopulation, maxIter, selectionSize, multipicationFactor, hypermutationRate)`

`DE`

:`list(numPopulation, maxIter, scalingVector, crossOverRate, strategy)`

`SFL`

:`list(numPopulation, maxIter, numMemeplex, frogLeapingIteration)`

`CSO`

:`list(numPopulation, maxIter, mixtureRatio, tracingConstant, maximumVelocity, smp, srd, cdc, spc)`

`ABC`

:`list(numPopulation, maxIter, cycleLimit)`

`KH`

:`list(numPopulation, maxIter, maxMotionInduced, inertiaWeightOfMotionInduced, epsilon, foragingSpeed, inertiaWeightOfForagingSpeed, maxDifussionSpeed, constantSpace, mu)`

`CS`

:`list(numPopulation, maxIter, abandonedFraction)`

`BA`

:`list(numPopulation, maxIter, maxFrequency, minFrequency, gama, alphaBA)`

`GBS`

:`list(numPopulation, maxIter, gravitationalConst, kbest)`

`BHO`

:`list(numPopulation, maxIter)`

**Description of the**`control`

Parameters`numPopulation`

: a positive integer to determine the number populations. The default value is 40.`maxIter`

: a positive integer to determine the maximum number of iterations. The default value is 500.`Vmax`

: a positive integer to determine the maximum velocity of particle. The default value is 2.`ci`

: a positive integer to determine the individual cognitive. The default value is 1.49445.`cg`

: a positive integer to determine the group cognitive. The default value is 1.49445.`w`

: a positive integer to determine the inertia weight. The default value is 0.729.`B0`

: a positive integer to determine the attractiveness firefly at r=0. The default value is 1.`gamma`

: a positive integer to determine light absorption coefficient. The default value is 1.`alphaFFA`

: a positive integer to determine randomization parameter. The default value is 0.2.`Pm`

: a positive integer to determine mutation probability. The default value is 0.1.`Pc`

: a positive integer to determine crossover probability. The default value is 0.8.`PAR`

: a positive integer to determine Pinch Adjusting Rate. The default value is 0.3.`HMCR`

: a positive integer to determine Harmony Memory Considering Rate. The default value is 0.95.`bandwith`

: a positive integer to determine distance bandwith. The default value is 0.05.`selectionSize`

: a positive integer between 0 and numVar to determine selection size. The default value is`as.integer(numPopulation/4)`

.`multipicationFactor`

: a positive numeric between 0 and 1 to determine number of clones. The default value is 0.5.`hypermutationRate`

: a positive numeric between 0 and 1 to determine probabilty of variable in clone candidate solutions to be mutated, close to 1 probability is high and vice versa. The default value is 0.1.`scalingVector`

: a positive numeric between 0 and 1 to determine scalingVector for mutation operator. The default value is 0.8.`crossOverRate`

: a positive numeric between 0 and 1 to determine crossOver probability. The default value is 0.5.`strategy`

: characters to determine mutation method. They are six methods to choose:"classical".

"best 1"

"target to best"

"best 2"

"rand 2"

"rand 2 dir"

The default value is "best 1".

`numMemeplex`

: a positive integer (as.integer()) between 0 and numVar to determine number of memeplex (see details).The default value is`as.integer(numPopulation/3)`

.`frogLeapingIteration`

: a positive integer (as.integer()) to determine number of iteration for each memeplex. The default value is`as.integer(10)`

.`mixtureRatio`

: a positive numeric between 0 and 1 to determine flaging proportion. higher mixtureRatio increase number of candidate solutions in seeking mode and vice versa. The default value is 0.5.`tracingConstant`

: a positive numeric between 0 and 1 to determine tracingConstant. The default value is 0.1.`maximumVelocity`

: a positive numeric to determine maximumVelocity while candidate solutions in tracing mode performing local search. The default value is 1.`smp`

: a positive integer to determine number of duplication in genetic operator. The default value is`as.integer(20)`

.`srd`

: a positive numeric between 0 and 100 to determine mutation length in genetic operator. The default value is 20.`cdc`

: a positive integer between 0 and numVar to determine number of variabel in candidate solutions in seeking mode to be mutated during mutation step in genetic operator. The default value is`as.integer(numVar)`

.`spc`

: a logical. if spc is TRUE smp = smp else smp = smp - 1. The default value is TRUE.`cycleLimit`

: a positive integer to determine number of times allowed for candidate solution to not move. The default value is`as.integer(numVar * numPopulation)`

.`maxMotionInduced`

: a positive numeric between 0 and 1 to determine maximum motion induced. The default value is 0.01.`inertiaWeightOfMotionInduced`

: a positive numeric between 0 and 1 to determine how much motion induced affect krill (candidate solution) movement. the greater the value the greater the affect of motion induced on krill movement. The default value is 0.01.`epsilon`

: a positive numeric between 0 and 1 to determine epsilon constant. The default value is 1e-05.`foragingSpeed`

: a positive numeric between 0 and 1 to determine foraging speed. The default value is 0.02`inertiaWeightOfForagingSpeed`

: a positive numeric between 0 and 1 to determine how much foraging speed affect krill (candidate solution) movement. the greater the value the greater the affect of foraging speed on krill movement. The default value is 0.01.`maxDifussionSpeed`

: a positive numeric between 0 and 1 to determine maximum difussion speed. The default value is 0.01.`constantSpace`

: a numeric between 0 and 1 to determine how much range affect krill movement. The default value is 1.`mu`

: a numeric between 0 and 1 to determine constant number for mutation operator. The default value is 0.1.`abandonedFraction`

: a positive numeric between 0 and 1 to determine fraction of population to be replaced. The default value is 0.5.`maxFrequency`

: a numeric to determine maximum frequency. The default value is 0.1.`minFrequency`

: a numeric to determine minimum frequency. The default value is -0.1.`gama`

: a numeric greater than equal to 1. It use to increase pulse rate. The default value is 1.`alphaBA`

: a numeric between 0 and 1. It use to decrease loudness. The default value is 0.1.`gravitationalConst`

: a numeric to determine gravitational constant while calculating total force. The default value is`max(rangeVar)`

.`kbest`

: a positive numeric between 0 and 1 to determine fraction of population with best fitness which will affect every candidate solution in population. The default value is 0.1.

seed

a number to determine the seed for RNG.

`List`

that contain list of variable, optimum value and execution time.

This function makes accessible all algorithm that are implemented in this package. All of the algorithm use this function as interface to find the optimal solution, so users do not need to call other functions. In order to obtain good results, users need to adjust some parameters such as the objective function, optimum type, number variable or dimension, number populations, the maximal number of iterations, lower bound, upper bound, or other algorithm-dependent parameters which are collected in the control parameter.

```
# NOT RUN {
##################################
## Optimizing the sphere function
## Define sphere function as an objective function
sphere <- function(X){
return(sum(X^2))
}
## Define control variable
control <- list(numPopulation=40, maxIter=100, Vmax=2, ci=1.49445, cg=1.49445, w=0.729)
numVar <- 5
rangeVar <- matrix(c(-10,10), nrow=2)
## Define control variable
best.variable <- metaOpt(sphere, optimType="MIN", algorithm="PSO", numVar,
rangeVar, control)
# }
```

Run the code above in your browser using DataCamp Workspace