Performs machine coded genetic algorithms on a function subject to be minimized.

Share:

Description

Machine coded genetic algorithm (MCGA) is a fast tool for real-valued optimization problems. It uses the byte representation of variables rather than real-values. It performs the classical crossover operations (uniform) on these byte representations. Mutation operator is also similar to classical mutation operator, which is to say, it changes a randomly selected byte value of a chromosome by +1 or -1 with probability 1/2. In MCGAs there is no need for encoding-decoding process and the classical operators are directly applicable on real-values. It is fast and can handle a wide range of a search space with high precision. Using a 256-unary alphabet is the main disadvantage of this algorithm but a moderate size population is convenient for many problems.

Usage

1
2
mcga(popsize, chsize, crossprob = 1.0, mutateprob = 0.01, 
	 elitism = 1, minval, maxval, maxiter = 10, evalFunc)

Arguments

popsize

Number of chromosomes.

chsize

Number of parameters.

crossprob

Crossover probability. By default it is 1.0

mutateprob

Mutation probability. By default it is 0.01

elitism

Number of best chromosomes to be copied directly into next generation. By default it is 1

minval

The lower bound of the randomized initial population. This is not a constraint for parameters.

maxval

The upper bound of the randomized initial population. This is not a constraint for parameters.

maxiter

The maximum number of generations. By default it is 10

evalFunc

An R function. By default, each problem is a minimization.

Value

population

Sorted population resulted after generations

costs

Cost values for each chromosomes in the resulted population

Author(s)

Mehmet Hakan Satman - mhsatman@istanbul.edu.tr

References

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# A sample optimization problem
# Min f(xi) = (x1-7)^2 + (x2-77)^2 + (x3-777)^2 + (x4-7777)^2 + (x5-77777)^2
# The range of xi is unknown. The solution is
# x1 = 7
# x2 = 77
# x3 = 777
# x4 = 7777
# x5 = 77777
# Min f(xi) = 0
require("mcga")
 f<-function(x){
    return ((x[1]-7)^2 + (x[2]-77)^2 +(x[3]-777)^2 +(x[4]-7777)^2 +(x[5]-77777)^2)
 }
 m <- mcga(	popsize=200, 
			chsize=5, 
			minval=0.0, 
			maxval=999999999.9, 
			maxiter=2500, 
			crossprob=1.0, 
			mutateprob=0.01, 
			evalFunc=f)
			
 cat("Best chromosome:\n")
 print(m$population[1,])
 cat("Cost: ",m$costs[1],"\n")

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.