Week 4.1 - Genetic Algorithm
MAIN PROGRAM
clear allclose allclc% DEFINING OUT SEARCH SPACEx=linspace(0,0.6,150);y=linspace(0,0.6,150);% CREATING A 2DIMENSIONAL MESH[xx, yy]=meshgrid(x,y);% EVALUATING THE STALAGMITE FUNCTIONfor 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); endendsurfc(xx,yy,f)xlabel('x value')ylabel('y value')shading interp[input,fval]=ga(@stalagmite,2);FUNCTION COMMAND FOR STALAGMITE
function [F]= stalagmite (input_vector) fx=(sin(5.1*pi*input_vector(1)+0.5))^6; fy=(sin(5.1*pi*input_vector(2)+0.5))^6; fxx=exp((-4*log(2)*(((input_vector(1)-0.0667)^2)/0.64))); fyy=exp((-4*log(2)*(((input_vector(2)-0.0667)^2)/0.64))); F=-(fx*fy*fxx*fyy);endOUTPUTS
while running the program i never face any major errors....




2).EXPLANATION FOR PROGRAM:
First of all we create the new script to generate genetic algoritham program.now start with clear all,close all ,clc.then defining our search space as X,Y the use the meshgrid command to create a 2dimensional mesh.the evaluating the stalagmite function denotes i,j and give inputs as 1 and 2 f(i,j)=stalagmite command use to function the command as new script the command for use to determine the formula F=(fx*fy*fxx*fyy). i.e fx=(sin(5.1*pi*input_vector(1)+0.5))^6 ,fy=(sin(5.1*pi*input_vector(2)+0.5))^6, fxx=exp((-4*log(2)*(((input_vector(1)-0.0667)^2)/0.64))),
fyy=exp((-4*log(2)*(((input_vector(2)-0.0667)^2)/0.64)));. surfc command as used for companed thn label itas x,y shading interp as use for clear output with any line margins in graph.
3)Theory for genetic algorithm: A genetic algorithm is a method for solving both constrained and unconstrained optimization problems based on a natural selection process that mimics biological evolution.the algorithm repeatedly modifies a population fo individual solution.it generates a population of points at each iteration .the best point in the population approaches an optimal solutions
there are five phases in genetic algorithm.1.Inital population ,2.fitness population,3.selection,4.crossover,5.Mutation
Stopping criteria in genetic algorithm: Stopping criteria refers to conditons that must be reached in order to stop the execution of the algorithm.some of the most common stopping conditons are: Execution time,total number of iterations,non improving iterations,optimal(lower bound for min,upper bound for max)solution found etc
syntax for genetic algorithm:
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,intcon,options)
fun = Objective function
nvar = Number of variables (specified a positive integer)
A,b = Linear inequality constraints(A=Real matrix; b= Real vector)
Aeq,beq= Linear equality constraints (A=Real matrix; b=Real vector)
Lb,ub = lower bounds and upper bounds
nonlcon = Nonlinear constraints
options = Optimization options