Genetic Algorithms (GAs) are most famous Evolutionary Algorithms (EAs) which are inspired from natural evolution and selection. Their main application is in the field of optimization. Hence they are applicable to any kind of problem, which can be converted or stated as an optimization task. To read more about Genetic Algorithms, you can see the related article in Wikipedia (here).
In this post we are going to share with you, the MATLAB implementation of two versions of Genetic Algorithms: the Binary Genetic Algorithm and Real-Coded Genetic Algorithm. The mechanism of optimization is identical in these versions and they are different only in the sense of solution representation and genetic operators. The algorithms are implemented in a structured manner and if you are familiar with MATLAB programming language, you will find it easy, to use the codes in your research projects.
The download link of this project follows.
Implementation of Binary and Real-Coded Genetic Algorithms in MATLABDownload
Citing This Work
If you wish, you can cite this content as follows.
Cite as:Mostapha Kalami Heris, Binary and Real-Coded Genetic Algorithms in MATLAB (URL: https://yarpiz.com/23/ypea101-genetic-algorithms), Yarpiz, 2015.
i am new in this field.
can you please clear out few doubts..it will be a great help for me.
1. what is @(x) in the first line when cost function is calculated?
2. what is the meaning of decision variables. my cost function is to minimize sum of xi*yi. where x and y are 2 arrays.what should be the number of decision variables then in my case if it depends on cost function.
3.what is position? what does it indicate?
by studying it more.. i am now clear about position and decision variables. now i have only one doubt what is @(x) in cost function in first line of code.
Answers of your questions, follow:
1) Consider the code: CostFunction = @(x) Sphere(x);
This indicates that, CostFunction is a function of x, which returns Sphere(x) as result. This notation is a function_handle and Anonymous Function notation in MATLAB. This way of declaration of Cost Function, enables us to connect any form of objective function, to the implementation of metaheuristics. All of implementations shared via Yarpiz, are using the same method.
2) Decision variables are unknown variables of the optimization problem, finding the optimum values of which is the main goal of solving an optimization problem. For example in your cost function of the form sum of xi*yi, all xi’s and yi’s, are decision variables. However, you should augment them into a unique vector or matrix, to have a single piece of unknown variables matrix.
3) Position indicates the position of a candidate solution (e.g. a chromosome in Genetic Algorithm or a particle in PSO), in the search space, where the optimization problem is defined. In other words, the Position Vector (or in general Position Matrix), contains the values of Unknown or Decision Variables, suggested by any particular solution.
Very clean and clear code, Thanks for sharing.