Solving Optimization Problems

Adaptive Restart Hybrid Genetic Algorithm

function Y=population(p,d,LR,UR)
% d = dimensions of the problem
% p = population size
% LR = Lower bound
% UR = Up bound
Y=(UR-LR)*rand(p,d)+LR;

function Y=crossover(X,n)
% X = population
% n = no of pairs of chromosomes crossover
[x y]=size(X);
E=zeros(2*n,y);
for i= 1:n
    r=randi(x,1,2);
    while r(1)==r(2)
        r=randi(x,1,2);
    end
    % Note: r = selec two chromsomes for crossover
    A=X(r(1),:); % chromosome 1 for crossover
    B=X(r(2),:); % chromosome 2 for crossover
    c=1+randi(y-1); % select cut point
    D=A(1,c:y); % reserve
    A(1,c:y)=B(1,c:y);
    B(1,c:y)=D;
    % NOTE: A and B are chromosomes after crossover
    E(2*i-1,:)=A;
    E(2*i,:)=B;
end
Y=E;

function Y=mutation(X,n)
% X = population
% n = no of pairs of chromosomes crossover
[x y]=size(X);
E=zeros(2*n,y);
for i= 1:n
    r=randi(x,1,2);
    while r(1)==r(2)
        r=randi(x,1,2);
    end
    % Note: r = selec two chromsomes for mutation
    A=X(r(1),:); % chromosome 1 for mutation
    B=X(r(2),:); % chromosome 2 for mutation
    
    c=randi(y); % select cut point
    D=A(1,c); % reserve
    A(1,c)=B(1,c);
    B(1,c)=D;
    % NOTE: A and B are chromosomes after crossover
    E(2*i-1,:)=A;
    E(2*i,:)=B;
end
Y=E;

function YY=local_search(X,n,s,LR,UR)
% X = current best solution
% n = no. of chromosomes seleected
%clc
%clear all
%close all
%X=population(1);
%=====================================================
[x y]=size(X);
A=ones(2*y,1)*X;
j=1;

for i=1:y
...
end
% NOTE: A = LOCAL SOLUTION 
%=======================================================
% Randomly select n local solutions
[x1 y1]=size(A);
Y=zeros(n,y1);
for k = 1:n
...
end
[x2 y2]=size(Y);
for i=1:x2
    for j=1:y2
...
end
YY=Y;

function Y = evaluation(X)
% X = population
[x y]=size(X);
d=y; % number of dimensions
C=zeros(1,x);
for j=1:x
    P=X(j,:);
    B=zeros(2,d);
    for i=1:d
        x1=P(1,i);
        B(1,i)=x1^2;
        B(2,i)=cos(2*pi*x1);
    end
    Z=-20*exp(-0.2*sqrt(sum(B(1,:))/d))-exp(sum(B(2,:))/d)+20+exp(1);
    C(1,j)=1/Z; % obbjective function
end
Y=C;

function [YY1 YY2] = selection(P1,B,p,s)
% P1 - population
% B - fitness value 
% p - population size
% s = select top s chromsomes
%-------------------------------------------------------------------------
% Top selection operation
for i =1:s
    [r1 c1]=find(B==max(B));
    Y1(i,:)=P1(max(c1),:);
    Fn(i)=1/B(max(c1));
    P1(max(c1),:)=[];
    B(:,max(c1))=[];
    clear r1 c1
end
% Determine total fitness for the population
C=sum(B);
% Determine selection probability
D=B/C;
% Determine cumulative probability 
E= cumsum(D);
% Generate a vector constaining normalised random numbers
N=rand(1);
d1=1;
d2=s;
while d2 <= p-1
...
...
end
YY1=Y1;
YY2=Fn;
end

clear all
clc
close all
%--------------------------------------------------------------------------
dim = 10; % dimensions of the problem
LR=-15; % Lower bound
UR=30;  % Up bound
%----------------------------------------------------------------
p= 100; % population size
c= 2; % crossover rate
m= 10; % mutation rate
s= 50; % number of generations to restart if getting stuck in local minimum
g= 1; % elite chromosomes
r= 1;% number of initial chromosomes
n= 4; % no of chromosomes RAMDOMLY selected from local (in %)
tg=500; % Total generations
redu=0.1;
%--------------------------------------------------------------------------
P1=population(r,dim,LR,UR); % Initial guess
w=1;
j=1;
K=0;
KK=0;
ww=1;
figure
title('Blue - Minimum         Red - Average');
xlabel('Generation')
ylabel('Objective function value')
hold on
while j <=tg
        P=population(p-r,dim,LR,UR);
        P(p-r+1:p,:)=P1;
        % Extended population
        lp=1;
        t= 15;% initial step size
        while lp==1
...
        end
end
minimum=min(K(:,2))
.
.
.
Sorry! This is only a half of the Matlab code.

Do you want to get the whole Matlab code of my innovative Genetic Algorithm to use in your research, thesis, report, and publications?

It’s possible to watch the video and re-type the Matlab code yourself – that would take you from 1 to 3 hours; or with just €3.99 (the cost of a cup of coffee), you can download/copy the whole Matlab code within 3 minutes. It’s your choice to make.

Original price is €6.99 but today it’s only €3.99 (save €3 today – available for a limited time only)

Download the whole Matlab code here (Membership Code ID: 039)

No need to build the Matlab code from scratch because it’s very time-consuming. My idol, Jim Rohn, once said: “Time is more value than money. You can get more money, but you cannot get more time”. If you think this code can be used in your research/teaching work, you should download it and then customize/modify/apply it to your work, without any obligation of citing the original source if you don’t want. However, redistribution (i.e., downloading the code/script here and then making it available on another site on the Internet) is strictly prohibited.

If you have any question or problem, please contact Dr. Panda by email: learnwithpanda2018@gmail.com

Thank you very much and good luck with your research!

Dr.Panda

Recent Posts

Adaptive Re-Start Hybrid Genetic Algorithm in Matlab

Hello everyone! In this post, I am going to show you my innovative version of…

6 months ago

Test Your Understanding About Genetic Algorithm (Test 2)

Hello everyone. Let’s take a test to check your understanding about genetic algorithm, with multiple…

7 months ago

Adaptive Re-Start Hybrid Genetic Algorithm (Test the Performance in Case Studies)

Hello everyone. In this post, I am going to show you my innovative version of…

1 year ago

Adaptive Re-Start Hybrid Genetic Algorithm in Matlab

Hello everyone! Let’s see how my innovative version of Genetic Algorithm, called Adaptive Re-start Hybrid…

1 year ago

Crypto Quiz (Test Your Knowledge About Cryptocurrency)

Hello everyone! Let’s take a short quiz, to test your knowledge about crypto-currency, or crypto.…

1 year ago

Test Your Crypto Knowledge (Test 2)

Hello everyone! Let’s take a test to check your knowledge in crypto-currency, or crypto. From…

2 years ago