Challenge

Week 4.1 - Genetic Algorithm

STALEGMITE FUNCTION.

A stalagmite function generally refers to the function with which we are generating values over a stalagmite kind of surface for finding out the local and global maxima and minima of that particular given function. For this in Matlab we are using a method called 'Optimization'.

          fig-stalegmite function graph.

Programm for stalegmite function optimization.

clear all 
close all
clc

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

%creating a 2Dimensional mesh
[xx yy]=meshgrid(x,y);
num_cases=50;% No of times the iteration will run.

%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 
surfc(x,y,f);
shading interp

[x,fval]=ga(@stalagmite,2);


For obtaining global maxima we use diff unbounded condition.

                         fig-global maxima

programme for obtaining global maxima

clear all 
close all
clc

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

%creating a 2Dimensional mesh
[xx yy]=meshgrid(x,y);
num_cases=50;% No of times the iteration will run.

%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 


[x,fval]=ga(@stalagmite,2);
maximum=-fval

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

study_time1=toc
figure(1)
subplot(2,1,1)
hold on
surface(x,y,-fval)
shading interp
plot3(xopt,yopt,-fopt,'marker','o','markersize',6,'markerfacecolor','b');
title('unbounded input');
subplot(2,1,2);
plot(-fopt)
xlabel('iterations');
ylabel('function maximum');

Genetic algorithm

The genetic algorithm is a method for solving both constrained and unconstrained optimization problems that is based on natural selection, the process that drives biological evolution. The genetic algorithm repeatedly modifies a population of individual solutions. At each step, the genetic algorithm selects individuals from the current population to be parents and uses them to produce the children for the next generation. Over successive generations, the population "evolves" toward an optimal solution. You can apply the genetic algorithm to solve a variety of optimization problems that are not well suited for standard optimization algorithms, including problems in which the objective function is discontinuous, nondifferentiable, stochastic, or highly nonlinear. The genetic algorithm can address problems of mixed integer programming, where some components are restricted to be integer-valued

  • ga.  The state structure for ga, which is an input argument to plot, mutation, and output functions, contains the following fields:
    • Generation — Current generation number.

    • StartTime — Time when genetic algorithm started, returned by TIC

    • StopFlag — Reason for stopping, a character vector.

    • LastImprovement — Generation at which the last improvement in fitness value occurred.

    • LastImprovementTime — Time at which last improvement occurred.

    • Best — Vector containing the best score in each generation.

    • how — The 'augLag' nonlinear constraint algorithm reports one of the following actions: 'Infeasible point', 'Update multipliers', or 'Increase penalty'; see 

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.