mcga2
is the improvement version of the standard mcga function as it is based on the GA::ga
function. The
byte_crossover
and the byte_mutation
operators are the main reproduction operators and these operators uses the byte
representations of parents in the computer memory.
mcga2(fitness, ..., min, max,
population = gaControl("real-valued")$population,
selection = gaControl("real-valued")$selection,
crossover = byte_crossover, mutation = byte_mutation, popSize = 50,
pcrossover = 0.8, pmutation = 0.1, elitism = base::max(1, round(popSize
* 0.05)), maxiter = 100, run = maxiter, maxFitness = Inf,
names = NULL, parallel = FALSE, monitor = gaMonitor, seed = NULL)
Returns an object of class ga-class
The goal function to be maximized
Additional arguments to be passed to the fitness function
Vector of lower bounds of variables
Vector of upper bounds of variables
Initial population. It is gaControl("real-valued")$population
by default.
Selection operator. It is gaControl("real-valued")$selection
by default.
Crossover operator. It is byte_crossover
by default.
Mutation operator. It is byte_mutation
by default. Other values can be given including byte_mutation_random
,
byte_mutation_dynamic
and byte_mutation_random_dynamic
Population size. It is 50 by default
Probability of crossover. It is 0.8 by default
Probability of mutation. It is 0.1 by default
Number of elitist solutions. It is base::max(1, round(popSize*0.05))
by default
Maximum number of generations. It is 100 by default
The genetic search is stopped if the best solution has not any improvements in last run
generations. By default it is maxiter
Upper bound of the fitness function. By default it is Inf
Vector of names of the variables. By default it is NULL
If TRUE, fitness calculations are performed parallel. It is FALSE by default
The monitoring function for printing some information about the current state of the genetic search. It is gaMonitor
by default
The seed for random number generating. It is NULL
by default
Mehmet Hakan Satman - mhsatman@istanbul.edu.tr
M.H.Satman (2013), Machine Coded Genetic Algorithms for Real Parameter Optimization Problems, Gazi University Journal of Science, Vol 26, No 1, pp. 85-95
Luca Scrucca (2013). GA: A Package for Genetic Algorithms in R. Journal of Statistical Software, 53(4), 1-37.
GA::ga
f <- function(x){
return(-sum( (x-5)^2 ) )
}
myga <- mcga2(fitness = f, popSize = 100, maxiter = 300,
min = rep(-50,5), max = rep(50,5))
print(myga@solution)
Run the code above in your browser using DataLab