0% found this document useful (0 votes)
2 views

MATLAB Program for De

The document outlines a MATLAB program for implementing the Differential Evolution (DE) optimization technique to find the minimum value of the function f(x)=(x-1)² within the constraints of 0 ≤ x ≤ 5. It details the steps involved, including parameter initialization, mutation, crossover, and selection processes to determine the best solution. The program aims to optimize the function by iterating through a population of candidate solutions and selecting the one with the lowest fitness value.

Uploaded by

mohammedmziny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

MATLAB Program for De

The document outlines a MATLAB program for implementing the Differential Evolution (DE) optimization technique to find the minimum value of the function f(x)=(x-1)² within the constraints of 0 ≤ x ≤ 5. It details the steps involved, including parameter initialization, mutation, crossover, and selection processes to determine the best solution. The program aims to optimize the function by iterating through a population of candidate solutions and selecting the one with the lowest fitness value.

Uploaded by

mohammedmziny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

• MATLAB program for Implementing Differential

Evolution (DE) optimizing Technique


• Goal: find minimum value to the function f(x)=(x-1)2

constraint: 0 ≤ x ≤ 5
• Steps:
1-initialize parameters
• 2-Mutation to get donor=x1+F(x2-x3)
3-Crossover to get trial vector
4- make sure that 0 ≤ trial values ≤ 5
5-Selection between trial and parent
6- find the best solution that gives the best minimum value

Prof. Ali Awad 1


• %Parameters initialization
• clc;
• Clear;;
• close all;
• format short
• lb=0 ;
• ub=20;
• best_value=100000000;
• Number_decison_var=1;
• Np=5; %population size (increase Np muh better than

increasing number of trial )


• T = 1; %Number of trial
• pc=0.8; %Probability of cross over
• F=0.5; %scaling factot
• best_fit=[]; % to store the fitness function for each population
member
• D=Number_decison_var; % derermine the number of decision variables in the
fitness function
Prof. Ali Awad 2
• p=repmat(lb,Np,1)+repmat((ub-lb),Np,1).*rand(Np,D) ;
• p = 1.7495
• 3.3613
• 1.6608
• 0.8823
• 3.6713

% generate Np population its values between lb


and up
• %repmat(A,1,2) generate matrix or vector A in
one row and two columns

Prof. Ali Awad 3


• %MUTATION to Generate Donor vector
• for i=1:Np
• parent=p(i,:); parent =1.7495
• sel_sols=p;
sel_sols(i,:)=[];
% sel_sols= 3.3613
• 1.6608
• 0.8823
• 3.6713
• remove the current member (parent) from the population size
• [n1 n2]=size(sel_sols) n1=4 n2=1

Prof. Ali Awad 4


P=[1.7495 3.36 1.6608 0.882 3.6713]

sel_sols =[3.36 1.6608 0.882 3.6713]

%selection of three random solutions

• ind=(randperm(n1,3)) ; 1 4 3

• x1=sel_sols(ind(1),:) ; 3.3613 selecting solution 1 randomly

• x2=sel_sols(ind(2),:) ; 3.6713 selecting solution 2 randomly

• x3=sel_sols(ind(3),:) ; 0.8823 selecting solution 3 randomly



• donor=x1+F*(x2-x3) ; 3.5163 %Generating the donor vector
Prof. Ali Awad 5
• %CROSSOVR to generate trial vector
• delta=randperm(D,1); delta=1 % generate integer number between 1 t0 D
randomly
• for j=1:D j=1


• if (rand <= pc) | (j==delta) rand=0.6088 pc=0.8
• trial(j)=donor(j); % if above condition satisfied put
• trial(1)=donor(1)for j=1 as an example
• else
• trial(j)=parent(j) ; % if above condition not satisfied put
trial(1)=parent(1)for j=1 as an example
• end
• end

• trial =3.5163
• Note: donor=x1+F*(x2-x3) ; 3.5163
Prof. Ali Awad 6
• %Make sure the values of the trial vector are between
ub and lb

• trial=min(ub,trial); trial=3.5163 %comparison berween


ub=20 and each component in trial variable select min

• trial=max(lb,trial); trial=3.5163 %comparison berween


lb=0 and each component in trial variable select max


Prof. Ali Awad 7


• %% Selection Process to replace parent vector by trial vector in the population
list if its fitness value is greater.

• fitness_trial=sum( (trial-1).^2 ) ; 6.3315


• %fitness fumction=(x-1)^2 for trial vector

• fitness_parent=sum( (parent-1).^2 ); 0.5618 %fitness fumction=(x-1)^2 for


parent vector

• if fitness_trial< fitness_parent
• %comparison between fitness value of trial and parent put the least one as best
fit
• p(i,:)= trial;
• best_fit(i) = fitness_trial; 0.5618
• else
• p(i,:)= parent; p(1,1)= 0.5618
• best_fit(i)= fitness_parent;

• end

• end % for i
Prof. Ali Awad 8
• %select the minimum fitness value and its
corresponding solution(best solution) from the
population list

• [min_value,ind]=min(best_fit);

• best_sol=p(ind,:);

• best_value
• best_sol

Prof. Ali Awad 9

You might also like