Project

GENETIC ALGORITHM

GENETIC ALGORITHM

Genetic Algorithm are intelligent search techniques maintaining a population of candidate solutions for a given problem and search the solution space by applying variation operator. They refer to a family of computational models inspired by darwin\'s theory of biological evolution. This idea of natural selection on organizing principle for optimizing individuals and population of individuals. GAs mimic natural selection to optimize successfully, problem are solved by an evolutionary process resulting in a best(fittest)solution(survivor).

GENETIC ALGORITHM - An Approach to solve global optimization problem

[Start] Generate random population of n chromosomes (suitable solutions for the problem)

[Fitness] Evaluate the fitness f(x) of each chromosome x in the population

[New population] Create a new population by repeating following steps until the new population iscomplete

[Selection] Select two parent chromosomes from a population according to their fitness (the better fitness,the bigger chance to be selected)

[Crossover] With a crossover probability cross over the parents to form a new offspring (children). If no crossover was performed, offspring is an exact copy of parents.

[Mutation]With a mutation probability mutate new offspring at each locus (position in chromosome).

[Accepting] Place new offspring in a new population

[Replace] Use new generated population for a further run of algorithm

[Test] If the end condition (for example number of populations or improvement of the best solution) issatisfied, stop, and return the best solution in current population

[Loop] Go to step 2

Optimization is the science of finding decisions that satisfy given constraints, and meet a specific goal at its optimalvalue. In engineering, constraints may arise from physical limitations and technical specifications. The objective of global optimization is to find the \"best possible\" solution in nonlinear decision models that frequently have a number of sub-optimal (local) solutions. In the absence of global optimization tools, engineers and
researchers are often forced to settle for feasible solutions, often neglecting the optimum values.The classical optimization techniques have difficulties in dealing with global optimization problems. One of the main reasons of their failure is that they can easily be entrapped in local minima. Moreover, these techniques cannot generate or even use the global information needed to find the global minimum for a function with multiple local minima.The genetic algorithm solves optimization problems by mimicking the principles of biological evolution, repeatedly modifying a population of individual points using rules modeled on gene combinations in biological reproduction.Due to its random nature, the genetic algorithm improves the chances of finding a global solution. Thus they prove to be very efficient and stable in searching for global optimum solutions.

GA SYNTAX USED IN THE PROGRAM

x = ga(fun,nvars,A,b)

finds a local minimum x to fun, subject to the linear inequalities A*x ≤ b. ga evaluates the matrix product A*x as if x is transposed (A*x\')

x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon)

subjects the minimization to the constraints defined in nonlcon. The function nonlcon accepts x and returns vectors C and Ceq, representing the nonlinear inequalities and equalities respectively. ga minimizes the fun such that C(x) ≤ 0 and Ceq(x) = 0. (Set lb=[] and ub=[] if no bounds exist.)

x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options)

minimizes with the default optimization parameters replaced by values in options. (Set nonlcon=[] if no nonlinear constraints exist.) Create options using optimoptions.

Fnction for stalagmite

function[f]=stalagmite(input_vector);

x=input_vector(1);
y=input_vector(2);

f1=[sin(5.1*pi*x+0.5)]^6;
f2=[sin(5.1*pi*y+0.5)]^6;
f3=exp(-4*log(2)*(((x-0.0667)^2)/(0.64)));
f4=exp(-4*log(2)*(((y-0.0667)^2)/(0.64)));

f=-(f1.*f2.*f3.*f4);

end

Function for get_stalagmite

function f =get_stalagmite(x,y)

[XX,YY]=meshgrid(x,y);

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
end 

Main Code

clear all 
close all 
clc

x=linspace(0,0.6,150);
y=linspace(0,0.6,150);

f=get_stalagmite(x,y);

% study 1
num_case=50;
tic 
for i=1:num_case
  [inputs, fopt(i)]=ga(@stalagmite,2);
  xopt(i)=inputs(1);
  yopt(i)=inputs(2);
end

study_time_1=toc;
figure(1)
subplot(2,1,1);
hold on 
surf(x,y,-f);
shading interp
plot3(xopt,yopt,-fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\');
title(\'unbounded inputs\');
subplot(2,1,2);
plot(-fopt)
xlabel(\'iterations\');
ylabel(\'function minimum\');


% study 2  
for i=1:num_case
  [inputs, fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1:1]);
  xopt(i)=inputs(1);
  yopt(i)=inputs(2);
end

study_time_2=toc;
figure(2)
subplot(2,1,1);
hold on 
surf(x,y,-f);
shading interp
plot3(xopt,yopt,-fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\');
title(\'bounded inputs\');
subplot(2,1,2);
plot(-fopt)
xlabel(\'iterations\');
ylabel(\'function minimum\');

% study 3 
tic
options=optimoptions(\'ga\');
options=optimoptions(options,\'populationsize\',270);
for i=1:num_case
  [inputs, fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1:1],[],[],options);
  xopt(i)=inputs(1);
  yopt(i)=inputs(2);
end

study_time_3=toc;
figure(3)
subplot(2,1,1);
hold on 
surf(x,y,-f);
shading interp
plot3(xopt,yopt,-fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\');
title(\'bounded inputs with populationsize\');
subplot(2,1,2);
plot(-fopt)
xlabel(\'iterations\');
ylabel(\'function minimum\');

Figure(1)

The optimization solution for unbounded inputs

Figure(2)

The optimization solution for bounded inputs

Figure(3)

The optimization solution for bounded inputs with population size

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.