Home > other >  ALO algorithm matlab language
ALO algorithm matlab language

Time:09-29

Clear all
CLC
% % % % % % % % % % %
SearchAgents_no=200; Set % number
Ts1=3.0448 [1]; % Ts1 low-pass filter initial parameters
Ts2=[13.94501]; % Ts2 low-pass filter initial parameters
Usc=48 * 6; % ultracapacitors monomer number
Rsc=7 * 6.3 e-3. % of the super capacitor resistance
/48 F=165/(Usc); % of the super capacitor capacity
Ahbat=30; % battery capacity


Max_iteration=50;
% intelligent optimization algorithm
Lb=,10,300,40 [1]; %
upper and lower bounds of the optimization parametersUb=,15,500,60 [5]; % to optimize parameters of lower
Dim=4; % optimization parameter number
Fobj=@ costfunction
[Best_score, Best_pos, cg_curve]=ALO (SearchAgents_no Max_iteration, lb, ub, dim, fobj)

Figure (' Position '[269, 240, 660, 290])

Semilogy (WOA_cg_curve, 'Color', 'r')
The title (' Objective space ')
Xlabel (' Iteration);
Ylabel (' Best score obtained so far ');
The plot (WOA_cg_curve, 'our LineWidth, 2,' Color ', 'r')
The title (' Objective space ')
Xlabel (' Iteration);
Ylabel (' Best score obtained so far ');

The axis tight
The grid on
Box on
The function [Elite_antlion_fitness, Elite_antlion_position Convergence_curve]=ALO (SearchAgents_no Max_iter, lb, ub, dim, fobj)

% the Initialize the positions of antlions and ants
Antlion_position=initialization (SearchAgents_no, dim, ub, lb).
Ant_position=initialization (SearchAgents_no, dim, ub, lb).

% the Initialize variables to save the position of elite, sorted antlions,
% as convergence curve, antlions fitness, and ants fitness
Sorted_antlions=zeros (SearchAgents_no, dim);
Elite_antlion_position=zeros (1, dim);
Elite_antlion_fitness=inf;
Convergence_curve=zeros (1, Max_iter);
Antlions_fitness=zeros (1, SearchAgents_no);
Ants_fitness=zeros (1, SearchAgents_no);

% Calculate the fitness of initial antlions and sort them
For I=1: size (antlion_position, 1)
Antlions_fitness (1, I)=fobj (antlion_position (I, :));
End

[sorted_antlion_fitness, sorted_indexes]=sort (antlions_fitness);

For newindex=1: SearchAgents_no
Sorted_antlions (newindex, :)=antlion_position (sorted_indexes (newindex), :);
End

Elite_antlion_position=Sorted_antlions (1, :);
Elite_antlion_fitness=sorted_antlion_fitness (1);

% the Main loop start from the second iteration since the first iteration
% was dedicated to calculating the fitness of antlions
Current_iter=2;
While Current_iter & lt; Max_iter + 1

% This for loop simulate the random walks
For I=1: size (ant_position, 1)
% the Select ant lions -based on their fitness (the better anlion the who chance of catching the ant)
Rolette_index=RouletteWheelSelection (1/sorted_antlion_fitness);
If Rolette_index==1
Rolette_index=1;
End

% RA is the random walk around the selected antlion by rolette wheel
RA=Random_walk_around_antlion (dim, Max_iter, lb, ub, Sorted_antlions (Current_iter Rolette_index, :));

% RA is the random walk around the elite (best antlion so far)
[RE]=Random_walk_around_antlion (dim, Max_iter, lb, ub, Elite_antlion_position (1, :), Current_iter);

Ant_position (I)=(RA (Current_iter, :) + RE (Current_iter, :))/2; % Equation (2.13) in the paper
End

For I=1: size (ant_position, 1)

% Boundar checking (" bringing back the antlions of ants inside the search
% space if they go beyoud the boundaries
Flag4ub=ant_position (I, :) & gt; Ub;
Flag4lb=ant_position (I, :) & lt; Lb.
Ant_position (I, :)=(ant_position (I, :). * (~ (Flag4ub + Flag4lb))) + ub. * Flag4ub + lb. * Flag4lb;

Ants_fitness (1, I)=fobj (ant_position (I, :));
All_fitness (1, I)=ants_fitness (1, I);

End

% the Update antlion positions and fitnesses -based of the ants (if an ant
% becomes fitter than an antlion we assume it was cought by the antlion
% and the antlion update goes to its position to build the trap)
Double_population=[Sorted_antlions; ant_position];
Double_fitness=[sorted_antlion_fitness ants_fitness];

[I] double_fitness_sorted=sort (double_fitness);
Double_sorted_population=double_population (I);

Antlions_fitness=double_fitness_sorted (1: SearchAgents_no);
Sorted_antlions=double_sorted_population (1: SearchAgents_no, :);
% Calculate objective function for each search agent
A1=0.5; % cell injury were weighted
A2=0.2; % grid fluctuations were weighted
A3=0.3; % economy were weighted
X=ant_position (I);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
Rsc=(X (3)/48) * 6 e - 3;
% calculation ultracapacitors resistanceRbat=0.4/(X (4)/10); % calculation battery resistance
Ts1=X (1);
Ts2=X (2);
F=165/(X (3)/48);
Usc=X (3);
Ahbat=X (4);
% % % % % % % % % % % % % % % % set model parameter % % % % % % % % % % % % % % % % % % % %
NomQ set_param (' energy_soure_designV2/Battery1 ', ' ', num2str (Ahbat))
Set_param (' energy_soure_designV2/Battery1 ', 'R', num2str (Rbat))

UpperLimit set_param (' energy_soure_designV2/Saturation1 ', ' ', num2str (Ahbat * 560))
LowerLimit set_param (' energy_soure_designV2/Saturation1 ', ' ', num2str (560) - Ahbat *)
Set_param (' energy_soure_designV2/Constant ', 'Value', num2str (Usc) * 0.85)

Set_param (' energy_soure_designV2/Supercapacitor1 'and' Voltage ', num2str (Usc))
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related