optimEA | R Documentation |
A basic implementation of a simple Evolutionary Algorithm for Combinatorial Optimization. Default evolutionary operators aim at permutation optimization problems.
optimEA(x = NULL, fun, control = list())
x |
Optional start individual(s) as a list. If NULL (default), |
fun |
target function to be minimized |
control |
(list), with the options:
|
a list:
xbest
best solution found.
ybest
fitness of the best solution.
x
history of all evaluated solutions.
y
corresponding target function values f(x).
count
number of performed target function evaluations.
message
Termination message: Which stopping criterion was reached.
population
Last population.
fitness
Fitness of last population.
optimCEGO
, optimRS
, optim2Opt
, optimMaxMinDist
#First example: permutation optimization
seed=0
#distance
dF <- distancePermutationHamming
#mutation
mF <- mutationPermutationSwap
#recombination
rF <- recombinationPermutationCycleCrossover
#creation
cF <- function()sample(5)
#objective function
lF <- landscapeGeneratorUNI(1:5,dF)
#start optimization
set.seed(seed)
res <- optimEA(,lF,list(creationFunction=cF,mutationFunction=mF,recombinationFunction=rF,
popsize=6,budget=60,targetY=0,verbosity=1,
vectorized=TRUE)) ##target function is "vectorized", expects list as input
res$xbest
#Second example: binary string optimization
#number of bits
N <- 50
#target function (simple example)
f <- function(x){
sum(x)
}
#function to create random Individuals
cf <- function(){
sample(c(FALSE,TRUE),N,replace=TRUE)
}
#control list
cntrl <- list(
budget = 100,
popsize = 5,
creationFunction = cf,
vectorized = FALSE, #set to TRUE if f evaluates a list of individuals
recombinationFunction = recombinationBinary2Point,
recombinationRate = 0.1,
mutationFunction = mutationBinaryBitFlip,
parameters=list(mutationRate = 1/N),
archive=FALSE #recommended for larger budgets. do not change.
)
#start algorithm
set.seed(1)
res <- optimEA(fun=f,control=cntrl)
res$xbest
res$ybest
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.