Project

generitc algorithm

1.DESCRIPTION

Genetic algorithms are a type of optimization algorithm that is they are used to find optimal solution(s) to a given computational problem that maximizes or minimizes a particular function. Genetic algorithms works ion the principle on the natural biological laws of reproduction and alo evolution laws told by darwin to get the fittest solutions.

As part of natural selection, a given environment has a population of individuals that compete for survival and reproduction. The ability of each individual to achieve these goals determines their chance to have children, in other words to pass on their genes to the next generation of individuals, who for genetic reasons will have an increased chance of doing well, even better, in realizing these two objectives. This principle of continuous improvement over the generations is taken by evolutionary algorithms to optimize solutions to a problem. In the initial generation, a population composed of different individuals is generated randomly or by other methods. An individual is a solution to the problem, more or less good: the quality of the individual in regards to the problem is called fitness, which reflects the adequacy of the solution to the problem to be solved. The higher the fitness of an individual, the higher it is likely to pass some or all of its genotype to the individuals of the next generation.

so the genetic algorithm works by optimizing the fitness function each time and thus modifying the results until we h=get highly optimzed result. but the ga onli=y gives the minimum value of tyhe function but according to the given problem we had to calculate the optimized result bcoz of whic we created another function which is the inverted on of the original. so the minimum of new function will give the maximum value of orginal function

and as the population increases better the rsults will be devloped, her we took the population size as 500.

2.

MAIN BODY

%Optimization of Stalagmite function using ga

%Program to calculate the global maxima of a stalagmite function
clear all
close all
clc

%Defining our search space
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);


options=optimoptions(\'ga\');
options=optimoptions(options,\'PopulationSize\',500);

%creating a 2D mesh
[xx yy]=meshgrid(x,y);

%evaluating the stalagmite function
for i=1:length(xx);
for j=1:length(yy);
input_vector(1)=xx(i,j);
input_vector(2)=yy(i,j);
f(i,j)=stalagmite(input_vector);
end
end

%Plotting
surfc(xx,yy,f)
title(\'Stalagmite function\')
xlabel(\'x values\')
ylabel(\'y values\')
zlabel(\'fitness function values\')
shading interp

% optimization
[inputs,fval]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options)

%Results
fprintf(\'The best function value (maximum value) found was: %g\\n\', fval);
fprintf(\'otimized result x value was: %g\\n\', inputs(1));
fprintf(\'otimized result y value was: %g\\n\', inputs(2));

MY FUNCTION PROGRAM:

%Stalagmite function for calculating the global maxima

function[f]= ga_func(input_vector)

f_1x= (sin(5.1*3.14*input_vector(1)+0.5))^6;
f_1y= (sin(5.1*3.14*input_vector(2)+0.5))^6;

f_2x= exp( -4*log(2)*(input_vector(1)-0.0667)^2/0.64);
f_2y= exp( -4*log(2)*(input_vector(2)-0.0667)^2/0.64);

f= -f_1x*f_1y*f_2x*f_2y;

end

PLOT

\"PLOT\"

RESULT

fval =

-1.0000

The best function value (maximum value) found was: -1
otimized result x is .066866
otimized result y is .0668653

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.